Spaces:
Build error
Build error
James McCool commited on
Commit ·
440ae44
1
Parent(s): e425b59
reverting
Browse files- global_func/exposure_spread.py +39 -51
global_func/exposure_spread.py
CHANGED
|
@@ -175,23 +175,6 @@ def check_salary_eligibility(current_lineup_salary, current_player, new_player,
|
|
| 175 |
salary_diff = calculate_salary_difference(current_player, new_player, column_name, projections_df, type_var)
|
| 176 |
return current_lineup_salary + salary_diff <= salary_max
|
| 177 |
|
| 178 |
-
|
| 179 |
-
def _showdown_slot_columns(columns):
|
| 180 |
-
"""CPT + FLEX* — full Showdown roster slots (no duplicate player across slots)."""
|
| 181 |
-
return [c for c in columns if c == 'CPT' or (isinstance(c, str) and str(c).startswith('FLEX'))]
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
def _lineup_player_names(row_series, df_columns, type_var, specific_columns):
|
| 185 |
-
"""Names already in the lineup for duplicate / opponent checks (all Showdown slots when Showdown)."""
|
| 186 |
-
if type_var == 'Showdown':
|
| 187 |
-
slots = _showdown_slot_columns(df_columns)
|
| 188 |
-
if slots:
|
| 189 |
-
return set(row_series.loc[slots].values)
|
| 190 |
-
if specific_columns:
|
| 191 |
-
return set(row_series[specific_columns].values)
|
| 192 |
-
return set(row_series.values)
|
| 193 |
-
|
| 194 |
-
|
| 195 |
def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary_below, comp_salary_above, ignore_stacks, remove_teams, specific_replacements, specific_exclusions, specific_columns, projections_df, sport_var, type_var, salary_max, stacking_sports, opp_map=None):
|
| 196 |
"""
|
| 197 |
Added parameter:
|
|
@@ -229,11 +212,15 @@ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary
|
|
| 229 |
player_pos_list = player_positions.split('/')
|
| 230 |
return any(pos in target_positions for pos in player_pos_list)
|
| 231 |
|
| 232 |
-
def check_opponent_conflict(candidate_player,
|
| 233 |
-
"""Check if candidate is an opponent of any player
|
| 234 |
if not opp_map:
|
| 235 |
return False # No conflicts if opp_map doesn't exist
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
for existing_player in existing_players:
|
| 238 |
if opp_map.get(existing_player) == candidate_player:
|
| 239 |
return True # Conflict found
|
|
@@ -311,17 +298,14 @@ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary
|
|
| 311 |
)
|
| 312 |
comparable_players = comparable_players[remove_mask]
|
| 313 |
|
| 314 |
-
#
|
| 315 |
-
existing_players = _lineup_player_names(
|
| 316 |
-
working_frame.loc[row], working_frame.columns, type_var, specific_columns
|
| 317 |
-
)
|
| 318 |
-
|
| 319 |
if specific_columns != []:
|
| 320 |
-
|
| 321 |
-
working_columns = specific_columns
|
| 322 |
else:
|
| 323 |
-
|
| 324 |
-
|
|
|
|
|
|
|
| 325 |
try:
|
| 326 |
comparable_players = comparable_players[~comparable_players['player_names'].isin(existing_players)]
|
| 327 |
comparable_player_list = comparable_players['player_names'].tolist()
|
|
@@ -329,15 +313,22 @@ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary
|
|
| 329 |
comparable_player_list = []
|
| 330 |
|
| 331 |
if comparable_player_list:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
replacement_made = False
|
| 333 |
-
|
| 334 |
if exposure_target == 0:
|
| 335 |
for col in working_columns:
|
| 336 |
-
if
|
| 337 |
suitable_replacements = []
|
| 338 |
for candidate in comparable_player_list:
|
| 339 |
# NEW: Check for opponent conflicts
|
| 340 |
-
if check_opponent_conflict(candidate,
|
| 341 |
continue # Skip this candidate
|
| 342 |
|
| 343 |
replacement_player_positions = projections_df[projections_df['player_names'] == candidate]['position'].iloc[0].split('/')
|
|
@@ -354,19 +345,14 @@ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary
|
|
| 354 |
insert_player = random.choice(suitable_replacements)
|
| 355 |
working_frame.at[row, col] = insert_player
|
| 356 |
replacement_made = True
|
| 357 |
-
|
| 358 |
-
working_frame.loc[row], working_frame.columns, type_var, specific_columns
|
| 359 |
-
)
|
| 360 |
-
comparable_player_list = [
|
| 361 |
-
p for p in comparable_player_list if p not in existing_players
|
| 362 |
-
]
|
| 363 |
else:
|
| 364 |
for col in working_columns:
|
| 365 |
-
if
|
| 366 |
# Filter candidates to exclude opponent conflicts
|
| 367 |
valid_candidates = [
|
| 368 |
-
candidate for candidate in comparable_player_list
|
| 369 |
-
if not check_opponent_conflict(candidate,
|
| 370 |
]
|
| 371 |
|
| 372 |
if not valid_candidates:
|
|
@@ -398,11 +384,14 @@ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary
|
|
| 398 |
while change_counter < math.ceil(lineups_to_add) and random_row_indices_replace:
|
| 399 |
row = random_row_indices_replace.pop(0)
|
| 400 |
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
|
|
|
|
|
|
|
|
|
| 406 |
continue # Skip this row, can't add exposure_player here
|
| 407 |
|
| 408 |
if specific_replacements != []:
|
|
@@ -436,8 +425,8 @@ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary
|
|
| 436 |
comparable_players = comparable_players[comparable_players['player_names'] != exposure_player]
|
| 437 |
|
| 438 |
comparable_player_list = comparable_players['player_names'].tolist()
|
| 439 |
-
|
| 440 |
-
if exposure_player in
|
| 441 |
comparable_player_list = []
|
| 442 |
|
| 443 |
if comparable_player_list:
|
|
@@ -449,10 +438,9 @@ def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary
|
|
| 449 |
working_columns = working_frame.columns
|
| 450 |
|
| 451 |
for col in working_columns:
|
| 452 |
-
|
| 453 |
-
if cell in comparable_player_list:
|
| 454 |
current_lineup_salary = working_frame.loc[row]['salary']
|
| 455 |
-
current_player =
|
| 456 |
|
| 457 |
if check_salary_eligibility(current_lineup_salary, current_player, exposure_player, col, projections_df, type_var, salary_max):
|
| 458 |
if type_var == 'Classic':
|
|
|
|
| 175 |
salary_diff = calculate_salary_difference(current_player, new_player, column_name, projections_df, type_var)
|
| 176 |
return current_lineup_salary + salary_diff <= salary_max
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
def exposure_spread(working_frame, exposure_player, exposure_target, comp_salary_below, comp_salary_above, ignore_stacks, remove_teams, specific_replacements, specific_exclusions, specific_columns, projections_df, sport_var, type_var, salary_max, stacking_sports, opp_map=None):
|
| 179 |
"""
|
| 180 |
Added parameter:
|
|
|
|
| 212 |
player_pos_list = player_positions.split('/')
|
| 213 |
return any(pos in target_positions for pos in player_pos_list)
|
| 214 |
|
| 215 |
+
def check_opponent_conflict(candidate_player, current_row_data, opp_map):
|
| 216 |
+
"""Check if candidate player is an opponent of any player in the current row"""
|
| 217 |
if not opp_map:
|
| 218 |
return False # No conflicts if opp_map doesn't exist
|
| 219 |
+
|
| 220 |
+
# Get all players currently in the row
|
| 221 |
+
existing_players = set(current_row_data.values)
|
| 222 |
+
|
| 223 |
+
# Check if candidate is opponent of any existing player
|
| 224 |
for existing_player in existing_players:
|
| 225 |
if opp_map.get(existing_player) == candidate_player:
|
| 226 |
return True # Conflict found
|
|
|
|
| 298 |
)
|
| 299 |
comparable_players = comparable_players[remove_mask]
|
| 300 |
|
| 301 |
+
# Get the current row data to check for existing players
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
if specific_columns != []:
|
| 303 |
+
current_row_data = working_frame.loc[row][specific_columns]
|
|
|
|
| 304 |
else:
|
| 305 |
+
current_row_data = working_frame.loc[row]
|
| 306 |
+
|
| 307 |
+
# Filter out players that are already present in this row
|
| 308 |
+
existing_players = set(current_row_data.values)
|
| 309 |
try:
|
| 310 |
comparable_players = comparable_players[~comparable_players['player_names'].isin(existing_players)]
|
| 311 |
comparable_player_list = comparable_players['player_names'].tolist()
|
|
|
|
| 313 |
comparable_player_list = []
|
| 314 |
|
| 315 |
if comparable_player_list:
|
| 316 |
+
if specific_columns != []:
|
| 317 |
+
row_data = working_frame.loc[row][specific_columns]
|
| 318 |
+
working_columns = specific_columns
|
| 319 |
+
else:
|
| 320 |
+
row_data = working_frame.loc[row]
|
| 321 |
+
working_columns = working_frame.columns
|
| 322 |
+
|
| 323 |
replacement_made = False
|
| 324 |
+
|
| 325 |
if exposure_target == 0:
|
| 326 |
for col in working_columns:
|
| 327 |
+
if row_data[col] == exposure_player:
|
| 328 |
suitable_replacements = []
|
| 329 |
for candidate in comparable_player_list:
|
| 330 |
# NEW: Check for opponent conflicts
|
| 331 |
+
if check_opponent_conflict(candidate, current_row_data, opp_map):
|
| 332 |
continue # Skip this candidate
|
| 333 |
|
| 334 |
replacement_player_positions = projections_df[projections_df['player_names'] == candidate]['position'].iloc[0].split('/')
|
|
|
|
| 345 |
insert_player = random.choice(suitable_replacements)
|
| 346 |
working_frame.at[row, col] = insert_player
|
| 347 |
replacement_made = True
|
| 348 |
+
comparable_player_list = [p for p in comparable_player_list if p != insert_player]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
else:
|
| 350 |
for col in working_columns:
|
| 351 |
+
if row_data[col] == exposure_player:
|
| 352 |
# Filter candidates to exclude opponent conflicts
|
| 353 |
valid_candidates = [
|
| 354 |
+
candidate for candidate in comparable_player_list
|
| 355 |
+
if not check_opponent_conflict(candidate, current_row_data, opp_map)
|
| 356 |
]
|
| 357 |
|
| 358 |
if not valid_candidates:
|
|
|
|
| 384 |
while change_counter < math.ceil(lineups_to_add) and random_row_indices_replace:
|
| 385 |
row = random_row_indices_replace.pop(0)
|
| 386 |
|
| 387 |
+
# Get current row data first to check for opponent conflicts
|
| 388 |
+
if specific_columns != []:
|
| 389 |
+
current_row_data = working_frame.loc[row][specific_columns]
|
| 390 |
+
else:
|
| 391 |
+
current_row_data = working_frame.loc[row]
|
| 392 |
+
|
| 393 |
+
# NEW: Check if exposure_player conflicts with existing players
|
| 394 |
+
if check_opponent_conflict(exposure_player, current_row_data, opp_map):
|
| 395 |
continue # Skip this row, can't add exposure_player here
|
| 396 |
|
| 397 |
if specific_replacements != []:
|
|
|
|
| 425 |
comparable_players = comparable_players[comparable_players['player_names'] != exposure_player]
|
| 426 |
|
| 427 |
comparable_player_list = comparable_players['player_names'].tolist()
|
| 428 |
+
|
| 429 |
+
if exposure_player in working_frame.loc[row].values:
|
| 430 |
comparable_player_list = []
|
| 431 |
|
| 432 |
if comparable_player_list:
|
|
|
|
| 438 |
working_columns = working_frame.columns
|
| 439 |
|
| 440 |
for col in working_columns:
|
| 441 |
+
if row_data[col] in comparable_player_list:
|
|
|
|
| 442 |
current_lineup_salary = working_frame.loc[row]['salary']
|
| 443 |
+
current_player = row_data[col]
|
| 444 |
|
| 445 |
if check_salary_eligibility(current_lineup_salary, current_player, exposure_player, col, projections_df, type_var, salary_max):
|
| 446 |
if type_var == 'Classic':
|