Give a single day figure as one figure, not as a range, in the data for search engines
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
2258c1f280
commit
6c6251a600
3 files changed
+20
-2
No files matched your search
+6
-2
@@ -277,8 +277,12 @@ def _properties(rec):
|
||||
props.append(_pv("Built length", rec["built_km"], "KMT", "kilometres"))
|
||||
days = h.get("days")
|
||||
if isinstance(days, list) and len(days) == 2:
|
||||
props.append(_pv("Usual time to walk it all", f"{days[0]} to {days[1]} days", "DAY", "days",
|
||||
minValue=days[0], maxValue=days[1]))
|
||||
lo, hi = min(days), max(days)
|
||||
if lo == hi: # one figure, not a range: "7 days", never "7 to 7 days"
|
||||
props.append(_pv("Usual time to walk it all", lo, "DAY", "day" if lo == 1 else "days"))
|
||||
else:
|
||||
props.append(_pv("Usual time to walk it all", f"{lo} to {hi} days", "DAY", "days",
|
||||
minValue=lo, maxValue=hi))
|
||||
elif isinstance(days, int):
|
||||
props.append(_pv("Usual time to walk it all", days, "DAY", "days"))
|
||||
if h.get("high_point_m"):
|
||||
|
||||
@@ -103,6 +103,16 @@ class StructuredDataTest(unittest.TestCase):
|
||||
def props(self, rec):
|
||||
return {(p["name"], p.get("unitCode")): p for p in seo.place_node(rec, GH)["additionalProperty"]}
|
||||
|
||||
def test_one_day_figure_is_never_written_as_a_range(self):
|
||||
rec = florida()
|
||||
rec["hike"] = dict(rec.get("hike") or {}, days=[7, 7])
|
||||
one = self.props(rec)[("Usual time to walk it all", "DAY")]
|
||||
self.assertEqual(one["value"], 7)
|
||||
self.assertNotIn("minValue", one)
|
||||
rec["hike"]["days"] = [5, 8]
|
||||
span = self.props(rec)[("Usual time to walk it all", "DAY")]
|
||||
self.assertEqual((span["value"], span["minValue"], span["maxValue"]), ("5 to 8 days", 5, 8))
|
||||
|
||||
def test_the_length_stays_canonical_and_the_system_figure_is_labelled(self):
|
||||
props = self.props(florida())
|
||||
self.assertEqual(props[("Published length", "KMT")]["value"], 1818)
|
||||
|
||||
Reference in new issue
Block a user