Show where a season came from; check it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 09:51:51 -07:00
1 parent fbb43d9ff0
commit 03c2611036
7 files changed
+73 -3

No files matched your search

+1
View File
@@ -42,6 +42,7 @@ jobs:
python3 tools/check_history.py --base "$base"
- run: python3 -m unittest discover tools/tests -p "test_history.py"
- run: python3 -m unittest discover tools/tests -p "test_trail_numbers.py"
- run: python3 -m unittest discover tools/tests -p "test_season*.py"
site:
runs-on: ubuntu-latest
+7
View File
@@ -1,5 +1,12 @@
# Changelog
## 2026-11-20 - Every season now says where it came from
- The 109 trails that have a season now record where it came from: 86 are from the body that manages the trail, or for a route its author, and 23 are from one page that is not the trail's own. None rests on several agreeing pages yet. A trail's "About this data" says which, in one sentence under the pages the facts were read on.
- A season from a route author's guidebook, cited through the publisher's page, counts as the author's own.
- This is the first step toward a season on every trail. The other 114 have none yet, and the "By month" lists still say so. A season that is worked out from climate rather than found on a page will be marked as an estimate wherever it appears.
- For contributors: a season now needs a basis (`hike.season_basis`) and a page that states it, and the validator checks both. A change to the basis gets a history entry like any other fact.
## 2026-11-20 - The Glacier loop is now listed as the North Circle, with a track
- The 52 mile loop from Many Glacier in Glacier National Park is now listed as the North Circle, its common name, which the Park Service's National Register record of the park's tourist trails uses. Its other names are in its summary: the Many Glacier Loop, and the Ptarmigan–Glenns Lake–Highline Loop, the title Mike White and Douglas Lorain's Best Backpacking Trips in Montana, Wyoming, and Colorado gives it. Its page address is unchanged, and the old name still finds it.
+18
View File
@@ -12,6 +12,8 @@ sys.dont_write_bytecode = True
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import season # noqa: E402
import validate as V # noqa: E402
import refresh # noqa: E402
def src(publisher, facts=("season", "months"), url="https://example.org/trail"):
@@ -105,6 +107,22 @@ class SeasonBasisTest(unittest.TestCase):
errors = check(season=None, months=None, season_basis=None, season_method="Some method.")
self.assertTrue(errors)
def test_every_record_with_a_season_passes_the_validator(self):
errors = []
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"):
V.check_hike(tid, rec, errors)
self.assertEqual(errors, [])
def test_provenance_keys_need_no_source_fact(self):
hike = {"season": "June to September", "months": [6, 7, 8, 9], "season_basis": "primary",
"source": [src("Park Service", facts=("season", "months"))]}
errors = []
V.check_hike("t", {"hike": hike}, errors)
self.assertFalse([e for e in errors if "not named in the facts" in e], errors)
self.assertFalse([e for e in errors if "not a known field" in e], errors)
if __name__ == "__main__":
unittest.main()
+8 -2
View File
@@ -17,6 +17,11 @@ import os
import re
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
spec = importlib.util.spec_from_file_location(
"season", os.path.join(ROOT, "tools", "season.py"))
season = importlib.util.module_from_spec(spec)
spec.loader.exec_module(season)
MAX_BYTES = 50 * 1024 * 1024
ALLOWED_LICENCES = {
"us-gov-public-domain", "CC-BY-4.0", "CC-BY", "ODbL-1.0", "stated-permission",
@@ -34,7 +39,7 @@ HIKE_FACTS = {"summary", "official_url", "start", "end", "shape", "days", "seaso
"months", "travel", "start_lonlat", "end_lonlat"}
LONLAT_BOUNDS = (-180.0, -50.0, 24.0, 75.0) # lon min, lon max, lat min, lat max
HIKE_TRAVEL = {"trail", "trail-and-road", "some-cross-country", "mostly-cross-country"}
HIKE_KEYS = HIKE_FACTS | {"checked"}
HIKE_KEYS = HIKE_FACTS | {"checked"} | season.PROVENANCE_KEYS
ELEVATION_KEYS = {"highest", "lowest", "ascent_m", "descent_m", "track_km", "published_km",
"coverage", "parts", "orientation", "profile", "part_starts_km", "source"}
ELEVATION_REQUIRED = ELEVATION_KEYS - {"part_starts_km"}
@@ -366,9 +371,10 @@ def check_hike(tid, rec, errors):
covered.update(("high_point", "high_point_m"))
else:
covered.add(fact)
for name in sorted(set(hike) & HIKE_KEYS - {"checked"}) if sources else []:
for name in sorted(set(hike) & HIKE_KEYS - {"checked"} - season.PROVENANCE_KEYS) if sources else []:
if name not in covered:
errors.append(f"{tid}: hike.{name} is not named in the facts of any hike source")
season.check_season(tid, hike, errors)
def check_elevation(tid, tdir, rec, errors):
+24
View File
@@ -185,6 +185,30 @@ def season_text(rec):
return words.join_names(MONTHS[m - 1] for m in ms)
SEASON_BASIS_TEXT = {
"primary": "The season comes from the page of the body that manages the trail or, for a route, its author.",
"sources": "Two or more pages from different publishers agree on the season.",
"source": "One page states the season. It is not the trail's own page.",
}
def season_basis(rec):
"""Where the season came from: primary, sources, source or estimate; "" when it has none."""
h = hike.table(rec)
if not h.get("season") and not h.get("months"):
return ""
return h.get("season_basis") or ""
def season_basis_line(rec):
"""One sentence for "About this data"; "" when the season has no recorded basis."""
basis = season_basis(rec)
if basis == "estimate":
method = (hike.table(rec).get("season_method") or "").strip()
return (method + " No page states a season.").strip()
return SEASON_BASIS_TEXT.get(basis, "")
# Terrain, Walking, Shape ----------------------------------------------------
TERRAIN_VALUES = words.TERRAIN
+3 -1
View File
@@ -1563,7 +1563,9 @@ def hike_sources_block(rec):
body = f'<ul class="linklist">{items}</ul>' if items else \
'<p class="record-text">The record names no page for these facts.</p>'
checked = f'<p class="note">Checked {esc(h["checked"])}.</p>' if h.get("checked") else ""
return block("hike-title", "Where the hiking facts come from", Markup(body + checked))
basis = facets.season_basis_line(rec)
basis = f'<p class="note">{esc(basis)}</p>' if basis else ""
return block("hike-title", "Where the hiking facts come from", Markup(body + checked + basis))
def about_data(rec, site, author_links=None):
+12
View File
@@ -125,6 +125,18 @@ class TrailPageTest(unittest.TestCase):
self.assertTrue(trail.description(rec).startswith(
"A trail of 62 miles (100 km) in Arizona, usually 5 to 7 months. A long walk along the crest"))
def test_about_this_data_says_where_the_season_came_from(self):
from olt import facets
rec = sample_record("X Trail")
rec["hike"] = dict(FULL_HIKE, season_basis="primary")
block = trail.hike_sources_block(rec)
self.assertIn("The season comes from the page of the body that manages the trail or, for a route, its author.",
html.unescape(block))
self.assertEqual(facets.season_basis(rec), "primary")
rec["hike"] = {k: v for k, v in FULL_HIKE.items() if k not in ("season", "months")}
self.assertNotIn("The season comes from", trail.hike_sources_block(rec))
self.assertEqual(facets.season_basis(rec), "")
def test_partial_hike_table(self):
rec = sample_record("X Trail")
rec["hike"] = {"shape": "loop", "start": "Lake Camp", "days": [4, 6], "checked": "2026-11-13"}