James McCool commited on
Commit
7bd0e86
·
1 Parent(s): 9916481

Enhance position handling in grab_contest_data function for MLB lineups

Browse files

- Updated the logic to correctly map player positions for 9-player MLB lineups, ensuring accurate output formatting.
- Simplified the handling of player IDs by removing unnecessary checks, improving data processing efficiency.
- These changes contribute to ongoing efforts to enhance data integrity and improve user experience within the application.

Files changed (1) hide show
  1. global_func/grab_contest_data.py +21 -10
global_func/grab_contest_data.py CHANGED
@@ -12,18 +12,29 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
12
  def format_lineup_string(lineup_hash, positions):
13
  """Replaces colons in a lineup hash with sequential positions."""
14
  # Remove the leading colon and split by the remaining colons
15
- # Only split on colons that are between numbers
16
- player_ids = [pid for pid in lineup_hash.lstrip(':').split(':') if pid.isdigit() or pid == '-1']
17
 
18
- # Get the actual positions needed for this lineup
19
- actual_positions = positions[:len(player_ids)]
20
-
21
- # Check if the number of IDs matches the number of positions
22
- if len(player_ids) != len(actual_positions):
23
- print(f"Warning: Mismatch for hash {lineup_hash}. IDs: {len(player_ids)}, Positions: {len(actual_positions)}")
24
- return lineup_hash
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- # Combine positions and player IDs, only for valid player IDs
27
  combined_parts = []
28
  for pos, pid in zip(actual_positions, player_ids):
29
  if pid == '-1': # Handle empty slots
 
12
  def format_lineup_string(lineup_hash, positions):
13
  """Replaces colons in a lineup hash with sequential positions."""
14
  # Remove the leading colon and split by the remaining colons
15
+ player_ids = lineup_hash.lstrip(':').split(':')
 
16
 
17
+ # For MLB, we need to handle the specific position order
18
+ if len(player_ids) == 9: # 9-player lineup
19
+ # Map positions to the correct order for a 9-player lineup
20
+ position_map = {
21
+ 0: '1B ',
22
+ 1: ' 2B ',
23
+ 2: ' 3B ',
24
+ 3: ' C ',
25
+ 4: ' OF ',
26
+ 5: ' OF ',
27
+ 6: ' P ',
28
+ 7: ' P ',
29
+ 8: ' SS '
30
+ }
31
+ # Use the mapped positions instead of the full position list
32
+ actual_positions = [position_map[i] for i in range(len(player_ids))]
33
+ else:
34
+ # For other cases, use the standard position list
35
+ actual_positions = positions[:len(player_ids)]
36
 
37
+ # Combine positions and player IDs
38
  combined_parts = []
39
  for pos, pid in zip(actual_positions, player_ids):
40
  if pid == '-1': # Handle empty slots