James McCool
commited on
Commit
·
ff6fb00
1
Parent(s):
42075ca
chaning for to while for lineup add
Browse files- global_func/exposure_spread.py +58 -58
global_func/exposure_spread.py
CHANGED
|
@@ -231,7 +231,7 @@ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary
|
|
| 231 |
lineups_to_remove = (player_exposure * len(working_frame))
|
| 232 |
else:
|
| 233 |
lineups_to_remove = ((player_exposure - exposure_target) * len(working_frame)) * 1.01
|
| 234 |
-
lineups_to_add = ((exposure_target - player_exposure) *
|
| 235 |
|
| 236 |
# isolate the rows that contain the player
|
| 237 |
player_rows = working_frame[player_mask]
|
|
@@ -360,71 +360,71 @@ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary
|
|
| 360 |
if not random_row_indices_insert:
|
| 361 |
break
|
| 362 |
else:
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
]
|
| 368 |
else:
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
(projections_df['position'].apply(lambda x: has_position_overlap(x, comp_player_position)))
|
| 379 |
-
]
|
| 380 |
-
if sport_var in stacking_sports:
|
| 381 |
-
if working_frame.iloc[row]['Size'] == 5 and comp_team != working_frame.iloc[row]['Stack']:
|
| 382 |
-
remove_mask = comparable_players.apply(
|
| 383 |
-
lambda player_row: not any(team in list(player_row) for team in [working_frame.iloc[row]['Stack']]), axis=1
|
| 384 |
-
)
|
| 385 |
-
comparable_players = comparable_players[remove_mask]
|
| 386 |
-
|
| 387 |
-
if remove_teams is not None:
|
| 388 |
-
remove_mask = comparable_players.apply(
|
| 389 |
-
lambda row: not any(team in list(row) for team in remove_teams), axis=1
|
| 390 |
)
|
| 391 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
|
| 393 |
-
|
| 394 |
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
working_frame.at[row, col] = exposure_player
|
| 422 |
-
change_counter += 1
|
| 423 |
-
break
|
| 424 |
-
else:
|
| 425 |
-
# For non-Classic types, salary check is sufficient (position eligibility handled elsewhere)
|
| 426 |
working_frame.at[row, col] = exposure_player
|
| 427 |
change_counter += 1
|
| 428 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
return working_frame
|
| 430 |
|
|
|
|
| 231 |
lineups_to_remove = (player_exposure * len(working_frame))
|
| 232 |
else:
|
| 233 |
lineups_to_remove = ((player_exposure - exposure_target) * len(working_frame)) * 1.01
|
| 234 |
+
lineups_to_add = ((exposure_target - player_exposure) * len(working_frame)) * 1.10
|
| 235 |
|
| 236 |
# isolate the rows that contain the player
|
| 237 |
player_rows = working_frame[player_mask]
|
|
|
|
| 360 |
if not random_row_indices_insert:
|
| 361 |
break
|
| 362 |
else:
|
| 363 |
+
while change_counter < math.ceil(lineups_to_add) and random_row_indices_replace:
|
| 364 |
+
row = random_row_indices_replace.pop(0)
|
| 365 |
+
if specific_replacements != []:
|
| 366 |
+
comparable_players = projections_df[(projections_df['player_names'].isin(specific_replacements))
|
| 367 |
+
]
|
| 368 |
+
else:
|
| 369 |
+
if type_var == 'Showdown':
|
| 370 |
+
comparable_players = projections_df[
|
| 371 |
+
(projections_df['salary'] >= comp_salary_low) &
|
| 372 |
+
(projections_df['salary'] <= comp_salary_high + (salary_max - working_frame['salary'][row]))
|
| 373 |
]
|
| 374 |
else:
|
| 375 |
+
comparable_players = projections_df[
|
| 376 |
+
(projections_df['salary'] >= comp_salary_low) &
|
| 377 |
+
(projections_df['salary'] <= comp_salary_high + (salary_max - working_frame['salary'][row])) &
|
| 378 |
+
(projections_df['position'].apply(lambda x: has_position_overlap(x, comp_player_position)))
|
| 379 |
+
]
|
| 380 |
+
if sport_var in stacking_sports:
|
| 381 |
+
if working_frame.iloc[row]['Size'] == 5 and comp_team != working_frame.iloc[row]['Stack']:
|
| 382 |
+
remove_mask = comparable_players.apply(
|
| 383 |
+
lambda player_row: not any(team in list(player_row) for team in [working_frame.iloc[row]['Stack']]), axis=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
)
|
| 385 |
+
comparable_players = comparable_players[remove_mask]
|
| 386 |
+
|
| 387 |
+
if remove_teams is not None:
|
| 388 |
+
remove_mask = comparable_players.apply(
|
| 389 |
+
lambda row: not any(team in list(row) for team in remove_teams), axis=1
|
| 390 |
+
)
|
| 391 |
+
comparable_players = comparable_players[remove_mask]
|
| 392 |
|
| 393 |
+
comparable_players = comparable_players[comparable_players['player_names'] != exposure_player]
|
| 394 |
|
| 395 |
+
# Create a list of comparable players
|
| 396 |
+
comparable_player_list = comparable_players['player_names'].tolist()
|
| 397 |
+
|
| 398 |
+
if exposure_player in working_frame.iloc[row].values:
|
| 399 |
+
comparable_player_list = []
|
| 400 |
|
| 401 |
+
if comparable_player_list:
|
| 402 |
+
# Find which column contains the exposure_player
|
| 403 |
+
if specific_columns != []:
|
| 404 |
+
row_data = working_frame.iloc[row][specific_columns]
|
| 405 |
+
working_columns = specific_columns
|
| 406 |
+
else:
|
| 407 |
+
row_data = working_frame.iloc[row]
|
| 408 |
+
working_columns = working_frame.columns
|
| 409 |
+
|
| 410 |
+
for col in working_columns:
|
| 411 |
+
if row_data[col] in comparable_player_list:
|
| 412 |
+
current_lineup_salary = working_frame.iloc[row]['salary']
|
| 413 |
+
current_player = row_data[col]
|
| 414 |
+
|
| 415 |
+
# Check salary eligibility using helper function
|
| 416 |
+
if check_salary_eligibility(current_lineup_salary, current_player, exposure_player, col, projections_df, type_var, salary_max):
|
| 417 |
+
if type_var == 'Classic':
|
| 418 |
+
# For Classic types, also check position eligibility
|
| 419 |
+
exposure_player_positions = projections_df[projections_df['player_names'] == exposure_player]['position'].iloc[0].split('/')
|
| 420 |
+
if check_position_eligibility(sport_var, col, exposure_player_positions):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
working_frame.at[row, col] = exposure_player
|
| 422 |
change_counter += 1
|
| 423 |
break
|
| 424 |
+
else:
|
| 425 |
+
# For non-Classic types, salary check is sufficient (position eligibility handled elsewhere)
|
| 426 |
+
working_frame.at[row, col] = exposure_player
|
| 427 |
+
change_counter += 1
|
| 428 |
+
break
|
| 429 |
return working_frame
|
| 430 |
|