Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
efbfb51
1
Parent(s):
a768a6b
Enhance player replacement logic in exposure_spread function by separating random row selection for insertion and replacement. This improves clarity and ensures accurate handling of lineups during exposure adjustments.
Browse files- global_func/exposure_spread.py +15 -12
global_func/exposure_spread.py
CHANGED
|
@@ -246,8 +246,12 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 246 |
|
| 247 |
# find the exposure rate of the player in the working frame
|
| 248 |
player_mask = working_frame[working_frame.columns].apply(
|
| 249 |
-
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
player_exposure = player_mask.sum() / len(working_frame)
|
| 252 |
|
| 253 |
# find the number of lineups that need to be removed to reach the target exposure
|
|
@@ -258,13 +262,17 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 258 |
|
| 259 |
# isolate the rows that contain the player
|
| 260 |
player_rows = working_frame[player_mask]
|
|
|
|
| 261 |
if comparable_stack != 0:
|
| 262 |
player_rows = player_rows[player_rows['Stack'] != comparable_stack]
|
|
|
|
| 263 |
|
| 264 |
change_counter = 0
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
|
|
|
|
|
|
| 268 |
|
| 269 |
# for each row to the the number of lineups to remove, replace with random choice from comparable player list if they can be inserted
|
| 270 |
|
|
@@ -272,7 +280,7 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 272 |
# key concept here is if they have a lineups to remove above 0 it means that we are trying to replace them with comparable players
|
| 273 |
# if the lineups to remove is below zero it means we want to find comparable players and replace them with the exposure player
|
| 274 |
if lineups_to_remove > 0:
|
| 275 |
-
for row in
|
| 276 |
if change_counter < math.ceil(lineups_to_remove):
|
| 277 |
comparable_players = projections_df[
|
| 278 |
(projections_df['salary'] >= comp_salary_low) &
|
|
@@ -319,7 +327,7 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 319 |
change_counter += 1
|
| 320 |
else:
|
| 321 |
lineups_to_remove = lineups_to_remove * -1
|
| 322 |
-
for row in
|
| 323 |
if change_counter < math.ceil(lineups_to_remove):
|
| 324 |
comparable_players = projections_df[
|
| 325 |
(projections_df['salary'] >= comp_salary_low) &
|
|
@@ -333,12 +341,7 @@ def exposure_spread(working_frame, exposure_player, exposure_target, exposure_st
|
|
| 333 |
lambda row: not any(team in list(row) for team in remove_teams), axis=1
|
| 334 |
)
|
| 335 |
comparable_players = comparable_players[remove_mask]
|
| 336 |
-
|
| 337 |
-
remove_mask = working_frame.apply(
|
| 338 |
-
lambda row: exposure_player not in list(row), axis=1
|
| 339 |
-
)
|
| 340 |
-
working_frame = working_frame[remove_mask]
|
| 341 |
-
|
| 342 |
comparable_players = comparable_players[comparable_players['player_names'] != exposure_player]
|
| 343 |
|
| 344 |
# Create a list of comparable players
|
|
|
|
| 246 |
|
| 247 |
# find the exposure rate of the player in the working frame
|
| 248 |
player_mask = working_frame[working_frame.columns].apply(
|
| 249 |
+
lambda row: exposure_player in list(row), axis=1
|
| 250 |
+
)
|
| 251 |
+
replace_mask = working_frame.apply(
|
| 252 |
+
lambda row: exposure_player not in list(row), axis=1
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
player_exposure = player_mask.sum() / len(working_frame)
|
| 256 |
|
| 257 |
# find the number of lineups that need to be removed to reach the target exposure
|
|
|
|
| 262 |
|
| 263 |
# isolate the rows that contain the player
|
| 264 |
player_rows = working_frame[player_mask]
|
| 265 |
+
replace_rows = working_frame[replace_mask]
|
| 266 |
if comparable_stack != 0:
|
| 267 |
player_rows = player_rows[player_rows['Stack'] != comparable_stack]
|
| 268 |
+
replace_rows = replace_rows[replace_rows['Stack'] != comparable_stack]
|
| 269 |
|
| 270 |
change_counter = 0
|
| 271 |
|
| 272 |
+
random_row_indices_insert = list(player_rows.index)
|
| 273 |
+
random_row_indices_replace = list(replace_rows.index)
|
| 274 |
+
random.shuffle(random_row_indices_insert)
|
| 275 |
+
random.shuffle(random_row_indices_replace)
|
| 276 |
|
| 277 |
# for each row to the the number of lineups to remove, replace with random choice from comparable player list if they can be inserted
|
| 278 |
|
|
|
|
| 280 |
# key concept here is if they have a lineups to remove above 0 it means that we are trying to replace them with comparable players
|
| 281 |
# if the lineups to remove is below zero it means we want to find comparable players and replace them with the exposure player
|
| 282 |
if lineups_to_remove > 0:
|
| 283 |
+
for row in random_row_indices_insert:
|
| 284 |
if change_counter < math.ceil(lineups_to_remove):
|
| 285 |
comparable_players = projections_df[
|
| 286 |
(projections_df['salary'] >= comp_salary_low) &
|
|
|
|
| 327 |
change_counter += 1
|
| 328 |
else:
|
| 329 |
lineups_to_remove = lineups_to_remove * -1
|
| 330 |
+
for row in random_row_indices_replace:
|
| 331 |
if change_counter < math.ceil(lineups_to_remove):
|
| 332 |
comparable_players = projections_df[
|
| 333 |
(projections_df['salary'] >= comp_salary_low) &
|
|
|
|
| 341 |
lambda row: not any(team in list(row) for team in remove_teams), axis=1
|
| 342 |
)
|
| 343 |
comparable_players = comparable_players[remove_mask]
|
| 344 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
comparable_players = comparable_players[comparable_players['player_names'] != exposure_player]
|
| 346 |
|
| 347 |
# Create a list of comparable players
|