James McCool commited on
Commit
5fe15cf
·
1 Parent(s): 076e322

Refactor position eligibility check in 'exposure_spread' to improve clarity and maintainability, ensuring proper handling of player positions during lineup generation.

Browse files
Files changed (1) hide show
  1. global_func/exposure_spread.py +7 -8
global_func/exposure_spread.py CHANGED
@@ -245,7 +245,7 @@ def exposure_spread(working_frame, exposure_player, exposure_target, ignore_stac
245
  comparable_player_list = comparable_players['player_names'].tolist()
246
  except:
247
  comparable_player_list = []
248
-
249
  if comparable_player_list:
250
  insert_player = random.choice(comparable_player_list)
251
  # Find which column contains the exposure_player
@@ -268,8 +268,7 @@ def exposure_spread(working_frame, exposure_player, exposure_target, ignore_stac
268
  for row in random_row_indices_replace:
269
  if change_counter < math.ceil(lineups_to_add):
270
  if specific_replacements != []:
271
- comparable_players = projections_df[(projections_df['player_names'].isin(specific_replacements)) &
272
- (projections_df['salary'] <= comp_salary_high + (salary_max - working_frame['salary'][row]))
273
  ]
274
  else:
275
  comparable_players = projections_df[
@@ -301,12 +300,12 @@ def exposure_spread(working_frame, exposure_player, exposure_target, ignore_stac
301
  for col in working_frame.columns:
302
  if row_data[col] in comparable_player_list:
303
  if working_frame.iloc[row]['salary'] - projections_df[projections_df['player_names'] == row_data[col]]['salary'].iloc[0] + projections_df[projections_df['player_names'] == exposure_player]['salary'].iloc[0] <= salary_max:
304
- # Get the replacement player's positions
305
- replacement_player_positions = projections_df[projections_df['player_names'] == row_data[col]]['position'].iloc[0].split('/')
306
- exposure_player_positions = projections_df[projections_df['player_names'] == exposure_player]['position'].iloc[0].split('/')
307
-
308
- # Check if the replacement player is eligible for this column
309
  if type_var == 'Classic':
 
 
 
 
 
310
  if check_position_eligibility(sport_var, col, exposure_player_positions):
311
  working_frame.at[row, col] = exposure_player
312
  change_counter += 1
 
245
  comparable_player_list = comparable_players['player_names'].tolist()
246
  except:
247
  comparable_player_list = []
248
+
249
  if comparable_player_list:
250
  insert_player = random.choice(comparable_player_list)
251
  # Find which column contains the exposure_player
 
268
  for row in random_row_indices_replace:
269
  if change_counter < math.ceil(lineups_to_add):
270
  if specific_replacements != []:
271
+ comparable_players = projections_df[(projections_df['player_names'].isin(specific_replacements))
 
272
  ]
273
  else:
274
  comparable_players = projections_df[
 
300
  for col in working_frame.columns:
301
  if row_data[col] in comparable_player_list:
302
  if working_frame.iloc[row]['salary'] - projections_df[projections_df['player_names'] == row_data[col]]['salary'].iloc[0] + projections_df[projections_df['player_names'] == exposure_player]['salary'].iloc[0] <= salary_max:
 
 
 
 
 
303
  if type_var == 'Classic':
304
+ replacement_player_positions = projections_df[projections_df['player_names'] == row_data[col]]['position'].iloc[0].split('/')
305
+ exposure_player_positions = projections_df[projections_df['player_names'] == exposure_player]['position'].iloc[0].split('/')
306
+
307
+ # Check if the replacement player is eligible for this column
308
+
309
  if check_position_eligibility(sport_var, col, exposure_player_positions):
310
  working_frame.at[row, col] = exposure_player
311
  change_counter += 1