- Empty net detection: pulled goalie triggers +150-250 bonus, stacks with PP - Playoff series importance: Game 7 Cup Final = 200, elimination games scale by round; fallback of 100 when series data unavailable - Period-aware score differential: 2-goal deficit penalty DECREASES in final 2 min of P3 (goalie-pull zone), 3+ goal games get harsher penalties late - Persistent comeback narrative: tracks max deficit, sustained bonus for 2+ goal recoveries instead of one-shot spike (0-3 to 3-3 = 150 persistent) - Shootout special handling: flat base 550 with no time component; ranks below dramatic close P3 games (skills competition, not hockey) - Multi-man advantage: parses situationCode for 5v3/4v3, applies 1.6x PP mult - Non-linear time priority: elapsed^1.5 curve weights final minutes more - Matchup multiplier rebalance: P1/P2 from 2.0/1.65 to 1.5, tiebreaker not dominant factor - Frontend gauge max raised from 700 to 1000 with adjusted color thresholds Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
101 lines
2.9 KiB
Python
101 lines
2.9 KiB
Python
import json
|
|
import sqlite3
|
|
|
|
import pytest
|
|
|
|
|
|
def make_game(
|
|
game_state="LIVE",
|
|
home_name="Maple Leafs",
|
|
away_name="Bruins",
|
|
home_score=2,
|
|
away_score=1,
|
|
period=3,
|
|
seconds_remaining=300,
|
|
in_intermission=False,
|
|
start_time_utc="2024-04-10T23:00:00Z",
|
|
home_record="40-25-10",
|
|
away_record="38-27-09",
|
|
game_type=2,
|
|
situation=None,
|
|
series_status=None,
|
|
):
|
|
clock = {
|
|
"timeRemaining": f"{seconds_remaining // 60:02d}:{seconds_remaining % 60:02d}",
|
|
"secondsRemaining": seconds_remaining,
|
|
"running": game_state == "LIVE",
|
|
"inIntermission": in_intermission,
|
|
}
|
|
return {
|
|
"gameState": game_state,
|
|
"startTimeUTC": start_time_utc,
|
|
"periodDescriptor": {"number": period},
|
|
"clock": clock,
|
|
"homeTeam": {
|
|
"name": {"default": home_name},
|
|
"score": home_score,
|
|
"sog": 15,
|
|
"logo": "https://example.com/home.png",
|
|
"record": home_record,
|
|
},
|
|
"awayTeam": {
|
|
"name": {"default": away_name},
|
|
"score": away_score,
|
|
"sog": 12,
|
|
"logo": "https://example.com/away.png",
|
|
"record": away_record,
|
|
},
|
|
"gameOutcome": {"lastPeriodType": "REG"},
|
|
"gameType": game_type,
|
|
**({"situation": situation} if situation is not None else {}),
|
|
**({"seriesStatus": series_status} if series_status is not None else {}),
|
|
}
|
|
|
|
|
|
LIVE_GAME = make_game()
|
|
PRE_GAME = make_game(
|
|
game_state="FUT", home_score=0, away_score=0, period=0, seconds_remaining=1200
|
|
)
|
|
FINAL_GAME = make_game(game_state="OFF", period=3, seconds_remaining=0)
|
|
|
|
SAMPLE_SCOREBOARD = {"games": [LIVE_GAME, PRE_GAME, FINAL_GAME]}
|
|
|
|
|
|
@pytest.fixture()
|
|
def sample_scoreboard():
|
|
return SAMPLE_SCOREBOARD
|
|
|
|
|
|
@pytest.fixture()
|
|
def flask_client(tmp_path, monkeypatch):
|
|
data_dir = tmp_path / "data"
|
|
data_dir.mkdir()
|
|
|
|
# Write sample scoreboard JSON
|
|
scoreboard_file = data_dir / "scoreboard_data.json"
|
|
scoreboard_file.write_text(json.dumps(SAMPLE_SCOREBOARD))
|
|
|
|
# Create minimal SQLite DB so get_team_standings doesn't crash
|
|
db_path = data_dir / "nhl_standings.db"
|
|
conn = sqlite3.connect(str(db_path))
|
|
conn.execute(
|
|
"CREATE TABLE standings "
|
|
"(team_common_name TEXT, league_sequence INTEGER, league_l10_sequence INTEGER, "
|
|
"division_abbrev TEXT, conference_abbrev TEXT, games_played INTEGER, wildcard_sequence INTEGER)"
|
|
)
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
# Patch module-level path constants so no reloads are needed
|
|
import app.routes as routes
|
|
import app.games as games
|
|
|
|
monkeypatch.setattr(routes, "SCOREBOARD_DATA_FILE", str(scoreboard_file))
|
|
monkeypatch.setattr(games, "DB_PATH", str(db_path))
|
|
|
|
from app import app as flask_app
|
|
|
|
flask_app.config["TESTING"] = True
|
|
with flask_app.test_client() as client:
|
|
yield client
|