James McCool
commited on
Commit
·
a7fac7f
1
Parent(s):
dbce748
Refactor lineup filtering logic in app.py to streamline player selection process. Updated multiselect options for removing and including players, enhancing clarity and user experience. Improved filtering conditions to ensure accurate lineup management based on user selections.
Browse files
app.py
CHANGED
|
@@ -1303,12 +1303,8 @@ with tab2:
|
|
| 1303 |
for col in st.session_state['working_frame'].columns:
|
| 1304 |
if col not in excluded_cols:
|
| 1305 |
player_names.update(st.session_state['working_frame'][col].unique())
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
-
conditional_remove_players = st.multiselect("If Remove variable is Players, remove lineups containing players:", options=sorted(list(player_names)), default=[])
|
| 1309 |
-
conditional_remove_stacks = st.multiselect("If Remove variable is Stacks, remove lineups containing stacks:", options=sorted(list(set(st.session_state['stack_dict'].values()))), default=[])
|
| 1310 |
-
conditional_include_players = st.multiselect("If Contains variable is Players, where lineups contain players:", options=sorted(list(player_names)), default=[])
|
| 1311 |
-
conditional_include_stacks = st.multiselect("If Contains variable is Stacks, where lineups contain stacks:", options=sorted(list(set(st.session_state['stack_dict'].values()))), default=[])
|
| 1312 |
|
| 1313 |
submitted_col, export_col = st.columns(2)
|
| 1314 |
st.info("Portfolio Button applies to your overall Portfolio, Export button applies to your Custom Export")
|
|
@@ -1319,31 +1315,37 @@ with tab2:
|
|
| 1319 |
if reg_submitted:
|
| 1320 |
st.session_state['settings_base'] = False
|
| 1321 |
parsed_frame = st.session_state['working_frame'].copy()
|
| 1322 |
-
|
| 1323 |
-
|
| 1324 |
-
|
| 1325 |
-
|
| 1326 |
-
|
| 1327 |
-
|
| 1328 |
-
|
| 1329 |
-
|
| 1330 |
-
|
| 1331 |
-
|
|
|
|
|
|
|
|
|
|
| 1332 |
st.session_state['working_frame'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
|
| 1333 |
st.session_state['export_merge'] = st.session_state['working_frame'].copy()
|
| 1334 |
elif exp_submitted:
|
| 1335 |
st.session_state['settings_base'] = False
|
| 1336 |
parsed_frame = st.session_state['export_base'].copy()
|
| 1337 |
-
|
| 1338 |
-
|
| 1339 |
-
|
| 1340 |
-
|
| 1341 |
-
|
| 1342 |
-
|
| 1343 |
-
|
| 1344 |
-
|
| 1345 |
-
|
| 1346 |
-
|
|
|
|
|
|
|
|
|
|
| 1347 |
st.session_state['export_base'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
|
| 1348 |
st.session_state['export_merge'] = st.session_state['export_base'].copy()
|
| 1349 |
|
|
|
|
| 1303 |
for col in st.session_state['working_frame'].columns:
|
| 1304 |
if col not in excluded_cols:
|
| 1305 |
player_names.update(st.session_state['working_frame'][col].unique())
|
| 1306 |
+
conditional_remove_players = st.multiselect("Remove lineups containing player(s):", options=sorted(list(player_names)), default=[])
|
| 1307 |
+
conditional_include_players = st.multiselect("If they also contain player(s):", options=sorted(list(player_names)), default=[])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1308 |
|
| 1309 |
submitted_col, export_col = st.columns(2)
|
| 1310 |
st.info("Portfolio Button applies to your overall Portfolio, Export button applies to your Custom Export")
|
|
|
|
| 1315 |
if reg_submitted:
|
| 1316 |
st.session_state['settings_base'] = False
|
| 1317 |
parsed_frame = st.session_state['working_frame'].copy()
|
| 1318 |
+
|
| 1319 |
+
# Filter rows that contain ALL conditional_include_players AND NONE of conditional_remove_players
|
| 1320 |
+
if conditional_include_players:
|
| 1321 |
+
include_mask = parsed_frame['player_names'].apply(lambda x: all(player in x for player in conditional_include_players))
|
| 1322 |
+
else:
|
| 1323 |
+
include_mask = True
|
| 1324 |
+
|
| 1325 |
+
if conditional_remove_players:
|
| 1326 |
+
remove_mask = parsed_frame['player_names'].apply(lambda x: not any(player in x for player in conditional_remove_players))
|
| 1327 |
+
else:
|
| 1328 |
+
remove_mask = True
|
| 1329 |
+
|
| 1330 |
+
parsed_frame = parsed_frame[include_mask & remove_mask]
|
| 1331 |
st.session_state['working_frame'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
|
| 1332 |
st.session_state['export_merge'] = st.session_state['working_frame'].copy()
|
| 1333 |
elif exp_submitted:
|
| 1334 |
st.session_state['settings_base'] = False
|
| 1335 |
parsed_frame = st.session_state['export_base'].copy()
|
| 1336 |
+
|
| 1337 |
+
# Filter rows that contain ALL conditional_include_players AND NONE of conditional_remove_players
|
| 1338 |
+
if conditional_include_players:
|
| 1339 |
+
include_mask = parsed_frame['player_names'].apply(lambda x: all(player in x for player in conditional_include_players))
|
| 1340 |
+
else:
|
| 1341 |
+
include_mask = True
|
| 1342 |
+
|
| 1343 |
+
if conditional_remove_players:
|
| 1344 |
+
remove_mask = parsed_frame['player_names'].apply(lambda x: not any(player in x for player in conditional_remove_players))
|
| 1345 |
+
else:
|
| 1346 |
+
remove_mask = True
|
| 1347 |
+
|
| 1348 |
+
parsed_frame = parsed_frame[include_mask & remove_mask]
|
| 1349 |
st.session_state['export_base'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
|
| 1350 |
st.session_state['export_merge'] = st.session_state['export_base'].copy()
|
| 1351 |
|