James McCool
commited on
Commit
·
3daeb17
1
Parent(s):
642b27d
Add CPT/FLEX/Overall focus selection for player locking and removal in Showdown mode in 'app.py', enhancing lineup customization options.
Browse files
app.py
CHANGED
@@ -1256,6 +1256,8 @@ if selected_tab == 'Manage Portfolio':
|
|
1256 |
for col in st.session_state['working_frame'].columns:
|
1257 |
if col not in excluded_cols:
|
1258 |
player_names.update(st.session_state['working_frame'][col].unique())
|
|
|
|
|
1259 |
player_lock = st.multiselect("Lock players?", options=sorted(list(player_names)), default=[])
|
1260 |
player_remove = st.multiselect("Remove players?", options=sorted(list(player_names)), default=[])
|
1261 |
team_include = st.multiselect("Include teams?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
|
@@ -1275,41 +1277,96 @@ if selected_tab == 'Manage Portfolio':
|
|
1275 |
st.session_state['settings_base'] = False
|
1276 |
parsed_frame = st.session_state['working_frame'].copy()
|
1277 |
if player_remove:
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1282 |
parsed_frame = parsed_frame[remove_mask]
|
1283 |
|
1284 |
if player_lock:
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1289 |
parsed_frame = parsed_frame[lock_mask]
|
1290 |
|
1291 |
if team_include:
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1301 |
parsed_frame = parsed_frame[include_mask]
|
1302 |
|
1303 |
if team_remove:
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1313 |
parsed_frame = parsed_frame[remove_mask]
|
1314 |
|
1315 |
if size_include:
|
|
|
1256 |
for col in st.session_state['working_frame'].columns:
|
1257 |
if col not in excluded_cols:
|
1258 |
player_names.update(st.session_state['working_frame'][col].unique())
|
1259 |
+
if type_var == 'Showdown':
|
1260 |
+
cpt_flex_focus = st.selectbox("Focus on Overall, CPT, or FLEX?", options=['Overall', 'CPT', 'FLEX'], index=0)
|
1261 |
player_lock = st.multiselect("Lock players?", options=sorted(list(player_names)), default=[])
|
1262 |
player_remove = st.multiselect("Remove players?", options=sorted(list(player_names)), default=[])
|
1263 |
team_include = st.multiselect("Include teams?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
|
|
|
1277 |
st.session_state['settings_base'] = False
|
1278 |
parsed_frame = st.session_state['working_frame'].copy()
|
1279 |
if player_remove:
|
1280 |
+
if type_var == 'Showdown':
|
1281 |
+
if cpt_flex_focus == 'CPT':
|
1282 |
+
remove_mask = parsed_frame[st.session_state['player_columns'][0]].apply(
|
1283 |
+
lambda row: not any(player in list(row) for player in player_remove), axis=1
|
1284 |
+
)
|
1285 |
+
elif cpt_flex_focus == 'FLEX':
|
1286 |
+
remove_mask = parsed_frame[st.session_state['player_columns'][1:]].apply(
|
1287 |
+
lambda row: not any(player in list(row) for player in player_remove), axis=1
|
1288 |
+
)
|
1289 |
+
elif cpt_flex_focus == 'Overall':
|
1290 |
+
remove_mask = parsed_frame[st.session_state['player_columns']].apply(
|
1291 |
+
lambda row: not any(player in list(row) for player in player_remove), axis=1
|
1292 |
+
)
|
1293 |
+
else:
|
1294 |
+
# Create mask for lineups that contain any of the removed players
|
1295 |
+
remove_mask = parsed_frame[st.session_state['player_columns']].apply(
|
1296 |
+
lambda row: not any(player in list(row) for player in player_remove), axis=1
|
1297 |
+
)
|
1298 |
parsed_frame = parsed_frame[remove_mask]
|
1299 |
|
1300 |
if player_lock:
|
1301 |
+
if type_var == 'Showdown':
|
1302 |
+
if cpt_flex_focus == 'CPT':
|
1303 |
+
lock_mask = parsed_frame[st.session_state['player_columns'][0]].apply(
|
1304 |
+
lambda row: all(player in list(row) for player in player_lock), axis=1
|
1305 |
+
)
|
1306 |
+
elif cpt_flex_focus == 'FLEX':
|
1307 |
+
lock_mask = parsed_frame[st.session_state['player_columns'][1:]].apply(
|
1308 |
+
lambda row: all(player in list(row) for player in player_lock), axis=1
|
1309 |
+
)
|
1310 |
+
elif cpt_flex_focus == 'Overall':
|
1311 |
+
lock_mask = parsed_frame[st.session_state['player_columns']].apply(
|
1312 |
+
lambda row: all(player in list(row) for player in player_lock), axis=1
|
1313 |
+
)
|
1314 |
+
else:
|
1315 |
+
lock_mask = parsed_frame[st.session_state['player_columns']].apply(
|
1316 |
+
lambda row: all(player in list(row) for player in player_lock), axis=1
|
1317 |
+
)
|
1318 |
parsed_frame = parsed_frame[lock_mask]
|
1319 |
|
1320 |
if team_include:
|
1321 |
+
if type_var == 'Showdown':
|
1322 |
+
if cpt_flex_focus == 'CPT':
|
1323 |
+
include_mask = parsed_frame[st.session_state['player_columns'][0]].apply(
|
1324 |
+
lambda row: any(team in list(row) for team in team_include), axis=1
|
1325 |
+
)
|
1326 |
+
elif cpt_flex_focus == 'FLEX':
|
1327 |
+
include_mask = parsed_frame[st.session_state['player_columns'][1:]].apply(
|
1328 |
+
lambda row: any(team in list(row) for team in team_include), axis=1
|
1329 |
+
)
|
1330 |
+
elif cpt_flex_focus == 'Overall':
|
1331 |
+
include_mask = parsed_frame[st.session_state['player_columns']].apply(
|
1332 |
+
lambda row: any(team in list(row) for team in team_include), axis=1
|
1333 |
+
)
|
1334 |
+
else:
|
1335 |
+
# Create a copy of the frame with player names replaced by teams, excluding SP1 and SP2
|
1336 |
+
filtered_player_columns = [col for col in st.session_state['player_columns'] if col not in ['SP1', 'SP2']]
|
1337 |
+
team_frame = parsed_frame[filtered_player_columns].apply(
|
1338 |
+
lambda x: x.map(st.session_state['map_dict']['team_map'])
|
1339 |
+
)
|
1340 |
+
# Create mask for lineups that contain any of the included teams
|
1341 |
+
include_mask = team_frame.apply(
|
1342 |
+
lambda row: any(team in list(row) for team in team_include), axis=1
|
1343 |
+
)
|
1344 |
parsed_frame = parsed_frame[include_mask]
|
1345 |
|
1346 |
if team_remove:
|
1347 |
+
if type_var == 'Showdown':
|
1348 |
+
if cpt_flex_focus == 'CPT':
|
1349 |
+
remove_mask = parsed_frame[st.session_state['player_columns'][0]].apply(
|
1350 |
+
lambda row: not any(team in list(row) for team in team_remove), axis=1
|
1351 |
+
)
|
1352 |
+
elif cpt_flex_focus == 'FLEX':
|
1353 |
+
remove_mask = parsed_frame[st.session_state['player_columns'][1:]].apply(
|
1354 |
+
lambda row: not any(team in list(row) for team in team_remove), axis=1
|
1355 |
+
)
|
1356 |
+
elif cpt_flex_focus == 'Overall':
|
1357 |
+
remove_mask = parsed_frame[st.session_state['player_columns']].apply(
|
1358 |
+
lambda row: not any(team in list(row) for team in team_remove), axis=1
|
1359 |
+
)
|
1360 |
+
else:
|
1361 |
+
# Create a copy of the frame with player names replaced by teams, excluding SP1 and SP2
|
1362 |
+
filtered_player_columns = [col for col in st.session_state['player_columns'] if col not in ['SP1', 'SP2']]
|
1363 |
+
team_frame = parsed_frame[filtered_player_columns].apply(
|
1364 |
+
lambda x: x.map(st.session_state['map_dict']['team_map'])
|
1365 |
+
)
|
1366 |
+
# Create mask for lineups that don't contain any of the removed teams
|
1367 |
+
remove_mask = team_frame.apply(
|
1368 |
+
lambda row: not any(team in list(row) for team in team_remove), axis=1
|
1369 |
+
)
|
1370 |
parsed_frame = parsed_frame[remove_mask]
|
1371 |
|
1372 |
if size_include:
|