James McCool
commited on
Commit
·
1b89d01
1
Parent(s):
1046e61
Enhance exposure_spread function to include an option for removing specified teams, improving flexibility in player comparison and exposure calculations.
Browse files- app.py +2 -1
- global_func/exposure_spread.py +11 -4
app.py
CHANGED
|
@@ -1172,10 +1172,11 @@ with tab2:
|
|
| 1172 |
exposure_stack_bool = st.selectbox("Maintain Stacks?", options=['Yes', 'No'], index=0)
|
| 1173 |
else:
|
| 1174 |
exposure_stack_bool = 'No'
|
|
|
|
| 1175 |
submitted = st.form_submit_button("Submit")
|
| 1176 |
if submitted:
|
| 1177 |
st.session_state['settings_base'] = False
|
| 1178 |
-
parsed_frame = exposure_spread(st.session_state['working_frame'], exposure_player, exposure_target, exposure_stack_bool, st.session_state['projections_df'], sport_var, type_var)
|
| 1179 |
st.session_state['working_frame'] = parsed_frame.reset_index(drop=True)
|
| 1180 |
st.session_state['export_merge'] = st.session_state['working_frame'].copy()
|
| 1181 |
with st.container():
|
|
|
|
| 1172 |
exposure_stack_bool = st.selectbox("Maintain Stacks?", options=['Yes', 'No'], index=0)
|
| 1173 |
else:
|
| 1174 |
exposure_stack_bool = 'No'
|
| 1175 |
+
remove_teams_exposure = st.multiselect("Removed/Locked teams?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
|
| 1176 |
submitted = st.form_submit_button("Submit")
|
| 1177 |
if submitted:
|
| 1178 |
st.session_state['settings_base'] = False
|
| 1179 |
+
parsed_frame = exposure_spread(st.session_state['working_frame'], exposure_player, exposure_target, exposure_stack_bool, remove_teams_exposure, st.session_state['projections_df'], sport_var, type_var)
|
| 1180 |
st.session_state['working_frame'] = parsed_frame.reset_index(drop=True)
|
| 1181 |
st.session_state['export_merge'] = st.session_state['working_frame'].copy()
|
| 1182 |
with st.container():
|
global_func/exposure_spread.py
CHANGED
|
@@ -209,7 +209,7 @@ def check_position_eligibility(sport, column_name, player_positions):
|
|
| 209 |
# Default fallback - assume exact position match
|
| 210 |
return column_name in player_positions
|
| 211 |
|
| 212 |
-
def exposure_spread(working_frame, exposure_player, exposure_target, exposure_stack_bool, projections_df, sport_var, type_var):
|
| 213 |
# Find comparable players in the projections
|
| 214 |
comparable_players = projections_df[projections_df['player_names'] == exposure_player]
|
| 215 |
|
|
@@ -240,7 +240,16 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 240 |
(projections_df['median'] <= comp_projection_high) &
|
| 241 |
(projections_df['position'].apply(lambda x: has_position_overlap(x, comp_player_position)))
|
| 242 |
]
|
|
|
|
|
|
|
|
|
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
# Create a list of comparable players
|
| 245 |
comparable_player_list = comparable_players['player_names'].tolist()
|
| 246 |
|
|
@@ -255,11 +264,9 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 255 |
|
| 256 |
# isolate the rows that contain the player
|
| 257 |
player_rows = working_frame[player_mask]
|
| 258 |
-
print(player_rows.head(10))
|
| 259 |
if comparable_stack != 0:
|
| 260 |
player_rows = player_rows[player_rows['Stack'] != comparable_stack]
|
| 261 |
-
|
| 262 |
-
print(working_frame.head(10))
|
| 263 |
|
| 264 |
change_counter = 0
|
| 265 |
|
|
|
|
| 209 |
# Default fallback - assume exact position match
|
| 210 |
return column_name in player_positions
|
| 211 |
|
| 212 |
+
def exposure_spread(working_frame, exposure_player, exposure_target, exposure_stack_bool, remove_teams, projections_df, sport_var, type_var):
|
| 213 |
# Find comparable players in the projections
|
| 214 |
comparable_players = projections_df[projections_df['player_names'] == exposure_player]
|
| 215 |
|
|
|
|
| 240 |
(projections_df['median'] <= comp_projection_high) &
|
| 241 |
(projections_df['position'].apply(lambda x: has_position_overlap(x, comp_player_position)))
|
| 242 |
]
|
| 243 |
+
|
| 244 |
+
if exposure_target == 0:
|
| 245 |
+
comparable_players = comparable_players[comparable_players['player_names'] != exposure_player]
|
| 246 |
|
| 247 |
+
if remove_teams is not None:
|
| 248 |
+
remove_mask = player_rows.apply(
|
| 249 |
+
lambda row: not any(team in list(row) for team in remove_teams), axis=1
|
| 250 |
+
)
|
| 251 |
+
player_rows = player_rows[remove_mask]
|
| 252 |
+
|
| 253 |
# Create a list of comparable players
|
| 254 |
comparable_player_list = comparable_players['player_names'].tolist()
|
| 255 |
|
|
|
|
| 264 |
|
| 265 |
# isolate the rows that contain the player
|
| 266 |
player_rows = working_frame[player_mask]
|
|
|
|
| 267 |
if comparable_stack != 0:
|
| 268 |
player_rows = player_rows[player_rows['Stack'] != comparable_stack]
|
| 269 |
+
|
|
|
|
| 270 |
|
| 271 |
change_counter = 0
|
| 272 |
|