James McCool
commited on
Commit
·
032d464
1
Parent(s):
7deab18
Refactor grab_contest_data function to improve position handling
Browse files- Updated the logic for checking player ID and position counts to use actual positions, enhancing accuracy in data validation.
- Simplified the combination of player positions and IDs for clearer output formatting.
- These changes contribute to ongoing efforts to enhance data integrity and improve user experience within the application.
global_func/grab_contest_data.py
CHANGED
|
@@ -14,16 +14,19 @@ 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(
|
| 19 |
-
print(f"Warning: Mismatch for hash {lineup_hash}. IDs: {len(player_ids)}, Positions: {len(
|
| 20 |
return lineup_hash
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
|
| 25 |
# Join them into a single string
|
| 26 |
-
return "".join(
|
| 27 |
|
| 28 |
lineups_json = requests.get(lineups_url).json()
|
| 29 |
data_json = requests.get(data_url).json()
|
|
|
|
| 14 |
# Remove the leading colon and split by the remaining colons
|
| 15 |
player_ids = lineup_hash.lstrip(':').split(':')
|
| 16 |
|
| 17 |
+
# Get the actual positions needed for this lineup
|
| 18 |
+
actual_positions = positions[:len(player_ids)]
|
| 19 |
+
|
| 20 |
# Check if the number of IDs matches the number of positions
|
| 21 |
+
if len(player_ids) != len(actual_positions):
|
| 22 |
+
print(f"Warning: Mismatch for hash {lineup_hash}. IDs: {len(player_ids)}, Positions: {len(actual_positions)}")
|
| 23 |
return lineup_hash
|
| 24 |
|
| 25 |
+
# Combine positions and player IDs
|
| 26 |
+
combined_parts = [pos + pid_map.get(pid, pid) for pos, pid in zip(actual_positions, player_ids)]
|
| 27 |
|
| 28 |
# Join them into a single string
|
| 29 |
+
return "".join(combined_parts)
|
| 30 |
|
| 31 |
lineups_json = requests.get(lineups_url).json()
|
| 32 |
data_json = requests.get(data_url).json()
|