James McCool commited on
Commit
8db1f1d
·
1 Parent(s): 313a2ff

Add debug prints to grab_contest_data for improved traceability

Browse files

- Introduced print statements to display examples of lineup_hash, player_ids, and formatted results, aiding in debugging and understanding data transformations.
- Enhanced visibility of player ID mappings by printing the first three entries of pid_map, facilitating easier verification of data integrity.
- These changes support ongoing efforts to improve data handling and user experience within the application.

Files changed (1) hide show
  1. global_func/grab_contest_data.py +19 -4
global_func/grab_contest_data.py CHANGED
@@ -14,16 +14,22 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
14
  # Remove the leading colon and split by the remaining colons
15
  player_ids = lineup_hash.lstrip(':').split(':')
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()
@@ -47,6 +53,10 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
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({
@@ -65,7 +75,12 @@ 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=False)
 
 
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)
 
14
  # Remove the leading colon and split by the remaining colons
15
  player_ids = lineup_hash.lstrip(':').split(':')
16
 
17
+ # Print example of what we're working with
18
+ print(f"Example lineup_hash: {lineup_hash}")
19
+ print(f"Split player_ids: {player_ids}")
20
+
21
  # Check if the number of IDs matches the number of positions
22
  if len(player_ids) != len(positions):
23
  print(f"Warning: Mismatch for hash {lineup_hash}. IDs: {len(player_ids)}, Positions: {len(positions)}")
24
  return lineup_hash
25
 
26
+ # Combine positions and player IDs
27
+ combined_parts = [pos + pid for pos, pid in zip(positions, player_ids)]
28
+ result = "".join(combined_parts)
29
 
30
+ # Print example of the result
31
+ print(f"Formatted result: {result}")
32
+ return result
33
 
34
  lineups_json = requests.get(lineups_url).json()
35
  data_json = requests.get(data_url).json()
 
53
  players_df = players_df.sort_values(by='ownership', ascending=False).reset_index(drop=True)
54
  players_df = players_df.rename(columns={'fullName': 'Player', 'rosterPosition': 'Roster Position', 'ownership': '%Drafted', 'actualPoints': 'FPTS', 'salary': 'Salary', 'currentTeam': 'Team'})
55
  pid_map = dict(zip(players_df['playerId'].astype(str).apply(lambda x: f" {x} "), players_df['Player']))
56
+ print("Example pid_map entries:")
57
+ for i, (pid, name) in enumerate(pid_map.items()):
58
+ if i < 3: # Print first 3 entries
59
+ print(f"ID: '{pid}' -> Name: '{name}'")
60
 
61
  for lineup_hash, lineup_info in lineups_json['lineups'].items():
62
  lineup_data.append({
 
75
  lineups_df = lineups_df.rename(columns={'index': 'Rank', 'points': 'Points', 'entryNameList': 'EntryName', 'lineupHash': 'Lineup'})
76
  lineups_df['EntryName'] = lineups_df['EntryName'] + ' (1/1)'
77
  lineups_df['Lineup'] = lineups_df['Lineup'].apply(lambda x: format_lineup_string(x, position_inserts))
78
+ # Print example before and after replacement
79
+ print("\nExample before replacement:")
80
+ print(lineups_df['Lineup'].iloc[0])
81
  lineups_df['Lineup'] = lineups_df['Lineup'].replace(pid_map, regex=False)
82
+ print("\nExample after replacement:")
83
+ print(lineups_df['Lineup'].iloc[0])
84
  lineups_df = lineups_df[['Rank', 'EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup']]
85
 
86
  total_data = lineups_df.merge(players_df, how='left', left_index=True, right_index=True)