Files
longhikes/tools/tests/test_season_fit.py
T
swaitsandClaude Sonnet 5.5 748186d306 Estimate seasons by blending climate thresholds with the seasons of the most similar sourced trails, scored leave-one-out against the owner's measure
The earlier two-threshold rule matched 33 percent on a held-out half. The new method keeps the cold and heat thresholds and lets the twenty most similar sourced trails confirm or add months. Leave-one-out it matches 100 of 148 sourced seasons (67.6 percent), still under the 75 percent bar, so the fit file says it does not pass and estimates must not ship.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 12:36:37 -07:00

61 lines
2.1 KiB
Python

"""Tests for the committed fit figure in tools/season_fit.json.
Run from the repository root:
python3 -m unittest discover tools/tests
"""
import json
import os
import sys
import unittest
sys.dont_write_bytecode = True
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import estimate_season as E # noqa: E402
import refresh # noqa: E402
import validate as V # noqa: E402
FIT_PATH = os.path.join(V.ROOT, "tools", "season_fit.json")
def load_fit():
with open(FIT_PATH, encoding="utf-8") as f:
return json.load(f)
class SeasonFitFileTest(unittest.TestCase):
def test_the_committed_fit_has_the_fields_the_site_reads(self):
fit = load_fit()
for key in ("computed", "rule_version", "dataset", "period",
"params", "loo", "bar", "passes", "confidence"):
self.assertIn(key, fit)
self.assertEqual(sorted(fit["params"]), sorted(E.Params(0, 0).as_dict()))
for part in ("loo",):
for key in ("n", "within1", "worse", "no_data", "classified",
"jaccard", "by_group", "by_kind"):
self.assertIn(key, fit[part], part)
rep = fit[part]
self.assertEqual(rep["within1"] + rep["worse"] + rep["no_data"],
rep["n"], part)
self.assertEqual(fit["bar"], E.BAR)
self.assertEqual(fit["rule_version"], E.RULE_VERSION)
self.assertEqual(fit["passes"], E.passes_bar(fit["loo"], fit["bar"]))
def test_estimates_only_with_a_passing_fit(self):
estimated = []
for tid in refresh.trail_ids(V.ROOT):
rec = refresh.load_toml(os.path.join(V.ROOT, tid, "trail.toml"))
if (rec.get("hike") or {}).get("season_basis") == "estimate":
estimated.append(tid)
if not estimated:
self.skipTest("no estimated seasons on file yet")
fit = load_fit()
self.assertTrue(fit["passes"], fit)
held = fit["loo"]
self.assertGreaterEqual(held["within1"] / held["n"],
E.BAR["within1_min"])
if __name__ == "__main__":
unittest.main()