diff --git a/.github/workflows/season-check.yml b/.github/workflows/season-check.yml index 35c32fc..6ca4190 100644 --- a/.github/workflows/season-check.yml +++ b/.github/workflows/season-check.yml @@ -1,7 +1,8 @@ name: Season check -# Once a month, rerun the machine estimate for every estimated season and the fit against the -# sourced seasons. A failure lists the estimates whose inputs have changed; see docs/audit.md. +# Once a month, check offline that every estimated season is still on the track or location it +# was estimated for. Nothing is downloaded: the climate normals are a fixed published dataset. A +# failure lists the estimates whose inputs have changed; see docs/audit.md. on: schedule: - cron: "17 6 1 * *" @@ -10,17 +11,10 @@ on: jobs: check: runs-on: ubuntu-latest - timeout-minutes: 120 + timeout-minutes: 10 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: "3.12" - - id: month - run: echo "month=$(date +%Y-%m)" >> "$GITHUB_OUTPUT" - - uses: actions/cache@v4 - with: - path: ~/.cache/longhikes-climate - key: climate-${{ steps.month.outputs.month }} - restore-keys: climate- - run: python3 tools/estimate_season.py check diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f60b77..fc2385f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - How an estimate is made: a reviewer is given the trail's location and elevation, its monthly climate (CHELSA, public domain, with NOAA elevation), a climate model's own estimate, and the ten most similar trails whose season a page states, and sets the months. The climate model alone matched 67.6 percent of the known seasons within a month at each end, under the 75 percent the owner asked for, so it is one input and not the answer. - How it was tested: the same reviewers estimated the 148 trails whose season a page does state, from packets with that season hidden. Two measures, given together: 114 of 148 (77 percent) had their first and last months within a month of the page's; 105 (71 percent) also had no wrong gap in the middle. By confidence, first and last months: 48 of 52 where they were highly confident, 55 of 76 at medium confidence, and 11 of 20 at low; with no wrong gap as well: 48 of 52, 46 of 76 and 11 of 20. The 75 percent bar was set on the first and last months, and the method clears it there but not on the stricter measure. The owner decided the estimates ship with both figures stated. The reference page gives these figures, read from a data file. - The "By month" lists now include every trail and mark the estimated seasons, and the note that only some trails have a season is gone. The month filter has a box to leave estimated seasons out. -- An estimate is replaced when a page that states a season is found. The monthly audit searches again for every one, and a monthly check reruns the climate model for each estimate and flags any whose inputs have changed. +- An estimate is replaced when a page that states a season is found. The monthly audit searches again for every one, and a monthly check, which works offline and downloads nothing, flags any estimate whose trail's track or location has changed since the season was set. - For contributors: `hike.season_basis` may now be `estimate`, with a `hike.season_method` that ends "Confidence: high.", "Confidence: medium." or "Confidence: low." and one source that cites the climate data; a season is required on every trail, and the validator refuses an estimate that cites an ordinary page. The packet builder and the blind scorer are `tools/season_judge.py`, the reviewers' instruction is `docs/season-judging.md`, and the audit steps are in `docs/audit.md`. ## 2026-11-20 - Pages for national parks, mountain ranges and wilderness areas diff --git a/docs/audit.md b/docs/audit.md index 5544e52..25345cb 100644 --- a/docs/audit.md +++ b/docs/audit.md @@ -3,26 +3,32 @@ A written checklist for the owner. It does not repeat the refresh runbook; it points at it. Work down the list in order and stop at the first step that fails. -1. **Refresh the records.** Run `/refresh-trails` (the full run once a quarter, `light` in the - months between). It verifies every record against the pages it cites, re-checks the left-out - list, looks for missing trails and updates tracks and emblems. The runbook is +## Records and places + +1. **Refresh the records.** Run the `/refresh-trails` skill (the full run once a quarter, `light` + in the months between). It verifies every record against the pages it cites, re-checks the + left-out list, looks for missing trails and updates tracks and emblems. The runbook is `.claude/skills/refresh-trails/SKILL.md`; this checklist adds to it and does not replace it. 2. **Check the links.** `python3 tools/refresh.py links` lists every address a record cites that - no longer answers. Fix each one in a record with a history entry. + no longer answers (`--limit 20` is a quick trial). Fix each one in a record with a history + entry. 3. **Validate the data.** `python3 tools/validate.py` must end `OK trails`. It fails a record with no `places_checked`, and one whose track has changed since its places were measured. 4. **Check the history.** `python3 tools/check_history.py --base origin/main` must end `OK history`. A changed fact needs a new history entry. 5. **Run both test suites.** `python3 -m unittest discover tools/tests` and `python3 -m unittest discover -s web/tests` must both pass. -6. **Check the places.** `python3 tools/place_trails.py --check --refresh` downloads every outline again (without `--refresh` it reuses the files already in the cache, which are the ones first downloaded), - measures every track again and prints each difference from the records, one per line: - - a place gained or lost by a trail: re-run `place_trails.py propose`, read the line, and - apply it only when the new outline is right; - - a boundary that moved (a new source version): the owner rules whether the new outline - replaces the old one; - - a place that crossed the 3-trail line: its page appears or goes, so check its links and the - counts that name it. +6. **Check the places.** `.venv-places/bin/python tools/place_trails.py --check --refresh` + downloads every outline again (without `--refresh` it reuses the files already in the cache, + which are the ones first downloaded), measures every track again and prints each difference + from the records, one per line. The venv is made as `tools/place_trails.py --help` says. For + each line: + (a) a place gained or lost by a trail: run `.venv-places/bin/python tools/place_trails.py propose`, + read the line, and apply it only when the new outline is right; + (b) a boundary that moved (a new source version): the owner rules whether the new outline + replaces the old one; + (c) a place that crossed the 3-trail line: its page appears or goes, so check its links and the + counts that name it. The monthly workflow `.github/workflows/places.yml` runs this step by itself and fails with the list; this step is the one you run when it has failed, and before a release. 7. **Review the `stated` placements by hand.** A trail with no track is placed from a page, and no @@ -35,9 +41,11 @@ down the list in order and stop at the first step that fails. ## Seasons -Every trail has a season. Where a page states one, the season is that page's. Where none does, the season is an estimate: set by a reviewer from the trail's climate and the seasons of similar trails, with its confidence on the record (`docs/season-judging.md`). The aim of this audit is that estimates shrink over time, and that none goes stale unnoticed. +Every trail has a season. Where a page states one, the season is that page's. Where none does, the season is an estimate: set by a reviewer from the trail's climate and the seasons of similar trails, with its confidence on the record (`docs/season-judging.md`). Where pages from at least two publishers state different seasons and none is the trail's own, the season is set by judgement from all of them. The aim of this audit is that estimates shrink over time, and that none goes stale unnoticed. -1. Search afresh for a page that states the season of every trail still marked `estimate`. List them with `python3 tools/estimate_season.py estimates`. For each, follow `docs/season-research.md`: the trail's holder or a government page first, then an established hiking reference, a guidebook publisher's page or an association list. When a page states a season, replace the estimate through `tools/refresh.py` (propose, collect, apply): give the page's season and months, the basis (`primary`, `sources` or `source`), the page as a `[[hike.source]]` naming `season` and `months`, and remove the climate source and `season_method`. A change to the season gets a `[[history]]` entry like any other fact. Then run `python3 tools/season_judge.py inputs` so that the record of estimate inputs drops the trail. A trail with no page found stays an estimate, and nothing else about it changes. -2. Re-run the machine estimate and flag any estimate whose inputs have changed: `python3 tools/estimate_season.py check`. It reruns the machine estimate for every estimate, compares it, the climate at the trail and the sourced trails it is compared with against what was recorded in `tools/season_inputs.json` when the season was set, and lists each trail whose inputs differ. The listing is a flag, not a rewrite. For each trail listed, build its packet (`python3 tools/season_judge.py packets`), look at what changed, and either keep the season or set it again by judgement. Then run `python3 tools/season_judge.py inputs` to record the inputs as they now are. The check also fails when the blind test of the method (`tools/season_blind_test.json`) is below its bar on the ends-only measure (the first and last months within a month of the page's: 77 percent when set, against a bar of 75; the strict measure, which also needs no wrong gap in the middle, was 71 percent and is recorded beside it), or when the fit of the machine estimate against the sourced seasons has got worse. +The blind test behind the estimates has two figures, always read together: 114 of 148 (77 percent) had their first and last months within a month of the page's, and 105 (71 percent) also had no wrong gap in the middle. The 75 percent bar was set on the first measure; the second is below it. The owner decided that the estimates ship with both stated. + +1. Search afresh for a page that states the season of every trail still marked `estimate`. List them with `python3 tools/estimate_season.py estimates`. For each, follow `docs/season-research.md`: the trail's holder or a government page first, then an established hiking reference, a guidebook publisher's page or an association list. When a page states a season, replace the estimate through `tools/refresh.py` (stage a proposal, then `python3 tools/refresh.py collect` and `python3 tools/refresh.py apply`): give the page's season and months, the basis (`primary`, `sources` or `source`), the page as a `[[hike.source]]` naming `season` and `months`, and remove the climate source and `season_method`. A change to the season gets a `[[history]]` entry like any other fact. Then run `python3 tools/season_judge.py inputs --points` so that the record of estimate inputs drops the trail. A trail with no page found stays an estimate, and nothing else about it changes. +2. Check that no estimate has gone stale: `python3 tools/estimate_season.py check`. It works offline and downloads nothing. For every estimate it compares the digest of the trail's current track and location with the one recorded in `tools/season_inputs.json` when the season was set, and lists each trail where they differ or none is recorded. The listing is a flag, not a rewrite. For each trail listed, build its packet (`python3 tools/season_judge.py packets --out /tmp/season-packets`; it writes a packet for every trail and reads the climate, which is a large download the first time and cached after), look at what changed, and either keep the season or set it again by judgement. Then run `python3 tools/season_judge.py inputs --points ` to record the new digest. The climate normals are a fixed published dataset (CHELSA, 1981 to 2010), so they do not change from month to month and are not read again; `python3 tools/season_judge.py inputs ` (with the network) also records the machine estimate and the climate digest at the time, if a person wants them. The check also fails when the blind test of the method (`tools/season_blind_test.json`) is below its bar on the first-and-last-months measure (77 percent when set, against a bar of 75; the stricter figure, 71 percent, which also needs no wrong gap in the middle, is recorded beside it). The same check runs on its own on the first of each month (`.github/workflows/season-check.yml`), so a changed estimate is noticed even when the audit is late. The audit is still the step that acts on it. diff --git a/docs/superpowers/specs/2026-11-20-season-on-every-trail-design.md b/docs/superpowers/specs/2026-11-20-season-on-every-trail-design.md index 235f9b9..2fcb49c 100644 --- a/docs/superpowers/specs/2026-11-20-season-on-every-trail-design.md +++ b/docs/superpowers/specs/2026-11-20-season-on-every-trail-design.md @@ -108,10 +108,12 @@ left to someone remembering to run it (the owner's ruling): - **Every push.** The validator fails any record with no season, so a new trail cannot ship without one, sourced or estimated. -- **Every month.** A scheduled workflow runs `estimate_season.py --check`: it - re-runs every estimate and the fit against sourced seasons, and fails with - a list of estimates that would now come out different, or a fit that has - got worse. +- **Every month.** A scheduled workflow runs `estimate_season.py check`, + offline and with no download: it compares the digest of each estimate's + current track and location with the one recorded when the season was set, + and fails with a list of estimates whose inputs have changed, or the blind + test falling under its bar on the ends-only measure. The climate normals are + a fixed published dataset, so they are not read again. - **Every audit.** `docs/audit.md`, the written checklist for the monthly audit of everything, lists two season steps: the check above, and a fresh search for a source for every season still marked `estimate`, so estimates @@ -202,7 +204,7 @@ The plan above chose a rule over climate normals for Step 3. It was built and te - **The method is tested blind.** The same reviewers estimated the 148 trails whose season a page states, from identical packets with the season hidden, and a trail's comparable trails never came from its own part of the split. Two measures are given, always together. 114 of 148 (77 percent) had their first and last months within a month of the page's; 105 (71 percent) also had no wrong gap in the middle. The ends-only measure is the one the 75 percent bar was set on, and on it the method clears the bar (77 percent); the strict measure (every window of the season must correspond, so a wrong gap counts as a miss) is lower, and the method does not reach 75 percent on it (71 percent). The owner decided the estimates ship with both figures stated. By the reviewer's confidence, ends only and strict: high 48 and 48 of 52, medium 55 and 46 of 76, low 11 and 11 of 20. The figures are in `tools/season_blind_test.json`, written by `season_judge.py score`, and the site reads them. The six trails judged from pages that disagree are not scored against themselves. - **An estimate is stricter.** `season_basis = "estimate"` means no page states a season. `season` is built from `months`; `season_method` is one or two plain sentences saying how it was set and what sets the season there, ending "Confidence: high.", "medium." or "low."; and its one `[[hike.source]]` names `season` and `months` and cites the climate data. The validator refuses an estimate with any ordinary page naming the season, or with no method, and requires a season on every trail. - **Pages that disagree.** Three trails (the Sierra High Route, the Cohos Trail and the Ouachita Trail) have pages from at least two different publishers that disagree, where none is the managing body, association or route author. Their season is set by judgement from all the pages and the estimate: basis `sources`, the pages cited as sources naming the season, and a `season_method` saying the pages differ and how it was settled, ending with a confidence; the validator requires two publishers and the confidence. Three more (the Finger Lakes Trail, whose one page contradicts itself, and the Ice Age Trail and the Ozark Trail, each with two pages from one publisher that differ) have no two publishers, so they are estimates: the pages are not cited as stating the season, and the method says a page was found but differs, so the season was estimated from the climate and similar trails. A season with a method is shown as an estimate (it reads "About" with a note), left out of structured data, and not counted among the seasons a page states. -- **The monthly check** (`estimate_season.py check`) reruns the machine estimate for every estimate and flags any whose inputs have changed since `tools/season_inputs.json` recorded them. It does not rewrite anything. The audit (`docs/audit.md`) also searches afresh for a page for every estimate. +- **The monthly check** (`estimate_season.py check`) runs offline: it compares the digest of each estimate's current track and location with the one `tools/season_inputs.json` recorded when the season was set, and flags any that differ. The climate normals are a fixed published dataset and are not read again. It does not rewrite anything. The audit (`docs/audit.md`) also searches afresh for a page for every estimate. - **On the site**, a trail's page reads "About April to October" with a note (no page states a season; estimated from the climate at the trail's elevation and from similar trails; what sets it there; the confidence; that these are the usual months, not a closure). Rows, tables and month lists mark estimates, the month filter can leave them out, and the reference page and glossary give the counts and the blind-test result. ## Open risks diff --git a/tools/estimate_season.py b/tools/estimate_season.py index a6323f3..1064107 100644 --- a/tools/estimate_season.py +++ b/tools/estimate_season.py @@ -711,64 +711,52 @@ def estimates(root): if (rec.get("hike") or {}).get("season_basis") == "estimate"] -def check(root, fetch): - """Rerun the machine estimate for every estimated season and the - leave-one-out fit. Returns (ok, lines): not ok when an estimate's - inputs have changed since they were recorded in - tools/season_inputs.json (the machine estimate, the climate at the - trail, or the sourced trails it is compared with), when the - leave-one-out match share has fallen by more than 0.02 from - tools/season_fit.json, or when the blind test of the judged method - (tools/season_blind_test.json) is missing, or is below the bar on its - ends-only measure (the strict measure is recorded beside it). A changed +def points_signature(root, rec): + """A short digest of where a trail's season was estimated: the kind of sample points and their + coordinates and elevations, from the trail's current track (or its ends, or its place). It reads + only files in the repository, so the monthly check can compare it with no network.""" + points, kind = sample_points(root, rec) + material = json.dumps( + {"kind": kind, + "points": [[round(p.lat, 4), round(p.lon, 4), + None if p.elev_m is None else round(p.elev_m)] for p in points]}, + sort_keys=True) + return hashlib.sha256(material.encode()).hexdigest()[:16] + + +def check(root, fetch=None): + """The monthly check, offline. For every estimated season, compares the digest of the trail's + current track and location (points_signature) with the one recorded in + tools/season_inputs.json when the season was set, and returns (ok, lines): not ok when an + estimate has no recorded inputs, when its track or location has changed, when inputs are + recorded for a trail that is no longer an estimate, or when the blind test of the judged method + (tools/season_blind_test.json) is missing, or is below the bar on its ends-only measure (the + strict measure is recorded beside it). The climate normals are a fixed published dataset + (CHELSA, 1981 to 2010), so they are not read again; `fetch` is accepted and unused. A changed estimate is a flag for a person to look at, not a rewrite.""" import season_judge - try: - fit = load_fit(root) - except OSError: - return False, ["tools/season_fit.json is missing: run " - "python3 tools/estimate_season.py fit"] - params = load_params(root) ok, lines, checked = True, [], 0 - refs = references(root, fetch) recorded = load_inputs(root) for tid, rec in _records(root): hike = rec.get("hike") or {} if hike.get("season_basis") != "estimate": continue checked += 1 - sig = inputs_signature(estimate(root, dict(rec, id=tid), params, fetch, refs)) - then = recorded.get(tid) - if then is None: + now = points_signature(root, dict(rec, id=tid)) + then = (recorded.get(tid) or {}).get("points") + if tid not in recorded or then is None: ok = False lines.append(f"{tid}: no inputs are recorded for this estimate: run " - "python3 tools/season_judge.py inputs") - elif sig["machine"] != then["machine"]: + "python3 tools/season_judge.py inputs --points " + tid) + elif now != then: ok = False - lines.append(f"{tid}: inputs changed: the machine estimate was {then['machine']}, " - f"now {sig['machine']}; the season is {sorted(hike.get('months') or [])}") - elif sig["digest"] != then["digest"]: - ok = False - lines.append(f"{tid}: inputs changed: the climate or the similar sourced trails differ " - f"(machine estimate still {sig['machine']}); the season is " + lines.append(f"{tid}: inputs changed: the trail's track or location is no longer the one the " + f"season was estimated for ({then}, now {now}); the season is " f"{sorted(hike.get('months') or [])}") for tid in sorted(set(recorded) - set(estimates(root))): ok = False lines.append(f"{tid}: has recorded inputs but is no longer an estimate: remove it " "from tools/season_inputs.json") - sourced = sourced_trails(root, fetch) - if any(s[1] is not None for s in sourced): - _p, now, _loo = fit_sourced(sourced) - stored = fit.get("loo") or {} - if stored.get("n"): - was_share = stored["within1"] / stored["n"] - now_share = now["within1"] / now["n"] if now["n"] else 0.0 - if was_share - now_share > 0.02: - ok = False - lines.append( - f"fit got worse: leave-one-out matches " - f"{now['within1']}/{now['n']} ({now_share:.2f}), " - f"was {stored['within1']}/{stored['n']} ({was_share:.2f})") try: blind = season_judge.load_blind_test(os.path.join(root, "tools", "season_blind_test.json")) problems = season_judge.check_blind_test(blind) @@ -784,7 +772,8 @@ def check(root, fetch): ok = False lines.append("tools/season_blind_test.json is missing or unreadable") if ok: - lines.append(f"check passed: {checked} estimated seasons rest on the same inputs") + lines.append(f"check passed: {checked} estimated seasons are still on the track or location " + "they were estimated for") return ok, lines @@ -870,8 +859,7 @@ def cmd_estimates(args): def cmd_check(args): - fetch = _fetch_with_cache(args.cache) - ok, lines = check(ROOT, fetch) + ok, lines = check(ROOT) for line in lines: print(line) return 0 if ok else 1 @@ -907,9 +895,8 @@ def main(argv=None): "estimates", help="list the trails whose season is an estimate") estimates_parser.set_defaults(func=cmd_estimates) check_parser = sub.add_parser( - "check", help="rerun every estimate and the fit") - check_parser.add_argument("--cache", default=None, - help="climate cache directory") + "check", help="offline: compare each estimate's recorded inputs with the trail's " + "current track and location, and check the blind test") check_parser.set_defaults(func=cmd_check) argv = ["check" if a == "--check" else a for a in (sys.argv[1:] if argv is None else argv)] diff --git a/tools/season_inputs.json b/tools/season_inputs.json index 82877e8..fcd10e8 100644 --- a/tools/season_inputs.json +++ b/tools/season_inputs.json @@ -6,7 +6,8 @@ 6, 9, 10 - ] + ], + "points": "5b3280ac815e9040" }, "alpine-trail-7": { "digest": "efd5e277fbf3b6c1", @@ -14,7 +15,8 @@ 7, 8, 9 - ] + ], + "points": "66d1a158cf32328a" }, "avon": { "digest": "a9120a59a9a1907d", @@ -25,7 +27,8 @@ 8, 9, 10 - ] + ], + "points": "a133f33fe3b019f9" }, "batona": { "digest": "3dbdb3e8b17d2b98", @@ -35,7 +38,8 @@ 9, 10, 11 - ] + ], + "points": "560955c481df42f5" }, "bay-circuit": { "digest": "bdb128943b1900ae", @@ -46,7 +50,8 @@ 8, 9, 10 - ] + ], + "points": "90eafebf6ec4f76a" }, "bayou-state-trail": { "digest": "c7c4147060628fa7", @@ -57,7 +62,8 @@ 4, 11, 12 - ] + ], + "points": "a8467e9a59501dd8" }, "boundary-trail-mount-st-helens": { "digest": "01312d045fd17c20", @@ -65,7 +71,8 @@ 7, 8, 9 - ] + ], + "points": "f54416dc9b67f3a3" }, "boundary-trail-pasayten": { "digest": "e97c07b0f68a15a9", @@ -73,7 +80,8 @@ 7, 8, 9 - ] + ], + "points": "d95317240cb4b500" }, "bristol-hills-trail": { "digest": "a5fa7af7ebab8d67", @@ -84,13 +92,15 @@ 8, 9, 10 - ] + ], + "points": "7a56b636555fa553" }, "brooks-range-traverse": { "digest": "8a3c5ef0f30bc7f8", "machine": [ 8 - ] + ], + "points": "3e4bc0ab7ded98aa" }, "bruce-trail": { "digest": "ed62c99709c54267", @@ -99,7 +109,8 @@ 8, 9, 10 - ] + ], + "points": "e6e985acbfb0c18a" }, "california-coastal": { "digest": "5c7fa4913f78b36c", @@ -109,7 +120,8 @@ 8, 9, 10 - ] + ], + "points": "46d88fdd32b7c0c8" }, "conestoga-trail": { "digest": "31f1d48bf322e3a7", @@ -118,7 +130,8 @@ 5, 9, 10 - ] + ], + "points": "8b710f69e6901943" }, "conservation-trail": { "digest": "21bfcf5403bcbfdf", @@ -128,7 +141,8 @@ 8, 9, 10 - ] + ], + "points": "2ef8a2830d82f390" }, "cranberry-lake-50": { "digest": "87772fc46ebb73ca", @@ -136,7 +150,8 @@ 7, 8, 9 - ] + ], + "points": "61231407b018812f" }, "cross-vermont": { "digest": "de8f9f0acea8bd21", @@ -145,7 +160,8 @@ 6, 9, 10 - ] + ], + "points": "0cad6fec0d9afc44" }, "deseret-hiking-route": { "digest": "191f5e4f5cc698cb", @@ -155,7 +171,8 @@ 5, 10, 11 - ] + ], + "points": "6079d15e9d183d7f" }, "desert-trail": { "digest": "132108d83a002b0d", @@ -164,7 +181,8 @@ 8, 9, 10 - ] + ], + "points": "aa33dec22b7500b8" }, "donut-hole": { "digest": "dcc41463939e95a7", @@ -174,7 +192,8 @@ 6, 9, 10 - ] + ], + "points": "284c0ef8512572a6" }, "eastern-continental-trail": { "digest": "d40390952a719154", @@ -184,7 +203,8 @@ 8, 9, 10 - ] + ], + "points": "a6e0ee1c73858dcb" }, "eastern-sierra-high-route": { "digest": "34c0558ddeedd3f2", @@ -192,7 +212,11 @@ 7, 8, 9 - ] + ], + "points": "55b8981509ad0893" + }, + "finger-lakes": { + "points": "338c0f525d32224b" }, "ganaraska": { "digest": "b414a50c65a31b82", @@ -203,7 +227,8 @@ 8, 9, 10 - ] + ], + "points": "2bdcc55e79a5f683" }, "general-george-crook": { "digest": "f2896d5fe13e417f", @@ -212,7 +237,8 @@ 5, 9, 10 - ] + ], + "points": "64014e2e7644af9c" }, "georgia-loop": { "digest": "35f1d5133569d0c0", @@ -224,7 +250,8 @@ 10, 11, 12 - ] + ], + "points": "441770b746069082" }, "gila-centennial-loop": { "digest": "08f4ed745b5d2560", @@ -235,7 +262,8 @@ 9, 10, 11 - ] + ], + "points": "1bde178eb296427c" }, "grand-valley-trail": { "digest": "5f4505a160f8f245", @@ -244,7 +272,8 @@ 6, 9, 10 - ] + ], + "points": "8d3f4d42f8553ba0" }, "great-eastern": { "digest": "b77ec5d870bbcc88", @@ -252,7 +281,8 @@ 4, 5, 10 - ] + ], + "points": "f75851e040957980" }, "great-western-divide-loop": { "digest": "dd7b6f503f72081b", @@ -261,7 +291,8 @@ 8, 9, 10 - ] + ], + "points": "64bab16e50d60757" }, "high-country-pathway": { "digest": "b59fdbbf3b1ac6f8", @@ -271,7 +302,8 @@ 8, 9, 10 - ] + ], + "points": "0ea28ef5b9723b8d" }, "highlands": { "digest": "8212eeadd24218c3", @@ -280,7 +312,8 @@ 5, 9, 10 - ] + ], + "points": "28d7e27072f8cc8b" }, "hoosier-heritage-trail": { "digest": "f550667eab910362", @@ -290,7 +323,8 @@ 5, 10, 11 - ] + ], + "points": "27fe12298613e61c" }, "horse-shoe": { "digest": "aeff26cf6c7e0143", @@ -299,7 +333,8 @@ 5, 9, 10 - ] + ], + "points": "ffe09d582ca7a623" }, "hot-springs-trail": { "digest": "fc73ad4cf711d615", @@ -310,7 +345,8 @@ 5, 10, 11 - ] + ], + "points": "f64b708fe0a66d2a" }, "iat-newfoundland-labrador": { "digest": "91eadce2b4ef4c7f", @@ -318,7 +354,11 @@ 7, 8, 9 - ] + ], + "points": "658a452a468fffd1" + }, + "ice-age": { + "points": "6123e99c6a3082fe" }, "international-appalachian-trail-maine": { "digest": "8f488d4dc2b03636", @@ -326,13 +366,15 @@ 7, 8, 9 - ] + ], + "points": "4cac64a291020a9a" }, "koroc-palmer-loop": { "digest": "e18e82c08b6dfd5d", "machine": [ 8 - ] + ], + "points": "84ce0d6f0fd7b454" }, "la-cloche": { "digest": "61ce29ac5892d1b8", @@ -340,7 +382,8 @@ 7, 8, 9 - ] + ], + "points": "32195bb88992a86c" }, "lost-coast": { "digest": "971c47b8714b706f", @@ -350,7 +393,8 @@ 8, 9, 10 - ] + ], + "points": "46726fb00eebd4cf" }, "loyalsock": { "digest": "7e8067a31ec5da6c", @@ -360,7 +404,8 @@ 6, 9, 10 - ] + ], + "points": "589a23f3e8bf86e0" }, "mason-dixon": { "digest": "54cad0c500a1e861", @@ -369,7 +414,8 @@ 5, 9, 10 - ] + ], + "points": "b67b7d3e33ed925f" }, "midland-to-mackinac-trail": { "digest": "c5ed1765cac4534f", @@ -377,7 +423,8 @@ 7, 8, 9 - ] + ], + "points": "3df8a157582012ce" }, "midstate-ma": { "digest": "edc133c6ae5007c7", @@ -386,7 +433,8 @@ 6, 9, 10 - ] + ], + "points": "99a2fcf36b45e796" }, "north-south": { "digest": "86641545fa67fd0c", @@ -396,7 +444,8 @@ 6, 9, 10 - ] + ], + "points": "b0c1b0a0708e708e" }, "north-south-lbl": { "digest": "25b3d5d788753ae6", @@ -406,14 +455,16 @@ 5, 10, 11 - ] + ], + "points": "3d0f9ffedba5dd16" }, "north-umpqua": { "digest": "14231792880f7042", "machine": [ 5, 10 - ] + ], + "points": "81a26b35ce4a2b65" }, "oak-ridges": { "digest": "0646d355131c000c", @@ -423,7 +474,8 @@ 8, 9, 10 - ] + ], + "points": "ed723136e55593f2" }, "ottawa-temiskaming-highland-trail": { "digest": "77fbbe8137415f41", @@ -431,7 +483,11 @@ 7, 8, 9 - ] + ], + "points": "89d2a7d8f17525e7" + }, + "ozark-trail": { + "points": "48f5b65c51e0a605" }, "paumanok-path": { "digest": "588eea3017f04c4c", @@ -440,7 +496,8 @@ 8, 9, 10 - ] + ], + "points": "803699c022c3c997" }, "pfiffner-traverse": { "digest": "61965112f0b75445", @@ -448,7 +505,8 @@ 7, 8, 9 - ] + ], + "points": "d3eecf6f0442939d" }, "rideau-trail": { "digest": "55d2219b607959d1", @@ -458,7 +516,8 @@ 8, 9, 10 - ] + ], + "points": "7a16758637f5c4fc" }, "ring-the-peak": { "digest": "858d219cc4ecd8f6", @@ -466,7 +525,8 @@ 7, 8, 9 - ] + ], + "points": "f13e0b5aeec19a5c" }, "sawtooth-wilderness-high-route": { "digest": "0f4f2e2bf5e9bc6e", @@ -474,7 +534,8 @@ 7, 8, 9 - ] + ], + "points": "986a243b2dec421d" }, "sea-to-sea-route": { "digest": "eb6dbcb347f7a83d", @@ -482,7 +543,8 @@ 6, 9, 10 - ] + ], + "points": "18927e8fccda17e4" }, "shawangunk-ridge-trail": { "digest": "d3b38e00538fd900", @@ -492,7 +554,8 @@ 6, 9, 10 - ] + ], + "points": "6fe7bf6b493b24a4" }, "shenipsit-trail": { "digest": "a713c4e4a679b6fa", @@ -501,7 +564,8 @@ 5, 9, 10 - ] + ], + "points": "a4533e0f9dfca3b2" }, "siskiyou-peaks-trail": { "digest": "2b4dff26c8e71b80", @@ -509,7 +573,8 @@ 7, 8, 9 - ] + ], + "points": "6ff6148206cdf66b" }, "sky-islands-traverse": { "digest": "eed4f15ecdf6114d", @@ -520,7 +585,8 @@ 9, 10, 11 - ] + ], + "points": "840db2e4fcb1de1c" }, "solitude-loop": { "digest": "c091a7bb7336deb5", @@ -528,7 +594,8 @@ 7, 8, 9 - ] + ], + "points": "3f2a5bcfbaf1ebe2" }, "standing-stone": { "digest": "cdc4f7ed39a2c205", @@ -537,28 +604,32 @@ 5, 9, 10 - ] + ], + "points": "30d3a7085e711b49" }, "stein-valley-traverse": { "digest": "59cd7e9a35c5c732", "machine": [ 6, 9 - ] + ], + "points": "4bf13dd8bff38e69" }, "sunapee-ragged-kearsarge": { "digest": "f5d7131d547be861", "machine": [ 8, 9 - ] + ], + "points": "401dd7ea1ce18086" }, "tahoe-yosemite-trail": { "digest": "23aa94cfbefd3f86", "machine": [ 8, 9 - ] + ], + "points": "e77f9a0b7900a3d1" }, "tuscarora": { "digest": "606d9fe137a8347d", @@ -567,14 +638,16 @@ 5, 9, 10 - ] + ], + "points": "9e75f481d596079f" }, "vagabond-loop": { "digest": "33378ec42f73f8d5", "machine": [ 4, 10 - ] + ], + "points": "b56fa26d9315370d" }, "warrior-trail": { "digest": "cecd19f5c7ba6ae4", @@ -583,7 +656,8 @@ 5, 9, 10 - ] + ], + "points": "a1fa2f53436ddcbd" }, "wasatch-traverse": { "digest": "1582bd31f8f00ced", @@ -592,7 +666,8 @@ 6, 9, 10 - ] + ], + "points": "5b3280ac815e9040" }, "waskahegan": { "digest": "d7993fbe810051fd", @@ -600,7 +675,8 @@ 7, 8, 9 - ] + ], + "points": "3d85be5f038811c6" }, "western-uplands": { "digest": "464d6cd6bfe3257c", @@ -608,7 +684,8 @@ 7, 8, 9 - ] + ], + "points": "57288e3504dc6d55" }, "yosemite-high-route": { "digest": "eee24b0c39473ab0", @@ -616,6 +693,7 @@ 7, 8, 9 - ] + ], + "points": "10d56319fea3c478" } } diff --git a/tools/season_judge.py b/tools/season_judge.py index 438bbd4..df3284b 100644 --- a/tools/season_judge.py +++ b/tools/season_judge.py @@ -20,8 +20,9 @@ Commands: tools/season_blind_test.json) proposals stage the judged seasons for the trails with no season, for python3 tools/refresh.py collect and apply - inputs record the machine estimate and the inputs of every estimate, - so the monthly check can see when they change + inputs record what every estimate rests on (the digest of its track + and location, and the machine estimate), so the monthly check, + which runs offline, can see when a track or location changes An answer file is tab separated, one trail a line, no header: id, months (comma separated, 1 to 12), season phrase, confidence (high, medium or @@ -608,13 +609,37 @@ def cmd_proposals(args): def cmd_inputs(args): - fetch = E._fetch_with_cache(args.cache) - params = E.load_params(ROOT) - refs = E.references(ROOT, fetch) - doc = {} - for tid, rec in E._records(ROOT): - if (rec.get("hike") or {}).get("season_basis") == "estimate": - doc[tid] = E.inputs_signature(E.estimate(ROOT, dict(rec, id=tid), params, fetch, refs)) + """Record what each estimate rests on: the digest of the trail's track and location (offline, + all the monthly check compares) and, unless --points, the machine estimate and the digest of the + climate and similar trails at the time (which reads the climate, so it needs the network).""" + try: + with open(args.write, encoding="utf-8") as f: + doc = json.load(f) + except OSError: + doc = {} + params = refs = fetch = None + if not args.points: + fetch = E._fetch_with_cache(args.cache) + params = E.load_params(ROOT) + refs = E.references(ROOT, fetch) + estimates = {tid: rec for tid, rec in E._records(ROOT) + if (rec.get("hike") or {}).get("season_basis") == "estimate"} + unknown = [t for t in args.ids if t not in estimates] + if unknown: + print("not an estimate: " + ", ".join(unknown)) + return 1 + for tid in sorted(set(doc) - set(estimates)): + del doc[tid] + for tid, rec in estimates.items(): + if args.ids and tid not in args.ids: + continue + entry = dict(doc.get(tid, {})) + if not args.points: + entry.update(E.inputs_signature(E.estimate(ROOT, dict(rec, id=tid), params, fetch, refs))) + entry["points"] = E.points_signature(ROOT, dict(rec, id=tid)) + doc[tid] = entry + for tid, rec in estimates.items(): # every estimate has its digest, even when only some were asked for + doc.setdefault(tid, {"points": E.points_signature(ROOT, dict(rec, id=tid))}) with open(args.write, "w", encoding="utf-8") as f: json.dump(doc, f, indent=1, sort_keys=True) f.write("\n") @@ -642,7 +667,10 @@ def main(argv=None): p.add_argument("--pages", default=PAGES) p.add_argument("--dir", default=None) p.set_defaults(func=cmd_proposals) - p = sub.add_parser("inputs", help="record the inputs of every estimate") + p = sub.add_parser("inputs", help="record the inputs of every estimate (or of the trail ids named)") + p.add_argument("ids", nargs="*", help="only these estimates; default every estimate") + p.add_argument("--points", action="store_true", + help="record only the digest of the track and location (offline, quick)") p.add_argument("--write", default=INPUTS) p.add_argument("--cache", default=None) p.set_defaults(func=cmd_inputs) diff --git a/tools/tests/test_estimate_season.py b/tools/tests/test_estimate_season.py index 4a2a6c4..2898114 100644 --- a/tools/tests/test_estimate_season.py +++ b/tools/tests/test_estimate_season.py @@ -403,10 +403,8 @@ class ProposeCheckTest(unittest.TestCase): json.dump(doc, f) def record_inputs(self, root, tid="aaa", **change): - params = E.load_params(root) rec = E.refresh.load_toml(os.path.join(root, tid, "trail.toml")) - sig = E.inputs_signature(E.estimate(root, dict(rec, id=tid), params, mild_fetch, - E.references(root, mild_fetch))) + sig = {"points": E.points_signature(root, dict(rec, id=tid))} sig.update(change) with open(os.path.join(root, "tools", "season_inputs.json"), "w") as f: json.dump({tid: sig}, f) @@ -417,68 +415,82 @@ class ProposeCheckTest(unittest.TestCase): self.blind_doc(root, **kw) return root - def test_check_passes_when_nothing_changed(self): + @staticmethod + def no_network(lat, lon, elev): + raise AssertionError("the monthly check must not read the climate") + + def test_check_passes_when_nothing_changed_and_reads_no_climate(self): tmp = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tmp, True) root = self.checked_repo(tmp) - E._REFS.clear() self.record_inputs(root) - ok, lines = E.check(root, mild_fetch) + ok, lines = E.check(root, self.no_network) + self.assertTrue(ok, lines) + ok, lines = E.check(root) self.assertTrue(ok, lines) - def test_check_flags_an_estimate_whose_machine_estimate_changed(self): + def test_check_flags_an_estimate_whose_location_moved(self): tmp = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tmp, True) root = self.checked_repo(tmp) - E._REFS.clear() - self.record_inputs(root, machine=[6, 7]) - ok, lines = E.check(root, mild_fetch) + self.record_inputs(root) + path = os.path.join(root, "aaa", "trail.toml") + with open(path, encoding="utf-8") as f: + text = f.read() + with open(path, "w", encoding="utf-8") as f: + f.write(text.replace("end_lonlat = [-110.0, 43.2]", "end_lonlat = [-111.5, 44.2]")) + ok, lines = E.check(root, self.no_network) self.assertFalse(ok) - self.assertTrue(any("aaa" in line and "inputs changed" in line and "[6, 7]" in line + self.assertTrue(any("aaa" in line and "inputs changed" in line and "track or location" in line for line in lines), lines) - def test_check_flags_an_estimate_whose_climate_digest_changed(self): + def test_check_flags_an_estimate_whose_recorded_inputs_differ(self): tmp = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tmp, True) root = self.checked_repo(tmp) - E._REFS.clear() - self.record_inputs(root, digest="0" * 16) - ok, lines = E.check(root, mild_fetch) + self.record_inputs(root, points="0" * 16) + ok, lines = E.check(root, self.no_network) self.assertFalse(ok) self.assertTrue(any("aaa" in line and "inputs changed" in line for line in lines), lines) + def test_the_points_signature_does_not_move_for_changes_that_are_not_the_location(self): + tmp = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, tmp, True) + root = self.checked_repo(tmp) + rec = E.refresh.load_toml(os.path.join(root, "aaa", "trail.toml")) + before = E.points_signature(root, dict(rec, id="aaa")) + rec["hike"]["summary"] = "Something else." + self.assertEqual(E.points_signature(root, dict(rec, id="aaa")), before) + def test_check_flags_an_estimate_with_no_recorded_inputs(self): tmp = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tmp, True) root = self.checked_repo(tmp) - E._REFS.clear() - ok, lines = E.check(root, mild_fetch) + ok, lines = E.check(root, self.no_network) self.assertFalse(ok) self.assertTrue(any("aaa" in line and "no inputs are recorded" in line for line in lines), lines) - def test_check_fails_when_the_blind_test_is_under_the_bar(self): + def test_check_flags_inputs_recorded_for_a_trail_that_is_no_longer_an_estimate(self): + tmp = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, tmp, True) + root = self.checked_repo(tmp) + self.record_inputs(root) + with open(os.path.join(root, "tools", "season_inputs.json"), "w") as f: + json.dump({"aaa": {"points": E.points_signature( + root, dict(E.refresh.load_toml(os.path.join(root, "aaa", "trail.toml")), id="aaa"))}, + "gone": {"points": "x"}}, f) + ok, lines = E.check(root) + self.assertFalse(ok) + self.assertTrue(any("gone" in line for line in lines), lines) + + def test_check_fails_when_the_blind_test_is_under_the_bar_on_the_ends_only_measure(self): tmp = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, tmp, True) root = self.checked_repo(tmp, share=0.6) - E._REFS.clear() self.record_inputs(root) - ok, lines = E.check(root, mild_fetch) + ok, lines = E.check(root) self.assertFalse(ok) - self.assertTrue(any("blind test" in line for line in lines), lines) - - def test_check_fails_when_the_fit_got_worse(self): - tmp = tempfile.mkdtemp() - self.addCleanup(shutil.rmtree, tmp, True) - # one sourced trail that mild all-year normals cannot match - extra = ('season = "June"\nmonths = [6]\n' - 'season_basis = "source"\n' + self.ENDS) - root = self.repo_with(tmp, [("only", "Only", {"extra_hike": extra})]) - self.fit_doc(root, within1=4, n=4) - self.blind_doc(root) - E._REFS.clear() - ok, lines = E.check(root, mild_fetch) - self.assertFalse(ok) - self.assertTrue(any("fit got worse" in line for line in lines), lines) + self.assertTrue(any("blind test" in line and "ends-only" in line for line in lines), lines) def test_the_estimates_command_lists_only_estimates(self): tmp = tempfile.mkdtemp() diff --git a/tools/tests/test_season_audit.py b/tools/tests/test_season_audit.py index a9bf698..f1f22e3 100644 --- a/tools/tests/test_season_audit.py +++ b/tools/tests/test_season_audit.py @@ -35,7 +35,8 @@ class AuditChecklistTest(unittest.TestCase): self.assertIn("estimate_season.py estimates", seasons) self.assertIn("docs/season-research.md", seasons) self.assertIn("search afresh for a page that states the season", seasons.lower().replace("\n", " ")) - self.assertIn("re-run the machine estimate", seasons.lower()) + self.assertIn("downloads nothing", seasons) + self.assertIn("fixed published dataset", seasons) self.assertIn("1. ", seasons) self.assertIn("2. ", seasons) @@ -51,6 +52,27 @@ class AuditChecklistTest(unittest.TestCase): self.assertEqual(stop.exception.code, 0, sub) self.assertIn(f" {sub}", out.getvalue()) + def test_every_command_in_the_audit_runs_as_written(self): + """Each `python3 tools/