James McCool commited on
Commit
313a2ff
·
1 Parent(s): 433ab29

Refine player ID handling in grab_contest_data function for improved formatting

Browse files

- Adjusted the combination of player positions and IDs to ensure consistent spacing around player IDs, enhancing the readability of the output.
- Updated the player ID mapping to include spaces, ensuring uniform formatting across the application.
- 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 +6 -7
global_func/grab_contest_data.py CHANGED
@@ -16,15 +16,14 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
16
 
17
  # Check if the number of IDs matches the number of positions
18
  if len(player_ids) != len(positions):
19
- # Handle potential errors - maybe return the original hash or log a warning
20
  print(f"Warning: Mismatch for hash {lineup_hash}. IDs: {len(player_ids)}, Positions: {len(positions)}")
21
- return lineup_hash # Or some other error indication
22
 
23
- # Combine positions and player IDs
24
- combined_parts = [pos + pid for pos, pid in zip(positions, player_ids)]
25
 
26
- # Join them into a single string
27
- return "".join(combined_parts)
28
 
29
  lineups_json = requests.get(lineups_url).json()
30
  data_json = requests.get(data_url).json()
@@ -47,7 +46,7 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
47
  players_df = pd.DataFrame(player_data)
48
  players_df = players_df.sort_values(by='ownership', ascending=False).reset_index(drop=True)
49
  players_df = players_df.rename(columns={'fullName': 'Player', 'rosterPosition': 'Roster Position', 'ownership': '%Drafted', 'actualPoints': 'FPTS', 'salary': 'Salary', 'currentTeam': 'Team'})
50
- pid_map = dict(zip(players_df['playerId'].astype(str), players_df['Player']))
51
 
52
  for lineup_hash, lineup_info in lineups_json['lineups'].items():
53
  lineup_data.append({
 
16
 
17
  # Check if the number of IDs matches the number of positions
18
  if len(player_ids) != len(positions):
 
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, ensuring spaces around player IDs
23
+ combined_parts = [f"{pos}{pid} " for pos, pid in zip(positions, player_ids)]
24
 
25
+ # Join them into a single string and strip trailing space
26
+ return "".join(combined_parts).rstrip()
27
 
28
  lineups_json = requests.get(lineups_url).json()
29
  data_json = requests.get(data_url).json()
 
46
  players_df = pd.DataFrame(player_data)
47
  players_df = players_df.sort_values(by='ownership', ascending=False).reset_index(drop=True)
48
  players_df = players_df.rename(columns={'fullName': 'Player', 'rosterPosition': 'Roster Position', 'ownership': '%Drafted', 'actualPoints': 'FPTS', 'salary': 'Salary', 'currentTeam': 'Team'})
49
+ pid_map = dict(zip(players_df['playerId'].astype(str).apply(lambda x: f" {x} "), players_df['Player']))
50
 
51
  for lineup_hash, lineup_info in lineups_json['lineups'].items():
52
  lineup_data.append({