Add the schema for the place registry and the record's place fields
This commit is contained in:
1 parent
fe2306d90b
commit
aad93a246c
5 files changed
+107
-5
No files matched your search
+32
-2
@@ -50,6 +50,8 @@ line_file = "line.geojson"
|
||||
| `wave_note` | string, where present | Why a held trail is held. | `"Held: no usable whole track exists."` |
|
||||
| `inclusion` | string, where present | `nst-unconditional` for every National Scenic Trail that is listed; `candidate-decision-pending` for a candidate. Absent otherwise. | `"nst-unconditional"` |
|
||||
| `short_reason` | string, with `length_km` under 80 | One plain sentence saying why a trail under the 50 mile (80 km) floor is listed, by the owner's test: it has real cross-country travel, it genuinely takes five or more days, or it is very well known and popular. It rests on what the record already says. Required on every record with `length_km` under 80, and refused on any other. A trail whose record can give none of the three reasons is not listed. | `"The book gives it five to eight days."` |
|
||||
| `places_checked` | string (date) | The day the record's `[[place]]` tables were last measured against the published outlines, or reviewed by hand where the trail has no track. Present once the record's places have been settled, including when the answer is no park, range or wilderness at all. Not a fact: changing it alone needs no `[[history]]` entry. | `"2026-11-20"` |
|
||||
| `places_track` | string | The first 16 hex digits of the SHA-256 of the record's `line.geojson` bytes, as they were when the places were measured. Present on every record with a track once its places are settled, and refused on a record with no track. The validator fails a record whose track has changed since, so a new track cannot ship unmeasured. Not a fact. | `"0123456789abcdef"` |
|
||||
|
||||
### What `length_km` counts
|
||||
|
||||
@@ -203,6 +205,18 @@ The trail's own page belongs in `hike.official_url`, not here, and the publisher
|
||||
| `url` | string | The page's address, `http` or `https`. No two links in a record share one. | `"https://www.longtrailswiki.net/wiki/Appalachian_Trail"` |
|
||||
| `note` | string, where needed | One short plain sentence on what the page offers, where that is not obvious. | `"Trip reports and resupply notes."` |
|
||||
|
||||
## `[[place]]`: the parks, ranges and wilderness areas the trail is in
|
||||
|
||||
Optional: an array of tables, one per place, written by `tools/place_trails.py` or, for a trail with no track, entered by hand from a cited source. Every entry names a place in `places.toml` by `kind` and `slug` together (slugs are unique within a kind, not across kinds). A trail is in a place when at least 1 mile (1.6 km) of its main track lies inside the published outline; alternates do not count. A record never names a parent place from `within`: the site works out parent membership itself. Adding or removing a `[[place]]` entry is a fact change and needs a `[[history]]` entry naming `place`; the measured `km` is not a fact, and it is never shown anywhere, including in history text.
|
||||
|
||||
| Field | Type | Meaning | Example |
|
||||
| --- | --- | --- | --- |
|
||||
| `kind` | string | `park`, `range` or `wilderness`. | `"range"` |
|
||||
| `slug` | string | The place's slug in `places.toml`, within its kind. | `"wind-river-range"` |
|
||||
| `basis` | string | `track`: measured from the track against the outline; only on a record with a track. `stated`: the trail has no track and a cited source puts it in the place. A trail later given a track must be re-measured, which the `places_track` check forces. | `"track"` |
|
||||
| `km` | number, with `basis` `track` | The measured length of the main track inside the outline, in kilometres. Recorded so the 1 mile threshold can be audited; never shown anywhere. Required with `track` and refused with `stated`. Not a fact. | `142.3` |
|
||||
| `source` | string, with `basis` `stated` | The address of the page that puts this trail in this place. Required with `stated` and refused with `track`. | `"https://example.org/trail"` |
|
||||
|
||||
## `[[history]]`: who asked for what, and on what evidence
|
||||
|
||||
Required: every record has at least one entry. An array of tables, oldest first, added to and never rewritten. Git keeps the diffs. The history keeps what git does not: the reason for each change, who asked for it, and the requests that were turned down, so that a later request that conflicts with an earlier one is easy to notice and settle.
|
||||
@@ -233,9 +247,9 @@ 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, terrain, travel, high point, permit, unfinished and caution); `[route]` except `note` (the author and the track policy); `[[guide]]` except the price; `[[place]]` except the measured `km`. 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.
|
||||
**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`; `places_checked`, `places_track` and the measured `place.km`, which `tools/place_trails.py` refreshes. 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.
|
||||
|
||||
The site shows the history of each record under "History of this record".
|
||||
|
||||
@@ -398,6 +412,22 @@ An author's page opens with the name, the `summary` as its one sentence (or, wit
|
||||
|
||||
On an `organisation`, `summary`, `bio`, `checked` and `[[author.source]]` are refused; it may carry `url`. An unknown field is refused anywhere in an entry or a source. `tools/validate.py` runs these checks (`tools/check_datafiles.py`).
|
||||
|
||||
## `places.toml`: the parks, ranges and wilderness areas
|
||||
|
||||
One file at the top level, one `[[place]]` entry per place that at least one record names. It is the one spot where a place's display name, kind and source live. Entries are written by `tools/place_trails.py`, sorted by kind then slug, and checked by `tools/validate.py` (`tools/check_places.py`). Slugs are unique within a kind, not across kinds: a park and a wilderness area may share a slug. A page that joins two units, as Sequoia and Kings Canyon are joined, is one entry with two `source_id`s.
|
||||
|
||||
| Field | Type | Meaning | Example |
|
||||
| --- | --- | --- | --- |
|
||||
| `slug` | string | The place's slug, unique within its kind. | `"wind-river-range"` |
|
||||
| `kind` | string | `park`, `range` or `wilderness`. | `"range"` |
|
||||
| `name` | string | The display name. | `"Wind River Range"` |
|
||||
| `where` | array of strings | The state or province codes the place is in, as records write them (`"WY"`, `"ON"`). Proposed by the tool from the `regions` codes shared by at least half of the place's measured trails, and confirmed by a reviewer. | `["WY"]` |
|
||||
| `within` | array of strings, where present | The slugs of parent places, ranges within ranges. Each names an existing `range` entry, and the chains never circle. A trail in a nested range is also in every parent; records never store the parents. | `["rocky-mountains"]` |
|
||||
| `source` | string | Which published outline set the boundary came from: `nps`, `wilderness-connect`, `cpcad` or `gmba-v2`. | `"gmba-v2"` |
|
||||
| `source_id` | string, or array of strings | The publisher's own id for the outline (an array where one page joins units). | `"1234"` |
|
||||
| `source_version` | string | The source's version, or the date the outline was downloaded, so a measurement can be re-derived from the same outline. | `"2026-11-20"` |
|
||||
| `box` | array of numbers | The outline's bounding box as `[west, south, east, north]` in longitude and latitude, rounded to 2 decimals. A measurement, like `km`: the tool refreshes it, and the place's map opens on it. | `[-110.0, 42.5, -108.5, 43.5]` |
|
||||
|
||||
## `trail-numbers.txt`: a permanent number for every trail
|
||||
|
||||
One plain text file at the top level gives every trail a number that never changes and is never used again. It is one `id` per line, after a few `#` comment lines at the top. A trail's number is the zero-based index of its line among the `id` lines (the comments are not counted), so the first `id` is trail 0. The Saved page's short links are written in these numbers (see below).
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# The place registry: every national park, mountain range and wilderness area that a record
|
||||
# names in a [[place]] table. One [[place]] entry per place; fields are documented in
|
||||
# docs/schema.md, section "places.toml". Entries are written by tools/place_trails.py,
|
||||
# sorted by kind then slug, and checked by tools/validate.py. Only places that at least one
|
||||
# record names are listed here.
|
||||
@@ -0,0 +1,56 @@
|
||||
"""Tests for the place schema: the record's [[place]] table, places_checked and
|
||||
places_track, and their place in the history rules (tools/trail_history.py, docs/schema.md).
|
||||
|
||||
Run from the repository root:
|
||||
python3 -m unittest discover tools/tests -p "test_places_schema.py"
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
TOOLS = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
ROOT = os.path.dirname(TOOLS)
|
||||
sys.path.insert(0, TOOLS)
|
||||
|
||||
import trail_history as H # noqa: E402
|
||||
|
||||
|
||||
class PlaceSchemaTest(unittest.TestCase):
|
||||
def test_place_fields_are_schema_fields(self):
|
||||
self.assertIn("place", H.SCHEMA_FIELDS)
|
||||
self.assertIn("place.km", H.SCHEMA_FIELDS)
|
||||
self.assertIn("places_checked", H.SCHEMA_FIELDS)
|
||||
self.assertIn("places_track", H.SCHEMA_FIELDS)
|
||||
|
||||
def test_km_and_stamps_are_not_facts(self):
|
||||
self.assertFalse(H.is_fact("place.km"))
|
||||
self.assertFalse(H.is_fact("places_checked"))
|
||||
self.assertFalse(H.is_fact("places_track"))
|
||||
self.assertTrue(H.is_fact("place.slug"))
|
||||
self.assertTrue(H.is_fact("place.basis"))
|
||||
self.assertTrue(H.is_fact("place.kind"))
|
||||
self.assertTrue(H.is_fact("place.source"))
|
||||
|
||||
def test_a_km_only_change_needs_no_history(self):
|
||||
old = {"id": "x", "place": [{"kind": "range", "slug": "a", "basis": "track", "km": 10.0}]}
|
||||
new = {"id": "x", "place": [{"kind": "range", "slug": "a", "basis": "track", "km": 11.5}]}
|
||||
changed = H.changed_paths(old, new)
|
||||
self.assertEqual(changed, ["place.km"])
|
||||
self.assertEqual([p for p in changed if H.is_fact(p)], [])
|
||||
|
||||
def test_schema_documents_every_place_field(self):
|
||||
with open(os.path.join(ROOT, "docs", "schema.md"), encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
for name in H._TABLES["place"]:
|
||||
self.assertIn(f"`{name}`", text, name)
|
||||
for name in ("places_checked", "places_track"):
|
||||
self.assertIn(f"`{name}`", text, name)
|
||||
|
||||
def test_facts_text_names_place(self):
|
||||
self.assertIn("place", H.FACTS_TEXT)
|
||||
self.assertIn("place.km", H.NOT_FACTS_TEXT)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -19,7 +19,7 @@ URL_RE = re.compile(r"^https?://[^\s/]+\S*$")
|
||||
# names these. A table name on its own ("source", "hike.source") names every field in it.
|
||||
_TABLES = {
|
||||
"": ("id", "name", "common_name", "short_name", "short_name_url", "country", "regions", "length_km",
|
||||
"length_note", "system_km", "system_note", "built_km", "kind", "tier", "designation", "wave", "wave_note", "inclusion", "short_reason"),
|
||||
"length_note", "system_km", "system_note", "built_km", "kind", "tier", "designation", "wave", "wave_note", "inclusion", "short_reason", "places_checked", "places_track"),
|
||||
"source": ("status", "publisher", "publisher_url", "url", "discovery", "format", "crs",
|
||||
"licence", "licence_text", "permission_quote", "permission_by",
|
||||
"permission_date", "permission_url", "attribution", "osm_only", "mainline",
|
||||
@@ -37,6 +37,7 @@ _TABLES = {
|
||||
"guide": ("title", "author", "access", "url", "format", "price", "price_checked",
|
||||
"publisher", "isbn"),
|
||||
"link": ("title", "publisher", "url", "note"),
|
||||
"place": ("kind", "slug", "basis", "km", "source"),
|
||||
}
|
||||
SCHEMA_FIELDS = set()
|
||||
for _table, _names in _TABLES.items():
|
||||
@@ -60,6 +61,8 @@ NOT_FACTS = (
|
||||
"guide.price", "guide.price_checked", # a price read on a date, and refreshed
|
||||
"osm.note", "shield.note", "route.note", "link", # notes and other pages about the trail
|
||||
"wave", "wave_note", # the dataset's own bookkeeping
|
||||
"places_checked", "places_track", # when the places were last measured, and of which track
|
||||
"place.km", # a measurement of the track inside a place, refreshed by the tool
|
||||
)
|
||||
FACTS_TEXT = (
|
||||
"name, common_name, short_name, short_name_url, country, regions, length_km, length_note, system_km, system_note, built_km, kind, tier, "
|
||||
@@ -68,12 +71,14 @@ FACTS_TEXT = (
|
||||
"decision, decision_text, redistributable); osm.relation; shield.* except note; "
|
||||
"hike.* except summary, checked and source (start, end, official_url, days, season, 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."
|
||||
"guide.* except price; place.* except km (kind, slug, basis, source). "
|
||||
"A replaced track file counts as a change to source.line_file."
|
||||
)
|
||||
NOT_FACTS_TEXT = (
|
||||
"history; verification.*; source.source_checked, discovery, format, crs, mainline, "
|
||||
"length_gap_note; hike.summary, hike.checked, hike.source; guide.price, "
|
||||
"guide.price_checked; osm.note, shield.note, route.note; link; wave, wave_note."
|
||||
"guide.price_checked; osm.note, shield.note, route.note; link; wave, wave_note; "
|
||||
"places_checked, places_track, place.km."
|
||||
)
|
||||
TRACK_FIELD = "source.line_file"
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
collections.toml [[collection]] named sets of trails set side by side (olt/standing.py)
|
||||
[[list]] which lists the home page shows, and in what order (olt/home.py)
|
||||
authors.toml [[author]] route authors, and the words about the people among them (olt/authors.py)
|
||||
places.toml [[place]] the parks, mountain ranges and wilderness areas records name
|
||||
|
||||
Each is checked by tools/validate.py and described in docs/schema.md. Like left-out.toml, a file
|
||||
is looked for in the repository being built and then in this one, so a test repository without
|
||||
@@ -37,6 +38,11 @@ def authors(repo_root):
|
||||
return load(repo_root, "authors.toml", "author")
|
||||
|
||||
|
||||
def places(repo_root):
|
||||
"""The [[place]] entries of places.toml: the place registry."""
|
||||
return load(repo_root, "places.toml", "place")
|
||||
|
||||
|
||||
def lists(repo_root):
|
||||
"""The [[list]] entries of collections.toml: a list's key, and `home`, its place in the home page's row."""
|
||||
return load(repo_root, "collections.toml", "list")
|
||||
Reference in new issue
Block a user