James McCool commited on
Commit
a266f29
·
1 Parent(s): 53d6dd0

Enhance player lineup processing in load_contest_file function

Browse files

- Improved the logic for cleaning player names by handling position indicators more effectively, ensuring accurate player assignments.
- Updated debug prints to show both original and cleaned lineups, enhancing traceability during execution.
- These changes contribute to ongoing efforts to refine data handling and improve user experience within the application.

Files changed (1) hide show
  1. global_func/load_contest_file.py +33 -7
global_func/load_contest_file.py CHANGED
@@ -84,20 +84,46 @@ def load_contest_file(upload, sport):
84
 
85
  # Process each lineup
86
  for idx, row in df.iterrows():
87
- # Get all players in the lineup
88
  players = row['Lineup'].split(',')
89
- players = [p.strip() for p in players if p.strip()]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  print(f"\nProcessing lineup {idx}:")
91
- print(f"Players found: {players}")
 
92
 
93
  # First pass: fill required positions (excluding OF)
94
  required_positions = ['SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS']
95
  for pos in required_positions:
96
- for player in players:
97
  if is_eligible_for_position(player, pos):
98
  print(f"Assigning {player} to {pos}")
99
  df.at[idx, pos] = player
100
- players.remove(player)
101
  break
102
  else:
103
  print(f"No player found for {pos}")
@@ -105,11 +131,11 @@ def load_contest_file(upload, sport):
105
  # Second pass: fill OF positions with remaining players
106
  of_positions = ['OF1', 'OF2', 'OF3']
107
  for pos in of_positions:
108
- for player in players:
109
  if 'OF' in pos_dict.get(player, '').split('/'):
110
  print(f"Assigning {player} to {pos}")
111
  df.at[idx, pos] = player
112
- players.remove(player)
113
  break
114
  else:
115
  print(f"No player found for {pos}, using -1")
 
84
 
85
  # Process each lineup
86
  for idx, row in df.iterrows():
87
+ # Get all players in the lineup and clean up the strings
88
  players = row['Lineup'].split(',')
89
+ cleaned_players = []
90
+ current_position = None
91
+
92
+ for item in players:
93
+ item = item.strip()
94
+ # If the item is just a position indicator, store it
95
+ if item in pos_values:
96
+ current_position = item
97
+ continue
98
+
99
+ # If we have a position and a player name
100
+ if current_position:
101
+ # Remove any trailing position indicators
102
+ for pos in pos_values:
103
+ if item.endswith(pos):
104
+ item = item[:-len(pos)].strip()
105
+ cleaned_players.append(item)
106
+ current_position = None
107
+ else:
108
+ # If we somehow got a player without a position, try to clean it
109
+ for pos in pos_values:
110
+ if item.endswith(pos):
111
+ item = item[:-len(pos)].strip()
112
+ break
113
+ cleaned_players.append(item)
114
+
115
  print(f"\nProcessing lineup {idx}:")
116
+ print(f"Original lineup: {row['Lineup']}")
117
+ print(f"Cleaned players: {cleaned_players}")
118
 
119
  # First pass: fill required positions (excluding OF)
120
  required_positions = ['SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS']
121
  for pos in required_positions:
122
+ for player in cleaned_players:
123
  if is_eligible_for_position(player, pos):
124
  print(f"Assigning {player} to {pos}")
125
  df.at[idx, pos] = player
126
+ cleaned_players.remove(player)
127
  break
128
  else:
129
  print(f"No player found for {pos}")
 
131
  # Second pass: fill OF positions with remaining players
132
  of_positions = ['OF1', 'OF2', 'OF3']
133
  for pos in of_positions:
134
+ for player in cleaned_players:
135
  if 'OF' in pos_dict.get(player, '').split('/'):
136
  print(f"Assigning {player} to {pos}")
137
  df.at[idx, pos] = player
138
+ cleaned_players.remove(player)
139
  break
140
  else:
141
  print(f"No player found for {pos}, using -1")