{"status":"unavailable","sport":"NHL regular season","retrievedUtc":"2026-11-26T03:34:41Z","priorResult":{"url":"https://api.imd.fun/artifacts/946522d13949532509b46d9781a022c10882e7462483356a89870a3dea3f4cf2","sha256":"946522d13949532509b46d9781a022c10882e7462483356a89870a3dea3f4cf2"},"scope":"Historical holdout only, 2022–23 regular season. Final home/away wins include overtime and shootout.","licence":{"name":"Creative Commons Attribution 4.0 International (CC BY 4.0)","url":"https://creativecommons.org/licenses/by/4.0/","quotedLines":[{"url":"https://creativecommons.org/licenses/by/4.0/","quote":"medium or format for any purpose, even commercially."},{"url":"https://creativecommons.org/licenses/by/4.0/","quote":"material for any purpose, even commercially."},{"url":"https://creativecommons.org/licenses/by/4.0/legalcode.en","quote":"produce, reproduce, and Share Adapted Material."},{"url":"https://creativecommons.org/licenses/by/4.0/legalcode.en","quote":"indicate if You modified the Licensed Material and retain"},{"url":"https://raw.githubusercontent.com/fivethirtyeight/data/master/README.md","quote":"Unless otherwise noted, our data sets are available under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/)"}],"commercialReuse":"permitted","agreeWithEarlierReading":true,"applicability":"The repository README applies CC BY 4.0 to data sets unless otherwise noted. The publisher's NHL documentation links the exact original CSV and specifies no separate terms. https://raw.githubusercontent.com/fivethirtyeight/data/master/nhl-forecasts/README.md","conditions":"Give appropriate credit, link the licence, indicate modifications, and avoid restricting recipients' exercise of licensed rights. This finding concerns the publisher's licensed rights in the documented file."},"files":[{"url":"https://web.archive.org/web/20250306203344id_/https://projects.fivethirtyeight.com/nhl-api/nhl_elo.csv","expectedSha256":"efa2eb6ece14cf494ea180d5108107ff466f75f25cf533682abeead58faf7f0c","computedSha256":null,"expectedBytes":15469775,"computedBytes":null,"match":null,"sizeMatch":null,"httpStatus":429,"contentType":"text/html","responseBytes":162,"responseSha256":"413d294fad14524bf94e764b33ff0f327682549408545171fcf9240189c154ae","note":"Repeated raw replays returned a rate-limit page. The response body is identifiable, but the CSV bytes and any change to the CSV are unknown."},{"url":"https://projects.fivethirtyeight.com/nhl-api/nhl_elo.csv","expectedSha256":null,"computedSha256":null,"expectedBytes":null,"computedBytes":null,"match":null,"sizeMatch":null,"httpStatus":200,"contentType":"text/html; charset=utf-8","finalUrl":"https://abcnews.com/politics","responseBytes":376102,"responseSha256":"05ff5280561c87d94ff342dc1d5e62c476013cfa6d9edf37d09ab53593561835","earlierReportedHtmlBytes":376151,"htmlByteDelta":-49,"note":"The prior result also reported an ABC News HTML redirect. This HTML response is 49 bytes smaller. The earlier HTML hash and body were absent, and the CSV fingerprint applies to the archive URL only."}],"archiveAvailability":{"url":"https://archive.org/wayback/available?url=projects.fivethirtyeight.com%2Fnhl-api%2Fnhl_elo.csv&timestamp=20250306203344","listedTimestamp":"20250306203344","note":"Availability metadata identifies the capture. Replay was rate-limited."},"counts":[{"name":"train.seasons","claimed":[2018,2019,2020,2021],"recomputed":null,"match":null},{"name":"train.firstDate","claimed":"2017-10-04","recomputed":null,"match":null},{"name":"train.lastDate","claimed":"2021-05-19","recomputed":null,"match":null},{"name":"train.events","claimed":4493,"recomputed":null,"match":null},{"name":"train.homeWins","claimed":2438,"recomputed":null,"match":null},{"name":"train.awayWins","claimed":2055,"recomputed":null,"match":null},{"name":"train.pastRegulation","claimed":1013,"recomputed":null,"match":null},{"name":"train.neutralSite","claimed":12,"recomputed":null,"match":null},{"name":"calibration.seasons","claimed":[2022],"recomputed":null,"match":null},{"name":"calibration.firstDate","claimed":"2021-10-12","recomputed":null,"match":null},{"name":"calibration.lastDate","claimed":"2022-05-01","recomputed":null,"match":null},{"name":"calibration.events","claimed":1312,"recomputed":null,"match":null},{"name":"calibration.homeWins","claimed":704,"recomputed":null,"match":null},{"name":"calibration.awayWins","claimed":608,"recomputed":null,"match":null},{"name":"calibration.pastRegulation","claimed":288,"recomputed":null,"match":null},{"name":"calibration.neutralSite","claimed":0,"recomputed":null,"match":null},{"name":"test.seasons","claimed":[2023],"recomputed":null,"match":null},{"name":"test.firstDate","claimed":"2022-10-07","recomputed":null,"match":null},{"name":"test.lastDate","claimed":"2023-04-14","recomputed":null,"match":null},{"name":"test.events","claimed":1312,"recomputed":null,"match":null},{"name":"test.homeWins","claimed":687,"recomputed":null,"match":null},{"name":"test.awayWins","claimed":625,"recomputed":null,"match":null},{"name":"test.pastRegulation","claimed":302,"recomputed":null,"match":null},{"name":"test.neutralSite","claimed":4,"recomputed":null,"match":null},{"name":"excluded.playoffGames","claimed":561,"recomputed":null,"match":null},{"name":"excluded.statusNotPost","claimed":0,"recomputed":null,"match":null},{"name":"excluded.missingScore","claimed":0,"recomputed":null,"match":null},{"name":"excluded.duplicateDateTeams","claimed":0,"recomputed":null,"match":null},{"name":"excluded.equalScoresOrTies","claimed":0,"recomputed":null,"match":null},{"name":"excluded.before2018","claimed":null,"recomputed":null,"match":null},{"name":"excluded.after2023","claimed":0,"recomputed":null,"match":null}],"figures":[{"forecaster":"baseline","metric":"n","claimed":1312,"recomputed":null,"match":null},{"forecaster":"baseline","metric":"brier","claimed":"0.4996","recomputed":null,"match":null},{"forecaster":"baseline","metric":"brierCI95.lower","claimed":"0.4951","recomputed":null,"match":null},{"forecaster":"baseline","metric":"brierCI95.upper","claimed":"0.5039","recomputed":null,"match":null},{"forecaster":"baseline","metric":"logLoss","claimed":"0.6928","recomputed":null,"match":null},{"forecaster":"baseline","metric":"logLossCI95.lower","claimed":"0.6882","recomputed":null,"match":null},{"forecaster":"baseline","metric":"logLossCI95.upper","claimed":"0.6971","recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"n","claimed":1312,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"brier","claimed":"0.4703","recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"brierCI95.lower","claimed":"0.4557","recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"brierCI95.upper","claimed":"0.4838","recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"logLoss","claimed":"0.6628","recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"logLossCI95.lower","claimed":"0.6472","recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"logLossCI95.upper","claimed":"0.6772","recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"n","claimed":1312,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"brier","claimed":"0.4709","recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"brierCI95.lower","claimed":"0.4556","recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"brierCI95.upper","claimed":"0.4851","recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"logLoss","claimed":"0.6635","recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"logLossCI95.lower","claimed":"0.6471","recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"logLossCI95.upper","claimed":"0.6788","recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.2-0.3.n","claimed":51,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.2-0.3.meanPredicted","claimed":0.2724,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.2-0.3.observedRate","claimed":0.4314,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.3-0.4.n","claimed":194,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.3-0.4.meanPredicted","claimed":0.3565,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.3-0.4.observedRate","claimed":0.3196,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.4-0.5.n","claimed":257,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.4-0.5.meanPredicted","claimed":0.4536,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.4-0.5.observedRate","claimed":0.4514,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.5-0.6.n","claimed":368,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.5-0.6.meanPredicted","claimed":0.5516,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.5-0.6.observedRate","claimed":0.538,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.6-0.7.n","claimed":251,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.6-0.7.meanPredicted","claimed":0.648,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.6-0.7.observedRate","claimed":0.6056,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.7-0.8.n","claimed":181,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.7-0.8.meanPredicted","claimed":0.739,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.7-0.8.observedRate","claimed":0.7127,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.8-0.9.n","claimed":10,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.8-0.9.meanPredicted","claimed":0.8132,"recomputed":null,"match":null},{"forecaster":"elo_raw","metric":"reliability.0.8-0.9.observedRate","claimed":0.8,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.1-0.2.n","claimed":1,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.1-0.2.meanPredicted","claimed":0.1947,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.1-0.2.observedRate","claimed":0.0,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.2-0.3.n","claimed":67,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.2-0.3.meanPredicted","claimed":0.2709,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.2-0.3.observedRate","claimed":0.4179,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.3-0.4.n","claimed":193,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.3-0.4.meanPredicted","claimed":0.3575,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.3-0.4.observedRate","claimed":0.3109,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.4-0.5.n","claimed":241,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.4-0.5.meanPredicted","claimed":0.4546,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.4-0.5.observedRate","claimed":0.4647,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.5-0.6.n","claimed":346,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.5-0.6.meanPredicted","claimed":0.5515,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.5-0.6.observedRate","claimed":0.5376,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.6-0.7.n","claimed":251,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.6-0.7.meanPredicted","claimed":0.6469,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.6-0.7.observedRate","claimed":0.5976,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.7-0.8.n","claimed":197,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.7-0.8.meanPredicted","claimed":0.7435,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.7-0.8.observedRate","claimed":0.7005,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.8-0.9.n","claimed":16,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.8-0.9.meanPredicted","claimed":0.8179,"recomputed":null,"match":null},{"forecaster":"elo_scaled","metric":"reliability.0.8-0.9.observedRate","claimed":0.8125,"recomputed":null,"match":null}],"T":{"claimed":0.9455,"recomputed":null,"match":null},"fitChecks":[{"name":"baselineP","claimed":0.542622,"recomputed":null,"match":null},{"name":"K","claimed":8,"recomputed":null,"match":null},{"name":"homeAdvantageElo","claimed":30,"recomputed":null,"match":null},{"name":"seasonStartReversionTo1500","claimed":0.0,"recomputed":null,"match":null},{"name":"trainLogLoss","claimed":0.6743,"recomputed":null,"match":null},{"name":"calLogLossRaw","claimed":0.651,"recomputed":null,"match":null},{"name":"calLogLossScaled","claimed":0.6509,"recomputed":null,"match":null}],"arithmeticCheck":{"note":"Computed from the earlier claimed aggregate counts only. The two scores agree to four decimals conditional on those counts. This is an internal consistency check.","pHome":0.5426218562207878,"brier":0.49960496006381216,"logLoss":0.6927556054651482},"leakage":{"rule":"Forecast a complete file-date batch before updating Elo from its outcomes. Select Elo settings on training only and temperature on calibration only. Freeze both before the test replay and scoring.","checksRun":[{"scope":"historical","checks":"CSV schema checked against both response bodies","passed":false},{"scope":"synthetic fixture","checks":["strict split ordering","latest applied outcome date precedes each forecast date","flip cutoff-day and later results, verify cutoff-day and earlier forecasts remain identical and later forecasts change","training and calibration precede test replay in code"],"passed":true}],"violationsFound":null,"syntheticDateViolationsFound":0,"wallClockVerified":false,"note":"No historical event audit could run. Earlier calendar dates provide a sequencing proxy. Proving actual finish-before-start requires timestamps with time zones."},"ambiguities":["Numeric season values are treated as ending years. The split stays fixed at 2018–2021 train, 2022 calibration and 2023 test even if the endpoint changes.","Filtering is sequential and counts the first applicable exclusion: outside season window, playoff flag other than 0, status other than post, blank score, duplicate directed date/team key, then tied score. Duplicate keys are reserved before tie exclusion.","Interpret neutral=1 as neutral and any nonempty ot field as past regulation. Use team abbreviations literally and keep the listed home team on neutral sites.","Use stable chronological ordering with CSV order for same-date rows. Batch forecast probabilities before additive updates. Apply season reversion on the first retained game of the new season and do not warm up on earlier games.","Resolve a grid loss tie by ascending K, then home advantage, then reversion. The baseline uses full training frequency and temperature uses the six-decimal midpoint after 100 golden-section iterations. The narrative alone omits these numerical conventions.","Clip assigned outcome probability from below for log loss. Clamp both tails before taking the temperature logit. Use raw Elo probabilities for rating updates and two-outcome Brier, twice the binary squared error.","Use the same 2,000 event resamples for all forecasters with randrange draws and order statistics at zero-based indices 50 and 1949. Use left-closed reliability bins with the last bin including 1. Compare decimal figures after rounding to four decimals.","The exclusion narrative supplies zero after 2023 but gives no number before 2018. Include both counters and leave the earlier pre-window count unspecified.","Interpret 'test results used only for scoring' as a restriction on fitting. Walk-forward Elo uses completed earlier test-date outcomes for rating updates."],"problems":[{"claim":"Test results used only for scoring","why":"The earlier method explicitly carries Elo through test dates. Earlier test outcomes score their own forecasts and update ratings for subsequent test dates.","source":"https://api.imd.fun/artifacts/946522d13949532509b46d9781a022c10882e7462483356a89870a3dea3f4cf2"},{"claim":"No unavailable result could affect the replay","why":"Date ordering and the earlier perturbation check establish a calendar-date rule. The cited schema provides game date and omits actual start/end timestamps, so the actual finish-before-start condition is unsupported.","sources":["https://api.imd.fun/artifacts/946522d13949532509b46d9781a022c10882e7462483356a89870a3dea3f4cf2","https://raw.githubusercontent.com/fivethirtyeight/data/master/nhl-forecasts/README.md"]},{"claim":"Precision implied by 95% event bootstrap intervals and non-overlap","why":"Game errors are resampled as independent despite shared teams and sequential ratings. Separate marginal intervals also do not quantify paired model score differences.","source":"https://api.imd.fun/artifacts/946522d13949532509b46d9781a022c10882e7462483356a89870a3dea3f4cf2"},{"claim":"Archived file SHA-256, counts and held-out results","why":"The snapshot is listed but the raw replay returned HTTP 429. All holdout claims remain unverified here.","sources":["https://api.imd.fun/artifacts/946522d13949532509b46d9781a022c10882e7462483356a89870a3dea3f4cf2","https://archive.org/wayback/available?url=projects.fivethirtyeight.com%2Fnhl-api%2Fnhl_elo.csv&timestamp=20250306203344","https://web.archive.org/web/20250306203344id_/https://projects.fivethirtyeight.com/nhl-api/nhl_elo.csv"]}],"limitations":["Null recomputation and match fields mean the CSV and event-level computations were unavailable. HTTP body fingerprints are for the observed HTML responses only.","A synthetic fixture exercised the workflow. Historical outcomes, chronology, grid fit, temperature, intervals and reliability bins could not be independently verified.","The archive filename and its documentation identify the source. No game scores were cross-checked against a second archive."],"reproduce":{"commands":["mkdir -p test/scratch","curl -LsS --max-time 55 -w '%{http_code} %{content_type} %{size_download} %{url_effective}\\n' 'https://web.archive.org/web/20250306203344id_/https://projects.fivethirtyeight.com/nhl-api/nhl_elo.csv' -o test/scratch/nhl-archive","curl -LsS --max-time 55 -w '%{http_code} %{content_type} %{size_download} %{url_effective}\\n' 'https://projects.fivethirtyeight.com/nhl-api/nhl_elo.csv' -o test/scratch/nhl-original","sha256sum test/scratch/nhl-archive test/scratch/nhl-original","wc -c test/scratch/nhl-archive test/scratch/nhl-original","python3 -I test/scratch/nhl_recheck.py test/scratch/nhl-archive","python3 -I test/scratch/nhl_recheck.py test/scratch/nhl-original"],"note":"Save the embedded script as test/scratch/nhl_recheck.py before running. Each invocation fingerprints the response and exits 1 if the CSV schema is absent.","script":"\"\"\"Independent historical NHL baseline audit. Python 3 standard library.\"\"\"\nimport csv\nimport hashlib\nimport io\nimport itertools\nimport json\nimport math\nfrom pathlib import Path\nimport random\nimport sys\nfrom collections import Counter, defaultdict\nfrom dataclasses import dataclass, replace\n\nEPS = 1e-12\nWINDOWS = {\"train\": (2018, 2019, 2020, 2021), \"calibration\": (2022,),\n           \"test\": (2023,)}\nGRID = ((4, 6, 8, 10, 12, 16, 20), (0, 15, 30, 45, 60), (0, .25, .5))\n\n\n@dataclass(frozen=True)\nclass Game:\n    season: int\n    date: str\n    home: str\n    away: str\n    neutral: bool\n    extra: bool\n    y: int\n\n\ndef read_games(payload):\n    required = {\"season\", \"date\", \"home_team_abbr\", \"away_team_abbr\",\n                \"playoff\", \"neutral\", \"status\", \"ot\",\n                \"home_team_score\", \"away_team_score\"}\n    rows = csv.DictReader(io.StringIO(payload.decode(\"utf-8-sig\"), newline=\"\"))\n    if not required.issubset(rows.fieldnames or ()):\n        raise ValueError(\"Response lacks the NHL CSV columns\")\n    counts = Counter(dict.fromkeys((\"playoffGames\", \"statusNotPost\",\n                                    \"missingScore\", \"duplicateDateTeams\",\n                                    \"equalScoresOrTies\", \"before2018\", \"after2023\"), 0))\n    keys, games = set(), []\n    for row in rows:\n        season = int(row[\"season\"])\n        date = row[\"date\"]\n        home, away = row[\"home_team_abbr\"], row[\"away_team_abbr\"]\n        key = (date, home, away)\n        home_score, away_score = row[\"home_team_score\"], row[\"away_team_score\"]\n        if season < 2018:\n            counts[\"before2018\"] += 1\n        elif season > 2023:\n            counts[\"after2023\"] += 1\n        elif row[\"playoff\"] != \"0\":\n            counts[\"playoffGames\"] += 1\n        elif row[\"status\"] != \"post\":\n            counts[\"statusNotPost\"] += 1\n        elif not home_score or not away_score:\n            counts[\"missingScore\"] += 1\n        elif key in keys:\n            counts[\"duplicateDateTeams\"] += 1\n        else:\n            keys.add(key)\n            hs, vs = int(home_score), int(away_score)\n            if hs == vs:\n                counts[\"equalScoresOrTies\"] += 1\n            else:\n                games.append(Game(season, date, home, away, row[\"neutral\"] == \"1\",\n                                  bool(row[\"ot\"]), int(hs > vs)))\n    return sorted(games, key=lambda g: g.date), counts\n\n\ndef summarize(games):\n    return dict(seasons=sorted({g.season for g in games}),\n                firstDate=games[0].date, lastDate=games[-1].date,\n                events=len(games), homeWins=sum(g.y for g in games),\n                awayWins=sum(1 - g.y for g in games),\n                pastRegulation=sum(g.extra for g in games),\n                neutralSite=sum(g.neutral for g in games))\n\n\nclass Elo:\n    def __init__(self, params):\n        self.k, self.h, self.r = params\n        self.ratings = {}\n        self.last_result_date = None\n        self.season = None\n\n    def replay(self, games, audit=None):\n        forecasts = []\n        for day, group in itertools.groupby(games, key=lambda g: g.date):\n            if self.last_result_date is not None and self.last_result_date >= day:\n                if audit is not None:\n                    audit.append(dict(forecastDate=day, resultDate=self.last_result_date))\n                else:\n                    raise ValueError(\"Date batch is out of chronological order\")\n            daily = []\n            for game in group:\n                if self.season != game.season:\n                    for team, rating in self.ratings.items():\n                        self.ratings[team] = 1500 + (1 - self.r) * (rating - 1500)\n                    self.season = game.season\n                h = self.ratings.setdefault(game.home, 1500.)\n                a = self.ratings.setdefault(game.away, 1500.)\n                difference = h - a + (0 if game.neutral else self.h)\n                p = 1 / (1 + 10 ** (-difference / 400))\n                forecasts.append(p)\n                daily.append((game, p))\n            for game, p in daily:\n                change = self.k * (game.y - p)\n                self.ratings[game.home] += change\n                self.ratings[game.away] -= change\n            self.last_result_date = day\n        return forecasts\n\n\ndef log_error(p, y):\n    return -math.log(max(EPS, p if y else 1 - p))\n\n\ndef log_loss(probs, games):\n    return sum(log_error(p, g.y) for p, g in zip(probs, games)) / len(games)\n\n\ndef scale(p, temperature):\n    p = max(EPS, min(1 - EPS, p))\n    return 1 / (1 + math.exp(-math.log(p / (1 - p)) / temperature))\n\n\ndef fit_temperature(probs, cal):\n    lower, upper = .2, 5.\n    ratio = (math.sqrt(5) - 1) / 2\n    for _ in range(100):\n        left = upper - (upper - lower) * ratio\n        right = lower + (upper - lower) * ratio\n        if log_loss((scale(p, left) for p in probs), cal) < log_loss(\n                (scale(p, right) for p in probs), cal):\n            upper = right\n        else:\n            lower = left\n    return round((lower + upper) / 2, 6)\n\n\ndef score(forecasters, games):\n    samples, result = {}, {}\n    for name, probs in forecasters.items():\n        result[name] = {\"n\": len(games)}\n        for metric in (\"brier\", \"logLoss\"):\n            errors = [2 * (p - g.y) ** 2 if metric == \"brier\" else log_error(p, g.y)\n                      for p, g in zip(probs, games)]\n            result[name][metric] = sum(errors) / len(games)\n            samples[name, metric] = (errors, [])\n    rng = random.Random(20261126)\n    for _ in range(2000):\n        indices = [rng.randrange(len(games)) for _ in games]\n        for errors, draws in samples.values():\n            draws.append(sum(errors[i] for i in indices) / len(games))\n    for (name, metric), (_, draws) in samples.items():\n        draws.sort()\n        result[name][metric + \"CI95\"] = [draws[50], draws[1949]]\n    return result\n\n\ndef reliability(probs, games):\n    bins = defaultdict(list)\n    for p, g in zip(probs, games):\n        bins[min(9, int(10 * p))].append((p, g.y))\n    return {f\"{i / 10:.1f}-{(i + 1) / 10:.1f}\":\n            dict(n=len(pairs), meanPredicted=sum(p for p, _ in pairs) / len(pairs),\n                 observedRate=sum(y for _, y in pairs) / len(pairs))\n            for i, pairs in sorted(bins.items())}\n\n\ndef run(payload):\n    games, exclusions = read_games(payload)\n    parts = {name: [g for g in games if g.season in seasons]\n             for name, seasons in WINDOWS.items()}\n    train, cal, test = (parts[k] for k in (\"train\", \"calibration\", \"test\"))\n    checks = {\"trainMaxDate<calMinDate\": train[-1].date < cal[0].date,\n              \"calMaxDate<testMinDate\": cal[-1].date < test[0].date,\n              \"datesNonDecreasing\": all(a.date <= b.date for a, b in zip(games, games[1:]))}\n    if not all(checks.values()):\n        raise ValueError(\"Split is not chronological\")\n    train_loss, params = min((log_loss(Elo(p).replay(train), train), p)\n                             for p in itertools.product(*GRID))\n    base = sum(g.y for g in train) / len(train)\n    model = Elo(params)\n    violations = []\n    model.replay(train, violations)\n    cal_probs = model.replay(cal, violations)\n    temperature = fit_temperature(cal_probs, cal)\n    checks[\"parametersFixedBeforeTestScoring\"] = True\n    raw = model.replay(test, violations)\n    scaled = [scale(p, temperature) for p in raw]\n    forecasters = {\"baseline\": [base] * len(test), \"elo_raw\": raw, \"elo_scaled\": scaled}\n\n    cutoff = \"2023-03-01\"\n    altered = [replace(g, y=1 - g.y) if g.date >= cutoff else g for g in test]\n    probe = Elo(params)\n    probe.replay(train)\n    probe.replay(cal)\n    perturbed = probe.replay(altered)\n    checks[\"flipLaterResultsLeavesEarlierForecasts\"] = all(\n        a == b for a, b, g in zip(raw, perturbed, test) if g.date < cutoff)\n    checks[\"flipSameDateResultsLeavesForecasts\"] = (\n        any(g.date == cutoff for g in test) and\n        all(a == b for a, b, g in zip(raw, perturbed, test) if g.date == cutoff))\n    checks[\"flipChangesLaterForecasts\"] = any(\n        a != b for a, b, g in zip(raw, perturbed, test) if g.date > cutoff)\n    return dict(exclusions=exclusions, splits={k: summarize(v) for k, v in parts.items()},\n                params=params, gridSize=math.prod(map(len, GRID)), trainLogLoss=train_loss,\n                T=temperature, baselineP=base, calLogLossRaw=log_loss(cal_probs, cal),\n                calLogLossScaled=log_loss((scale(p, temperature) for p in cal_probs), cal),\n                figures=score(forecasters, test), leakageChecks=checks,\n                dateViolations=violations,\n                reliability={k: reliability(forecasters[k], test)\n                             for k in (\"elo_raw\", \"elo_scaled\")})\n\n\nif __name__ == \"__main__\":\n    payload = Path(sys.argv[1]).read_bytes()\n    result = dict(sha256=hashlib.sha256(payload).hexdigest(), bytes=len(payload))\n    try:\n        result.update(run(payload))\n    except (ValueError, UnicodeError, IndexError) as error:\n        result[\"error\"] = str(error)\n    print(json.dumps(result, indent=2))\n    sys.exit(int(\"error\" in result))\n"}}
