Keep parent ranges off the record when a child range holds the trail
This commit is contained in:
1 parent
0b929aa01e
commit
d432d6a296
2 files changed
+23
No files matched your search
@@ -549,6 +549,19 @@ def propose(records, outlines):
|
||||
counts[code] = counts.get(code, 0) + 1
|
||||
n = len(hit.trails)
|
||||
hit.where = sorted(c for c, k in counts.items() if k * 2 >= n) or list(hit.outline.state_codes_hint)
|
||||
# Parents are never stored on a record (the build closes membership over within):
|
||||
# a range drops out of a trail's list when the trail is also in one of its
|
||||
# descendants, by the GMBA Path. Place counts stay as measured.
|
||||
paths = {}
|
||||
for o in outlines:
|
||||
if o.kind == "range" and o.path:
|
||||
paths[(o.kind, o.slug or slugify(o.name))] = o.path
|
||||
for tid, lst in p.per_trail.items():
|
||||
here = {paths[k] for k, _km in lst if k in paths}
|
||||
p.per_trail[tid] = [(k, km) for k, km in lst
|
||||
if k not in paths
|
||||
or not any(other != paths[k] and other.startswith(paths[k] + " > ")
|
||||
for other in here)]
|
||||
for lst in p.per_trail.values():
|
||||
lst.sort(key=lambda t: (-t[1], t[0]))
|
||||
p.near.sort(key=lambda x: (abs(x.km - MIN_KM), x.trail))
|
||||
|
||||
@@ -160,6 +160,16 @@ class ProposalTest(unittest.TestCase):
|
||||
self.assertIn("needs a person", text)
|
||||
self.assertIn("z", text)
|
||||
|
||||
def test_a_parent_range_is_not_stored_when_a_child_is(self):
|
||||
big = outline("range", "R0", "Big Range",
|
||||
Polygon([(-111, 42), (-108, 42), (-108, 45), (-111, 45)]))
|
||||
big.path = "Continent > Big Range"
|
||||
self.range.path = "Continent > Big Range > Beta Range"
|
||||
p = P.propose([rec("a", ["WY"], self.inside)], [big, self.range])
|
||||
self.assertEqual({k for k, _ in p.per_trail["a"]}, {("range", "beta-range")})
|
||||
# the parent's page count still holds the trail, as measured
|
||||
self.assertEqual({t for t, _ in p.per_place[("range", "big-range")].trails}, {"a"})
|
||||
|
||||
def test_one_gmba_id_outside_the_allow_list_is_not_proposed_but_is_listed_by_candidates(self):
|
||||
records = [rec(f"t{i}", ["WY"], self.inside) for i in range(3)]
|
||||
all_ranges = [dict(gmba_id="R1", name="Beta Range", path="Beta Range",
|
||||
|
||||
Reference in new issue
Block a user