James McCool
commited on
Commit
·
38f865e
1
Parent(s):
0f6f9ba
Refactor exposure_spread function to streamline comparable player selection logic, ensuring accurate filtering based on salary, median projections, and position overlap, while maintaining team removal functionality.
Browse files- global_func/exposure_spread.py +18 -21
global_func/exposure_spread.py
CHANGED
|
@@ -233,26 +233,6 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 233 |
player_pos_list = player_positions.split('/')
|
| 234 |
return any(pos in target_positions for pos in player_pos_list)
|
| 235 |
|
| 236 |
-
comparable_players = projections_df[
|
| 237 |
-
(projections_df['salary'] >= comp_salary_low) &
|
| 238 |
-
(projections_df['salary'] <= comp_salary_high) &
|
| 239 |
-
(projections_df['median'] >= comp_projection_low) &
|
| 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 = comparable_players.apply(
|
| 249 |
-
lambda row: not any(team in list(row) for team in remove_teams), axis=1
|
| 250 |
-
)
|
| 251 |
-
comparable_players = comparable_players[remove_mask]
|
| 252 |
-
|
| 253 |
-
# Create a list of comparable players
|
| 254 |
-
comparable_player_list = comparable_players['player_names'].tolist()
|
| 255 |
-
|
| 256 |
# find the exposure rate of the player in the working frame
|
| 257 |
player_mask = working_frame[working_frame.columns].apply(
|
| 258 |
lambda row: exposure_player in list(row), axis=1
|
|
@@ -267,7 +247,6 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 267 |
if comparable_stack != 0:
|
| 268 |
player_rows = player_rows[player_rows['Stack'] != comparable_stack]
|
| 269 |
|
| 270 |
-
|
| 271 |
change_counter = 0
|
| 272 |
|
| 273 |
random_row_indices = list(player_rows.index)
|
|
@@ -276,6 +255,24 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 276 |
# for each row to the the number of lineups to remove, replace with random choice from comparable player list
|
| 277 |
for row in random_row_indices:
|
| 278 |
if change_counter < math.ceil(lineups_to_remove):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
insert_player = random.choice(comparable_player_list)
|
| 280 |
# Find which column contains the exposure_player
|
| 281 |
row_data = working_frame.iloc[row]
|
|
|
|
| 233 |
player_pos_list = player_positions.split('/')
|
| 234 |
return any(pos in target_positions for pos in player_pos_list)
|
| 235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
# find the exposure rate of the player in the working frame
|
| 237 |
player_mask = working_frame[working_frame.columns].apply(
|
| 238 |
lambda row: exposure_player in list(row), axis=1
|
|
|
|
| 247 |
if comparable_stack != 0:
|
| 248 |
player_rows = player_rows[player_rows['Stack'] != comparable_stack]
|
| 249 |
|
|
|
|
| 250 |
change_counter = 0
|
| 251 |
|
| 252 |
random_row_indices = list(player_rows.index)
|
|
|
|
| 255 |
# for each row to the the number of lineups to remove, replace with random choice from comparable player list
|
| 256 |
for row in random_row_indices:
|
| 257 |
if change_counter < math.ceil(lineups_to_remove):
|
| 258 |
+
comparable_players = projections_df[
|
| 259 |
+
(projections_df['salary'] >= comp_salary_low) &
|
| 260 |
+
(projections_df['salary'] <= comp_salary_high + (50000 - working_frame['salary'][row])) &
|
| 261 |
+
(projections_df['median'] >= comp_projection_low) &
|
| 262 |
+
(projections_df['position'].apply(lambda x: has_position_overlap(x, comp_player_position)))
|
| 263 |
+
]
|
| 264 |
+
|
| 265 |
+
if exposure_target == 0:
|
| 266 |
+
comparable_players = comparable_players[comparable_players['player_names'] != exposure_player]
|
| 267 |
+
|
| 268 |
+
if remove_teams is not None:
|
| 269 |
+
remove_mask = comparable_players.apply(
|
| 270 |
+
lambda row: not any(team in list(row) for team in remove_teams), axis=1
|
| 271 |
+
)
|
| 272 |
+
comparable_players = comparable_players[remove_mask]
|
| 273 |
+
|
| 274 |
+
# Create a list of comparable players
|
| 275 |
+
comparable_player_list = comparable_players['player_names'].tolist()
|
| 276 |
insert_player = random.choice(comparable_player_list)
|
| 277 |
# Find which column contains the exposure_player
|
| 278 |
row_data = working_frame.iloc[row]
|