Add the park units and ranges that trails with no track are placed in, place the tracked trails in them, and keep the history heading when apply rewrites place tables

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 11:21:34 -07:00
1 parent 8c14aee802
commit 2186ca8216
13 files changed
+362 -19

No files matched your search

+57
View File
@@ -342,3 +342,60 @@ name = "Sequoia and Kings Canyon National Parks"
source_id = "GLAC"
slug = "glacier"
name = "Glacier National Park"
# National Park Service units that are not national parks. A park page means any National
# Park Service unit (monuments, recreation areas, parkways, preserves, historic sites), so a
# unit goes in when a trail is placed in it by hand. Each is measured against every track too.
# The unit's own name from the boundary service is kept, except where noted.
[[park]]
source_id = "BLRI"
[[park]]
source_id = "COLM"
[[park]]
source_id = "FOBO"
# The boundary service lists the preserve and the park of this unit under one code, named for
# the preserve; the unit is Gates of the Arctic National Park and Preserve.
[[park]]
source_id = "GAAR"
slug = "gates-of-the-arctic-national-park-and-preserve"
name = "Gates of the Arctic National Park and Preserve"
[[park]]
source_id = "GLCA"
[[park]]
source_id = "KAWW"
[[park]]
source_id = "LAKE"
# Ranges not named by the owner that 3 or more trails reach once the trails with no track are
# counted with the tracked ones (2026-11-20): tracked trails measured, the others placed by a
# cited page.
[[range]]
gmba_id = "12004"
slug = "toiyabe-range"
name = "Toiyabe Range"
where = ["NV"]
[[range]]
gmba_id = "11567"
slug = "la-sal-mountains"
name = "La Sal Mountains"
within = ["colorado-plateau"]
where = ["CO", "UT"]
[[range]]
gmba_id = "12446"
slug = "peninsular-ranges"
name = "Peninsular Ranges"
where = ["CA"]
[[range]]
gmba_id = "12033"
slug = "vancouver-island-ranges"
name = "Vancouver Island Ranges"
where = ["BC"]
+47 -13
View File
@@ -901,6 +901,11 @@ def _remove_place_blocks(doc, rec):
while lo > 0 and doc.lines[lo - 1].strip() == "":
lo -= 1
break
# the span runs to the next header; the blank lines and comment lines at its end
# belong to what follows (the history's heading comment), so they stay
while end > header + 1 and (doc.lines[end - 1].strip() == ""
or doc.lines[end - 1].lstrip().startswith("#")):
end -= 1
del doc.lines[lo:end]
@@ -1059,27 +1064,56 @@ def apply(proposal_path, root, today, exclude=frozenset()):
def add_stated(root, rid, kind, slug, source_url, quote, today):
"""Place a trackless trail from a cited source, with its history entry."""
if not str(source_url).startswith(("https://", "http://")):
raise ValueError("stated needs an http(s) source address")
if not str(quote).strip():
raise ValueError("stated needs the sentence that puts the trail in the place")
add_stated_many(root, rid, [{"kind": kind, "slug": slug, "source": source_url, "quote": quote}], today)
def add_stated_many(root, rid, items, today):
"""Place a trackless trail in every place of `items` from cited sources, with one
history entry for the record. An item is {kind, slug, source, quote}; with
"summary": True the quote is the sentence of the record's own summary and the source is
the page the summary was taken from, and the history says so."""
if not items:
raise ValueError("stated needs at least one place")
for it in items:
if not str(it["source"]).startswith(("https://", "http://")):
raise ValueError("stated needs an http(s) source address")
if not str(it["quote"]).strip():
raise ValueError("stated needs the sentence that puts the trail in the place")
tdir = os.path.join(root, rid)
if line_file_of(tdir):
raise ValueError(f"{rid} has a track; stated is only for a trail with no track")
registry = {(e.get("kind"), e.get("slug")): e for e in registry_entries(root)}
entry = registry.get((kind, slug))
if entry is None:
raise ValueError(f"{kind}/{slug} is not in places.toml; add its registry entry first")
doc, path = _doc_of(root, rid)
rec = doc.data()
if any((p.get("kind"), p.get("slug")) == (kind, slug) for p in rec.get("place") or []):
raise ValueError(f"{rid} already names {kind}/{slug}")
doc.append_block("place", {"kind": kind, "slug": slug, "basis": "stated", "source": source_url})
seen = {(p.get("kind"), p.get("slug")) for p in rec.get("place") or []}
names = []
for it in items:
key = (it["kind"], it["slug"])
if key not in registry:
raise ValueError(f"{it['kind']}/{it['slug']} is not in places.toml; add its registry entry first")
if key in seen:
raise ValueError(f"{rid} already names {it['kind']}/{it['slug']}")
seen.add(key)
names.append(registry[key].get("name") or it["slug"])
for it in items:
doc.append_block("place", {"kind": it["kind"], "slug": it["slug"], "basis": "stated",
"source": it["source"]})
_set_top(doc, rec, "places_checked", today)
name = entry.get("name") or slug
if len(names) == 1:
where = names[0]
else:
where = ", ".join(names[:-1]) + " and " + names[-1]
groups = {}
for it, name in zip(items, names):
groups.setdefault((it["source"], it["quote"], bool(it.get("summary"))), []).append(name)
parts = []
for (source, quote, summary), who in groups.items():
lead = "The trail's own summary says" if summary else "The page says"
tail = f" ({', '.join(who)})" if len(groups) > 1 else ""
parts.append(f'{lead}: "{quote}"{tail}')
doc.append_history(_history_entry(
today, f"The trail was placed in {name} from a published page, as it has no track to measure.",
f'The page says: "{quote}"', source_url))
today, f"The trail was placed in {where} from published pages, as it has no track to measure.",
" ".join(parts), items[0]["source"]))
_save(doc, path)
+24
View File
@@ -521,6 +521,30 @@ class ApplyTest(unittest.TestCase):
self.assertEqual(rec["places_checked"], "2026-11-20")
self.assertEqual(rec["history"][-1]["fields"], ["place"])
def test_a_second_apply_of_the_same_proposal_leaves_every_record_byte_identical(self):
P.apply(self.pjson, self.root, "2026-11-20")
before = {t: open(self.trail_toml(t)).read() for t in ("aa", "bb", "cc")}
self.assertEqual(P.apply(self.pjson, self.root, "2026-11-20"), [])
for t, text in before.items():
self.assertEqual(open(self.trail_toml(t)).read(), text)
def test_stated_many_writes_every_place_with_one_history_entry(self):
P.apply(self.pjson, self.root, "2026-11-20")
reg = P.registry_entries(self.root)
reg.append({"slug": "beta-range", "kind": "range", "name": "Beta Range", "where": ["WY"],
"source": "gmba-v2", "source_id": "1", "source_version": "x", "box": [0, 0, 1, 1]})
P.write_registry(self.root, reg)
before = len(read_toml(self.trail_toml("zz"))["history"])
P.add_stated_many(self.root, "zz", [
{"kind": "park", "slug": "alpha-park", "source": "https://example.org/t", "quote": "Q one."},
{"kind": "range", "slug": "beta-range", "source": "https://example.org/t", "quote": "Q one."},
], "2026-11-20")
rec = read_toml(self.trail_toml("zz"))
self.assertEqual([p["slug"] for p in rec["place"]], ["alpha-park", "beta-range"])
self.assertEqual(len(rec["history"]), before + 1)
self.assertIn("Alpha Park and Beta Range", rec["history"][-1]["change"])
self.assertEqual(rec["history"][-1]["fields"], ["place"])
def test_stamp_none_sets_places_checked_with_no_place_tables_and_no_history(self):
P.stamp_none(self.root, "zz", "2026-11-20")
rec = read_toml(self.trail_toml("zz"))