fix: correct NHL API situation structure for power play detection
The NHL API nests situationDescriptions under situation.homeTeam / situation.awayTeam, not at the top level. The old flat-structure lookup always returned an empty list, silently breaking both the PP indicator on the frontend and the PP bonus in the hype score. Updated get_power_play_info, the _priority_components PP check, and all test fixtures to match the real API shape. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
20
app/games.py
20
app/games.py
@@ -179,12 +179,16 @@ def get_start_time(game):
|
||||
|
||||
|
||||
def get_power_play_info(game, team_name):
|
||||
if "situation" in game and "situationDescriptions" in game["situation"]:
|
||||
for situation in game["situation"]["situationDescriptions"]:
|
||||
if situation == "PP" and game["awayTeam"]["name"]["default"] == team_name:
|
||||
return f"PP {game['situation']['timeRemaining']}"
|
||||
elif situation == "PP" and game["homeTeam"]["name"]["default"] == team_name:
|
||||
return f"PP {game['situation']['timeRemaining']}"
|
||||
situation = game.get("situation", {})
|
||||
if not situation:
|
||||
return ""
|
||||
time_remaining = situation.get("timeRemaining", "")
|
||||
home_descs = situation.get("homeTeam", {}).get("situationDescriptions", [])
|
||||
away_descs = situation.get("awayTeam", {}).get("situationDescriptions", [])
|
||||
if "PP" in home_descs and game["homeTeam"]["name"]["default"] == team_name:
|
||||
return f"PP {time_remaining}"
|
||||
if "PP" in away_descs and game["awayTeam"]["name"]["default"] == team_name:
|
||||
return f"PP {time_remaining}"
|
||||
return ""
|
||||
|
||||
|
||||
@@ -275,7 +279,9 @@ def _priority_components(game):
|
||||
# ── 8. Power play bonus ───────────────────────────────────────────────
|
||||
pp_bonus = 0
|
||||
situation = game.get("situation", {})
|
||||
if "PP" in situation.get("situationDescriptions", []):
|
||||
home_descs = situation.get("homeTeam", {}).get("situationDescriptions", [])
|
||||
away_descs = situation.get("awayTeam", {}).get("situationDescriptions", [])
|
||||
if "PP" in home_descs or "PP" in away_descs:
|
||||
if period >= 4:
|
||||
pp_bonus = 200
|
||||
elif period == 3 and time_remaining <= 300:
|
||||
|
||||
Reference in New Issue
Block a user