James McCool
commited on
Commit
·
9916481
1
Parent(s):
032d464
Enhance player ID processing in grab_contest_data function
Browse files- Updated the logic for splitting lineup hashes to only include valid player IDs, improving data accuracy.
- Refined the combination of player positions and IDs to handle empty slots more effectively, ensuring 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
|
@@ -12,7 +12,8 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
|
|
| 12 |
def format_lineup_string(lineup_hash, positions):
|
| 13 |
"""Replaces colons in a lineup hash with sequential positions."""
|
| 14 |
# Remove the leading colon and split by the remaining colons
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
# Get the actual positions needed for this lineup
|
| 18 |
actual_positions = positions[:len(player_ids)]
|
|
@@ -22,8 +23,13 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
|
|
| 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 = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Join them into a single string
|
| 29 |
return "".join(combined_parts)
|
|
|
|
| 12 |
def format_lineup_string(lineup_hash, positions):
|
| 13 |
"""Replaces colons in a lineup hash with sequential positions."""
|
| 14 |
# Remove the leading colon and split by the remaining colons
|
| 15 |
+
# Only split on colons that are between numbers
|
| 16 |
+
player_ids = [pid for pid in lineup_hash.lstrip(':').split(':') if pid.isdigit() or pid == '-1']
|
| 17 |
|
| 18 |
# Get the actual positions needed for this lineup
|
| 19 |
actual_positions = positions[:len(player_ids)]
|
|
|
|
| 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 |
# Join them into a single string
|
| 35 |
return "".join(combined_parts)
|