fix: show correct "Game X of 7" for future playoff dates
Enrich raw score-endpoint games with gameNumber from the series cache before parsing. The score API omits gameNumber and its seriesStatus reflects current wins, so all future games in a series computed the same number. Now we cross-reference by game id against the cached series-detail endpoint which includes the correct gameNumber per game. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -158,6 +158,55 @@ def fetch_series(series_id):
|
||||
return None
|
||||
|
||||
|
||||
# ── Game-number enrichment ────────────────────────────────────────
|
||||
|
||||
|
||||
def enrich_game_numbers(raw_games):
|
||||
"""Inject gameNumber from cached series data into raw score-endpoint games.
|
||||
|
||||
The /v1/score/{date} endpoint omits gameNumber. For future dates the
|
||||
fallback computation (top_wins + bot_wins + 1) gives every game in a
|
||||
series the same number. The series-detail endpoint includes gameNumber,
|
||||
so we cross-reference by game id.
|
||||
"""
|
||||
need = {}
|
||||
for game in raw_games or []:
|
||||
if game.get("gameType") != 3:
|
||||
continue
|
||||
if isinstance(game.get("gameNumber"), int) and game["gameNumber"] > 0:
|
||||
continue
|
||||
ss = game.get("seriesStatus") or {}
|
||||
letter = ss.get("seriesLetter") or ss.get("seriesAbbrev")
|
||||
if not letter:
|
||||
continue
|
||||
start = game.get("startTimeUTC") or ""
|
||||
try:
|
||||
year = (
|
||||
datetime.fromisoformat(start.replace("Z", "+00:00"))
|
||||
.astimezone(EASTERN)
|
||||
.year
|
||||
)
|
||||
except (ValueError, AttributeError):
|
||||
year = datetime.now(EASTERN).year
|
||||
sid = f"{year}-{letter.upper()}"
|
||||
need.setdefault(sid, []).append(game)
|
||||
|
||||
for sid, games in need.items():
|
||||
payload = fetch_series(sid)
|
||||
if not payload:
|
||||
continue
|
||||
lookup = {}
|
||||
for sg in payload.get("games") or []:
|
||||
gid = sg.get("id")
|
||||
gn = sg.get("gameNumber")
|
||||
if gid is not None and isinstance(gn, int) and gn > 0:
|
||||
lookup[gid] = gn
|
||||
for game in games:
|
||||
gid = game.get("id")
|
||||
if gid is not None and gid in lookup:
|
||||
game["gameNumber"] = lookup[gid]
|
||||
|
||||
|
||||
# ── Per-round start dates (drive the "Day N" banner) ──────────────
|
||||
|
||||
ROUND_DATES_KEY = "meta:round_start_dates"
|
||||
|
||||
Reference in New Issue
Block a user