From 9528c717f7a882ab09543cc72d429e6899444878 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Fri, 20 Nov 2026 09:18:33 -0700 Subject: [PATCH] Register season_basis and season_method; schema allows estimated seasons --- docs/schema.md | 10 ++++++---- tools/tests/test_season_fields.py | 33 +++++++++++++++++++++++++++++++ tools/trail_history.py | 4 ++-- 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 tools/tests/test_season_fields.py diff --git a/docs/schema.md b/docs/schema.md index 39f13aa..9771347 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -126,7 +126,7 @@ The field and file names keep the word "line" (`line.geojson`, `line_file`, `lin ## `[hike]`: what a hiker asks first -Optional: a record without `[hike]` is valid. The table holds the facts a hiker wants before anything else: where the trail goes, what the country is like, how long it takes, when to go, where its own site is. Every fact is read on a page, and that page is named in `[[hike.source]]`. The first choice is a page of the trail's holder (the agency, the association, or for a route its author) or a government page. Where those say nothing, a fact may be read on an established hiking reference that covers the trail, such as a guide site, a hiking association's list of trails or a guidebook publisher's page; the source entry names that site as the publisher, so a reader can see where the fact came from and weigh it. Apps and pages that anyone can edit (AllTrails, forums, social media, wikis) are not sources. A fact found on no acceptable page is left out, never guessed. Where sources disagree, the managing body's figure is used. Wording is ours: nothing is copied from a source. +Optional: a record without `[hike]` is valid. The table holds the facts a hiker wants before anything else: where the trail goes, what the country is like, how long it takes, when to go, where its own site is. Every fact is read on a page, and that page is named in `[[hike.source]]`. The first choice is a page of the trail's holder (the agency, the association, or for a route its author) or a government page. Where those say nothing, a fact may be read on an established hiking reference that covers the trail, such as a guide site, a hiking association's list of trails or a guidebook publisher's page; the source entry names that site as the publisher, so a reader can see where the fact came from and weigh it. Apps and pages that anyone can edit (AllTrails, forums, social media, wikis) are not sources. A fact found on no acceptable page is left out, never guessed, except season, which may be estimated and must then say so. Typical time is estimated at page-build time and never stored, while an estimated season is stored on the record. Where sources disagree, the managing body's figure is used. Wording is ours: nothing is copied from a source. | Field | Type | Meaning | Example | | --- | --- | --- | --- | @@ -136,8 +136,10 @@ Optional: a record without `[hike]` is valid. The table holds the facts a hiker | `start_lonlat`, `end_lonlat` | array of two numbers, where present | The position of the place named in `start` (or `end`), as a gazetteer or the trail's holder gives it: longitude and latitude in decimal degrees, WGS84, longitude first, rounded to three decimals (about 100 m). It is the place, not a surveyed trailhead, and it is there so that a trail with no track can still be put on a map. A loop has `start_lonlat` only. The place name in `start` (or `end`) may be left out when the record has a track and the numbers are the ends of that track, with the track named as the source. The source of the numbers must allow republication and is named in `[[hike.source]]`, like every other fact. Where both are given, the straight distance between the two points cannot be longer than `length_km`, because a trail cannot be shorter than the distance between its ends; the validator checks this with a 2 per cent tolerance. | `[-83.927, 34.627]` | | `shape` | string | `"point-to-point"`, `"loop"` or `"network"`. | `"point-to-point"` | | `days` | array of two integers | The usual time to walk the whole trail in one go, `[fewest, most]`, in days, as a source states it. Weeks count 7 days, months 30. | `[150, 210]` | -| `season` | string | The months in which the whole trail is usually walked, as a short phrase. Not the dates a park or hut is open, unless those set the walking season. | `"July to September"` | -| `months` | array of integers | The same season as month numbers, 1 to 12, for filtering: every month in which the whole trail, or a usual start, is normally walked. A month counts when about half of it or more is in season. Given whenever `season` is. | `[7, 8, 9]` | +| `season` | string | The months in which the whole trail is usually walked, as a short phrase. Not the dates a park or hut is open, unless those set the walking season. `season` and `months` come together: one is never given without the other. For an estimated season (`season_basis = "estimate"`) the phrase is built from the months. | `"July to September"` | +| `months` | array of integers | The same season as month numbers, 1 to 12, for filtering: every month in which the whole trail, or a usual start, is normally walked. A month counts when about half of it or more is in season. Given whenever `season` is, and never without it. | `[7, 8, 9]` | +| `season_basis` | string | Required whenever `season` is present, and refused without it. Where the season came from, one of: `primary` (the page is published by the body that manages the trail, the trail's own association, or, for a route worked out by a hiker, that route's author); `sources` (no primary page, but two or more pages from different publishers agree on the season); `source` (one page that is not a primary one); `estimate` (no page states a season, so it is worked out from climate). A route author's stated season counts as `primary`. | `"primary"` | +| `season_method` | string | Required with `season_basis = "estimate"`, and refused otherwise. One sentence naming the method and its inputs: the dataset, the period, the points used and the rule version. | `"Estimated from 1991-2020 climate normals at 5 track points (rule version 1)."` | | `high_point` | string | Name of the highest point on the trail. | `"Mount Mansfield"` | | `high_point_m` | integer | The elevation of the highest point in metres, rounded to the nearest metre (converted from feet where the source gives feet). May be given without `high_point` where a source states the elevation but not a name. | `1340` | | `terrain` | array of strings | One to three of `alpine`, `forest`, `desert`, `coast`, `prairie`, `canyon`, `tundra`, `lakes`, `farmland`: the main kinds of country only. | `["forest"]` | @@ -233,7 +235,7 @@ Settling a conflict: - fails when an entry that was already there was changed or removed; - prints, for each changed fact, the earlier entries about the same field, and prints `!!` lines where an earlier entry was `declined`, or was asked for by someone other than the dataset's own check. That is where two requests may conflict: read the entry before you change the field again. -**Facts**, which need an entry when they change: `name`, `common_name`, `short_name`, `short_name_url`, `country`, `regions`, `length_km`, `length_note`, `system_km`, `system_note`, `built_km`, `kind`, `tier`, `designation`, `inclusion`; everything in `[source]` except the fields below, which includes the track's source, licence and permission; `osm.relation`; everything in `[shield]` except `note` (the logo); everything in `[hike]` except `summary`, `checked` and the sources (the ends, official page, days, season, terrain, travel, high point, permit, unfinished and caution); `[route]` except `note` (the author and the track policy); `[[guide]]` except the price. A replaced track file counts as a change to `source.line_file`. +**Facts**, which need an entry when they change: `name`, `common_name`, `short_name`, `short_name_url`, `country`, `regions`, `length_km`, `length_note`, `system_km`, `system_note`, `built_km`, `kind`, `tier`, `designation`, `inclusion`; everything in `[source]` except the fields below, which includes the track's source, licence and permission; `osm.relation`; everything in `[shield]` except `note` (the logo); everything in `[hike]` except `summary`, `checked` and the sources (the ends, official page, days, season, months, season_basis, season_method, terrain, travel, high point, permit, unfinished and caution); `[route]` except `note` (the author and the track policy); `[[guide]]` except the price. A replaced track file counts as a change to `source.line_file`. **Not facts**, which need none: `[[history]]` itself; all of `[verification]`, which the tools refresh; `source.source_checked`, `source.discovery`, `source.format`, `source.crs`, `source.mainline` and `source.length_gap_note`; `hike.summary` (our wording), `hike.checked` and `[[hike.source]]`; `guide.price` and `guide.price_checked`; the notes `osm.note`, `shield.note` and `route.note`; `[[link]]`; `wave` and `wave_note`. A field that is in neither list is a fact. The lists are `FACTS_TEXT` and `NOT_FACTS` in `tools/trail_history.py`, and `python3 tools/check_history.py --facts` prints them. diff --git a/tools/tests/test_season_fields.py b/tools/tests/test_season_fields.py new file mode 100644 index 0000000..e49b12f --- /dev/null +++ b/tools/tests/test_season_fields.py @@ -0,0 +1,33 @@ +"""Tests that season_basis and season_method are known fields and documented. + +Run from the repository root: + python3 -m unittest discover tools/tests +""" +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 trail_history as H # noqa: E402 +import validate as V # noqa: E402 + + +class SeasonFieldsTest(unittest.TestCase): + def test_the_new_fields_are_known_to_the_history_tool(self): + for f in ("hike.season_basis", "hike.season_method"): + self.assertIn(f, H.SCHEMA_FIELDS) + self.assertTrue(H.is_fact(f)) + + def test_the_facts_text_names_them(self): + self.assertIn("season_basis", H.FACTS_TEXT) + + def test_the_schema_documents_them_and_the_estimate_exception(self): + text = open(os.path.join(V.ROOT, "docs", "schema.md"), encoding="utf-8").read() + for needle in ("`season_basis`", "`season_method`", "except season, which may be estimated"): + self.assertIn(needle, text) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/trail_history.py b/tools/trail_history.py index 594d055..2cd9b14 100644 --- a/tools/trail_history.py +++ b/tools/trail_history.py @@ -29,7 +29,7 @@ _TABLES = { "shield": ("status", "logo_source", "contact", "note", "logo_file", "logo_owner"), "verification": ("verified", "date", "measured_km", "difference_percent", "parts", "note"), "hike": ("summary", "official_url", "start", "end", "start_lonlat", "end_lonlat", "shape", - "days", "season", "months", "high_point", "high_point_m", "terrain", "travel", + "days", "season", "months", "season_basis", "season_method", "high_point", "high_point_m", "terrain", "travel", "permit", "unfinished", "caution", "checked"), "hike.source": ("url", "publisher", "facts"), "route": ("creator", "year", "line_policy", "creator_words", "creator_words_url", @@ -66,7 +66,7 @@ FACTS_TEXT = ( "designation, inclusion; source.* (status, publisher, publisher_url, url, licence, licence_text, " "permission_*, attribution, osm_only, line_source, line_file, line_absent_reason, " "decision, decision_text, redistributable); osm.relation; shield.* except note; " - "hike.* except summary, checked and source (start, end, official_url, days, season, terrain, " + "hike.* except summary, checked and source (start, end, official_url, days, season, months, season_basis, season_method, terrain, " "travel, high_point, permit, unfinished, caution and the rest); route.* except note; " "guide.* except price. A replaced track file counts as a change to source.line_file." )