Place the Mogollon Rim Trail in the White Mountains of Arizona, and refuse a place that lies in none of a trail's states or provinces
A new registry range, white-mountains-arizona, shown as White Mountains, in Arizona. The validator now fails a record whose place's where shares no state or province with the record's regions, and place_trails.py no longer places a trail in a place outside its regions. The rule also caught the Hot Springs Trail (Nevada missing from its regions) and the North Boundary Trail (British Columbia missing), which now list those regions, and the Sentier international des Appalaches, whose track carries the Maine IAT into Katahdin Woods and Waters: that placement is removed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7e4d1de494
commit
3b745f706c
12 files changed
+111
-26
No files matched your search
@@ -151,6 +151,13 @@ def check_record(tid, rec, tdir, registry, errors):
|
||||
errors.append(f"{where} slug must be a non-empty string")
|
||||
elif kind in KINDS and (kind, slug) not in registry:
|
||||
errors.append(f"{where} {kind}/{slug} is not in places.toml")
|
||||
if kind in KINDS and (kind, slug) in registry:
|
||||
lies = [str(c) for c in registry[(kind, slug)].get("where") or []]
|
||||
regions = [str(c) for c in rec.get("regions") or []]
|
||||
if lies and regions and not set(lies) & set(regions):
|
||||
errors.append(f"{where} {kind}/{slug} lies in {', '.join(lies)}, none of the "
|
||||
f"record's regions ({', '.join(regions)}); a place must lie in at "
|
||||
f"least one of the trail's states or provinces")
|
||||
if (kind, slug) in seen:
|
||||
errors.append(f"{where} lists {kind}/{slug} more than once; a place is listed once per record")
|
||||
seen.add((kind, slug))
|
||||
|
||||
@@ -262,6 +262,14 @@ name = "White Mountains"
|
||||
within = ["appalachian-mountains"]
|
||||
where = ["ME", "NH"]
|
||||
|
||||
# The White Mountains of Arizona (GMBA 16575), not the ones of New Hampshire and Maine above.
|
||||
# The display name is the same; the slug says which.
|
||||
[[range]]
|
||||
gmba_id = "16575"
|
||||
slug = "white-mountains-arizona"
|
||||
name = "White Mountains"
|
||||
where = ["AZ"]
|
||||
|
||||
[[range]]
|
||||
gmba_id = "11169"
|
||||
slug = "bighorn-mountains"
|
||||
|
||||
+27
-4
@@ -536,7 +536,9 @@ def merge_same_name(outlines):
|
||||
place carries every id. The source lists some ranges twice under different ids."""
|
||||
merged, order = {}, []
|
||||
for o in outlines:
|
||||
key = (o.kind, o.source, " ".join(o.name.lower().split()))
|
||||
# An explicit slug tells two ranges of one display name apart (the White Mountains
|
||||
# of New Hampshire and of Arizona); the two Palisades ids share a slug and merge.
|
||||
key = (o.kind, o.source, " ".join(o.name.lower().split()), o.slug or "")
|
||||
# Two wilderness areas or parks of one name in different places are two places
|
||||
# (assign_slugs tells them apart by state); a range is one wherever its pieces lie.
|
||||
if key in merged and o.kind != "range" and not any(
|
||||
@@ -686,7 +688,24 @@ def _measure(records, outlines):
|
||||
return hits
|
||||
|
||||
|
||||
def propose(records, outlines):
|
||||
def propose(records, outlines, reviewed_where=None):
|
||||
"""Measure every track against every outline. A place counts for a trail only when it
|
||||
lies in at least one of the trail's states or provinces (the validator's rule): a track
|
||||
that strays over a border, or a relation that carries a neighbour's section, does not
|
||||
place the trail in the neighbour's park. reviewed_where is the registry's reviewed
|
||||
`where` by (kind, slug); it wins over the outline's own."""
|
||||
reviewed_where = reviewed_where or {}
|
||||
lies_cache = {}
|
||||
|
||||
def lies(idx, regions):
|
||||
if not regions:
|
||||
return True
|
||||
if idx not in lies_cache:
|
||||
o = outlines[idx]
|
||||
lies_cache[idx] = set(reviewed_where.get((o.kind, o.slug or slugify(o.name)))
|
||||
or where_of(o))
|
||||
return not lies_cache[idx] or bool(lies_cache[idx] & set(regions))
|
||||
|
||||
p = Proposal(names={r["id"]: r.get("name") or r["id"] for r in records})
|
||||
p.no_track = [r["id"] for r in records if r.get("track") is None]
|
||||
for r in records:
|
||||
@@ -696,6 +715,8 @@ def propose(records, outlines):
|
||||
for (tid, idx), (km, clipped) in sorted(hits.items()):
|
||||
o = outlines[idx]
|
||||
key = (o.kind, o.slug or slugify(o.name))
|
||||
if not lies(idx, by_id[tid].get("regions")):
|
||||
continue
|
||||
if abs(km - MIN_KM) <= 0.5:
|
||||
p.near.append(NearItem(tid, key, km, clipped))
|
||||
if km < MIN_KM:
|
||||
@@ -1149,7 +1170,8 @@ def check(root, cache, outlines=None, versions=None, records=None):
|
||||
versions = source_versions(cache)
|
||||
if records is None:
|
||||
records = load_records(root)
|
||||
p = propose(records, outlines)
|
||||
p = propose(records, outlines, {(e.get("kind"), e.get("slug")): e.get("where")
|
||||
for e in registry_entries(root)})
|
||||
diffs = []
|
||||
current_counts = {}
|
||||
for r in records:
|
||||
@@ -1246,7 +1268,8 @@ def main(argv=None):
|
||||
allow = load_allowlist(_opt(argv, "--allowlist", default_allowlist_path()))
|
||||
outlines = catalogue(cache_dir(), allow)
|
||||
records = load_records()
|
||||
p = propose(records, outlines)
|
||||
p = propose(records, outlines, {(e.get("kind"), e.get("slug")): e.get("where")
|
||||
for e in registry_entries(ROOT)})
|
||||
p.versions = source_versions(cache_dir())
|
||||
dest = os.path.join(_out_dir(_opt(argv, "--out")), "proposal.md")
|
||||
render_proposal(p, dest)
|
||||
|
||||
@@ -111,6 +111,17 @@ class ProposalTest(unittest.TestCase):
|
||||
self.park_only = LineString([(-109.9, 43.2), (-109.9, 43.29)])
|
||||
self.outside = LineString([(-107.0, 43.2), (-107.0, 43.29)])
|
||||
|
||||
def test_a_place_outside_the_trails_regions_does_not_place_it(self):
|
||||
p = P.propose([rec("a", ["NH"], self.inside)], [self.park, self.range])
|
||||
self.assertEqual(p.per_trail["a"], [])
|
||||
p = P.propose([rec("a", ["NH", "WY"], self.inside)], [self.park, self.range])
|
||||
self.assertEqual({k for k, _km in p.per_trail["a"]}, {("park", "alpha-park"), ("range", "beta-range")})
|
||||
|
||||
def test_the_registrys_reviewed_where_wins(self):
|
||||
p = P.propose([rec("a", ["NH"], self.inside)], [self.park],
|
||||
{("park", "alpha-park"): ["NH"]})
|
||||
self.assertEqual([k for k, _km in p.per_trail["a"]], [("park", "alpha-park")])
|
||||
|
||||
def test_propose_lists_per_trail_places_and_per_place_trails(self):
|
||||
records = [rec("a", ["WY"], self.inside), rec("b", ["WY"], self.park_only),
|
||||
rec("c", ["WY"], self.inside)]
|
||||
@@ -189,6 +200,13 @@ class ProposalTest(unittest.TestCase):
|
||||
out = P.assign_slugs(out)
|
||||
self.assertEqual(out[0].slug, "palisades") # no numeric suffix, no state code
|
||||
|
||||
def test_two_ranges_of_one_display_name_with_different_slugs_stay_two_places(self):
|
||||
a = outline("range", "12331", "White Mountains", self.park.geometry, slug="white-mountains")
|
||||
b = outline("range", "16575", "White Mountains", self.range.geometry,
|
||||
slug="white-mountains-arizona")
|
||||
self.assertEqual([o.slug for o in P.merge_same_name([a, b])],
|
||||
["white-mountains", "white-mountains-arizona"])
|
||||
|
||||
def test_the_same_name_from_two_sources_or_kinds_is_not_merged(self):
|
||||
a = outline("park", "1", "Glacier", self.park.geometry, hint=["MT"])
|
||||
b = outline("park", "2", "Glacier", self.range.geometry, hint=["BC"])
|
||||
|
||||
@@ -183,3 +183,19 @@ class WholeRepoTest(unittest.TestCase):
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class PlaceLiesInTheTrailsRegionsTest(unittest.TestCase):
|
||||
def stated(self, **kw):
|
||||
return record(regions=kw.pop("regions"), places_checked="2026-11-20",
|
||||
place=[{"kind": "range", "slug": "wind-river-range", "basis": "stated",
|
||||
"source": "https://example.org/x"}])
|
||||
|
||||
def test_a_place_in_one_of_the_trails_states_passes(self):
|
||||
errs = record_errors(self.stated(regions=["ID", "WY"]))
|
||||
self.assertEqual([e for e in errs if "lies in" in e], [])
|
||||
|
||||
def test_a_place_in_none_of_the_trails_states_fails(self):
|
||||
errs = record_errors(self.stated(regions=["AZ", "NM"]))
|
||||
self.assertTrue(any("range/wind-river-range lies in WY, none of the record's regions (AZ, NM)" in e
|
||||
for e in errs), errs)
|
||||
Reference in new issue
Block a user