James McCool
commited on
Commit
·
c375de1
1
Parent(s):
3c6a773
Refactor player data handling in grab_contest_data and load_contest_file functions
Browse files- Restored the player ID mapping logic in grab_contest_data to ensure accurate player identification.
- Updated the combination of player positions and IDs to handle empty slots more effectively, improving output clarity.
- Added logic in load_contest_file to replace None values with '-1', enhancing data consistency.
- These changes contribute to ongoing efforts to improve data integrity and user experience within the application.
global_func/grab_contest_data.py
CHANGED
@@ -23,16 +23,16 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
|
|
23 |
print(f"Warning: Mismatch for hash {lineup_hash}. IDs: {len(player_ids)}, Positions: {len(actual_positions)}")
|
24 |
return lineup_hash
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
# Just combine positions and PIDs without name mapping
|
35 |
-
combined_parts = [pos + pid for pos, pid in zip(actual_positions, player_ids)]
|
36 |
|
37 |
# Join them into a single string
|
38 |
return "".join(combined_parts)
|
@@ -58,7 +58,7 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
|
|
58 |
players_df = pd.DataFrame(player_data)
|
59 |
players_df = players_df.sort_values(by='ownership', ascending=False).reset_index(drop=True)
|
60 |
players_df = players_df.rename(columns={'fullName': 'Player', 'rosterPosition': 'Roster Position', 'ownership': '%Drafted', 'actualPoints': 'FPTS', 'salary': 'Salary', 'currentTeam': 'Team'})
|
61 |
-
|
62 |
|
63 |
for lineup_hash, lineup_info in lineups_json['lineups'].items():
|
64 |
lineup_data.append({
|
|
|
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
|
30 |
+
combined_parts.append(pos + '')
|
31 |
+
else:
|
32 |
+
combined_parts.append(pos + pid_map.get(pid, pid))
|
33 |
|
34 |
+
# # Just combine positions and PIDs without name mapping
|
35 |
+
# combined_parts = [pos + pid for pos, pid in zip(actual_positions, player_ids)]
|
36 |
|
37 |
# Join them into a single string
|
38 |
return "".join(combined_parts)
|
|
|
58 |
players_df = pd.DataFrame(player_data)
|
59 |
players_df = players_df.sort_values(by='ownership', ascending=False).reset_index(drop=True)
|
60 |
players_df = players_df.rename(columns={'fullName': 'Player', 'rosterPosition': 'Roster Position', 'ownership': '%Drafted', 'actualPoints': 'FPTS', 'salary': 'Salary', 'currentTeam': 'Team'})
|
61 |
+
pid_map = dict(zip(players_df['playerId'].astype(str), players_df['Player']))
|
62 |
|
63 |
for lineup_hash, lineup_info in lineups_json['lineups'].items():
|
64 |
lineup_data.append({
|
global_func/load_contest_file.py
CHANGED
@@ -43,6 +43,8 @@ def load_contest_file(upload, sport):
|
|
43 |
df[i] = df['Lineup'].str.split(',').str[i].str.strip()
|
44 |
# Remove position indicators from the end of each entry
|
45 |
df[i] = df[i].str.replace(r'\s+(' + '|'.join(pos_values) + r')$', '', regex=True)
|
|
|
|
|
46 |
|
47 |
if sport == 'MLB':
|
48 |
df = df.rename(columns={1: '1B', 2: '2B', 3: '3B', 4: 'C', 5: 'OF1', 6: 'OF2', 7: 'OF3', 8: 'SP1', 9: 'SP2', 10: 'SS'})
|
|
|
43 |
df[i] = df['Lineup'].str.split(',').str[i].str.strip()
|
44 |
# Remove position indicators from the end of each entry
|
45 |
df[i] = df[i].str.replace(r'\s+(' + '|'.join(pos_values) + r')$', '', regex=True)
|
46 |
+
# Replace None with -1
|
47 |
+
df[i] = df[i].fillna('-1')
|
48 |
|
49 |
if sport == 'MLB':
|
50 |
df = df.rename(columns={1: '1B', 2: '2B', 3: '3B', 4: 'C', 5: 'OF1', 6: 'OF2', 7: 'OF3', 8: 'SP1', 9: 'SP2', 10: 'SS'})
|