fix: correct NHL API situation structure for power play detection
All checks were successful
CI / Lint (push) Successful in 6s
CI / Test (push) Successful in 6s
CI / Build & Push (push) Successful in 22s

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:
2026-03-29 19:37:31 -04:00
parent 9edc9914a3
commit 8e1c455ded
2 changed files with 42 additions and 14 deletions

View File

@@ -131,7 +131,8 @@ class TestGetPowerPlayInfo:
def test_returns_pp_info_for_away_team(self):
game = make_game(away_name="Bruins")
game["situation"] = {
"situationDescriptions": ["PP"],
"awayTeam": {"situationDescriptions": ["PP"]},
"homeTeam": {"situationDescriptions": ["SH"]},
"timeRemaining": "1:30",
}
assert get_power_play_info(game, "Bruins") == "PP 1:30"
@@ -139,7 +140,8 @@ class TestGetPowerPlayInfo:
def test_returns_pp_info_for_home_team(self):
game = make_game(home_name="Maple Leafs", away_name="Bruins")
game["situation"] = {
"situationDescriptions": ["PP"],
"homeTeam": {"situationDescriptions": ["PP"]},
"awayTeam": {"situationDescriptions": ["SH"]},
"timeRemaining": "0:45",
}
assert get_power_play_info(game, "Maple Leafs") == "PP 0:45"
@@ -287,7 +289,11 @@ class TestCalculateGamePriority:
game_state="LIVE",
period=4,
seconds_remaining=600,
situation={"situationDescriptions": ["PP"], "timeRemaining": "1:30"},
situation={
"homeTeam": {"situationDescriptions": ["PP"]},
"awayTeam": {"situationDescriptions": ["SH"]},
"timeRemaining": "1:30",
},
)
assert calculate_game_priority(with_pp) - calculate_game_priority(base) == 200
@@ -301,7 +307,11 @@ class TestCalculateGamePriority:
game_state="LIVE",
period=3,
seconds_remaining=240,
situation={"situationDescriptions": ["PP"], "timeRemaining": "1:30"},
situation={
"homeTeam": {"situationDescriptions": ["PP"]},
"awayTeam": {"situationDescriptions": ["SH"]},
"timeRemaining": "1:30",
},
)
assert calculate_game_priority(with_pp) - calculate_game_priority(base) == 150
@@ -315,7 +325,11 @@ class TestCalculateGamePriority:
game_state="LIVE",
period=3,
seconds_remaining=600,
situation={"situationDescriptions": ["PP"], "timeRemaining": "1:30"},
situation={
"homeTeam": {"situationDescriptions": ["PP"]},
"awayTeam": {"situationDescriptions": ["SH"]},
"timeRemaining": "1:30",
},
)
assert calculate_game_priority(with_pp) - calculate_game_priority(base) == 100
@@ -329,7 +343,11 @@ class TestCalculateGamePriority:
game_state="LIVE",
period=3,
seconds_remaining=900,
situation={"situationDescriptions": ["PP"], "timeRemaining": "1:30"},
situation={
"homeTeam": {"situationDescriptions": ["PP"]},
"awayTeam": {"situationDescriptions": ["SH"]},
"timeRemaining": "1:30",
},
)
assert calculate_game_priority(with_pp) - calculate_game_priority(base) == 50
@@ -343,7 +361,11 @@ class TestCalculateGamePriority:
game_state="LIVE",
period=1,
seconds_remaining=600,
situation={"situationDescriptions": ["PP"], "timeRemaining": "1:30"},
situation={
"homeTeam": {"situationDescriptions": ["PP"]},
"awayTeam": {"situationDescriptions": ["SH"]},
"timeRemaining": "1:30",
},
)
assert calculate_game_priority(with_pp) - calculate_game_priority(base) == 30