James McCool commited on
Commit
972bd0b
·
1 Parent(s): 73a4cc3

Refactor player ID mapping in grab_contest_data for improved clarity and accuracy

Browse files

- Updated the logic for combining player positions and IDs to map player names directly, enhancing the readability of the output.
- Removed the regex replacement for lineup strings, simplifying the data handling process.
- These changes contribute to ongoing efforts to improve data integrity and user experience within the application.

Files changed (1) hide show
  1. global_func/grab_contest_data.py +3 -4
global_func/grab_contest_data.py CHANGED
@@ -19,11 +19,11 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
19
  print(f"Warning: Mismatch for hash {lineup_hash}. IDs: {len(player_ids)}, Positions: {len(positions)}")
20
  return lineup_hash
21
 
22
- # Combine positions and player IDs
23
- combined_parts = [pos + pid for pos, pid in zip(positions, player_ids)]
24
 
25
  # Join them into a single string
26
- return "".join(combined_parts)
27
 
28
  lineups_json = requests.get(lineups_url).json()
29
  data_json = requests.get(data_url).json()
@@ -65,7 +65,6 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
65
  lineups_df = lineups_df.rename(columns={'index': 'Rank', 'points': 'Points', 'entryNameList': 'EntryName', 'lineupHash': 'Lineup'})
66
  lineups_df['EntryName'] = lineups_df['EntryName'] + ' (1/1)'
67
  lineups_df['Lineup'] = lineups_df['Lineup'].apply(lambda x: format_lineup_string(x, position_inserts))
68
- lineups_df['Lineup'] = lineups_df['Lineup'].replace(pid_map, regex=True) # Note: back to regex=True
69
  lineups_df = lineups_df[['Rank', 'EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup']]
70
 
71
  total_data = lineups_df.merge(players_df, how='left', left_index=True, right_index=True)
 
19
  print(f"Warning: Mismatch for hash {lineup_hash}. IDs: {len(player_ids)}, Positions: {len(positions)}")
20
  return lineup_hash
21
 
22
+ # Map each player ID to their name and combine with position
23
+ mapped_parts = [pos + pid_map.get(pid, pid) for pos, pid in zip(positions, player_ids)]
24
 
25
  # Join them into a single string
26
+ return "".join(mapped_parts)
27
 
28
  lineups_json = requests.get(lineups_url).json()
29
  data_json = requests.get(data_url).json()
 
65
  lineups_df = lineups_df.rename(columns={'index': 'Rank', 'points': 'Points', 'entryNameList': 'EntryName', 'lineupHash': 'Lineup'})
66
  lineups_df['EntryName'] = lineups_df['EntryName'] + ' (1/1)'
67
  lineups_df['Lineup'] = lineups_df['Lineup'].apply(lambda x: format_lineup_string(x, position_inserts))
 
68
  lineups_df = lineups_df[['Rank', 'EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup']]
69
 
70
  total_data = lineups_df.merge(players_df, how='left', left_index=True, right_index=True)