Show an estimated season as an estimate on the trail page, in lists and tables, and in the month filter; say how seasons are sourced and tested on the reference page

This commit is contained in:
swaits committed 2026-11-20 13:26:51 -07:00
1 parent 713fff78df
commit e95131833b
20 files changed
+481 -103

No files matched your search

+10 -5
View File
@@ -78,7 +78,7 @@ GROUPS = (
("walking", "By kind of walking", "Loops, high routes, walking with no trail, and trails not yet finished."),
("terrain", "By terrain", "The main kinds of country a trail crosses."),
("holder", "By who looks after it", "Trails whose designation names the holder."),
("month", "By month", "Trails whose season on file includes the month. Only some trails have a season."),
("month", "By month", "Trails normally hiked in the month. Estimated seasons are marked."),
("where", "By country and GPX", "Where a trail is, and whether its page has a track to download."),
)
@@ -115,7 +115,7 @@ def time_note(recs, records):
def _month_list(m):
name = facets.MONTHS[m - 1]
return List(f"hike-in-{name.lower()}", f"Hiking in {name}",
f"Trails whose season on file includes {name}.",
f"Trails normally hiked in {name}. Estimated seasons are marked.",
lambda r, m=m: m in facets.months(r),
page_title=f"Long Trails to Hike in {name}: {{n}} Trails", group="month", note=month_note(name),
min_size=MONTH_MIN)
@@ -123,9 +123,14 @@ def _month_list(m):
def month_note(name):
def note(recs, records):
have = sum(1 for r in records if facets.months(r))
return (f"Only {have} of the {len(records)} trails have a season on file, so this page covers those "
f"{have}. It is not every trail that can be walked in {name}.")
est = sum(1 for r in recs if facets.season_estimated(r))
stated = len(recs) - est
if not est:
return f"A source states the season for all {stated}."
if not stated:
return "No source states the season for these, so each is estimated from climate."
return (f"A source states the season for {stated} of these. For the other {est} it is "
f"estimated from climate, and marked.")
return note
+13
View File
@@ -4,11 +4,13 @@
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)
tools/season_blind_test.json how the judged seasons did against the seasons pages state (olt/reference.py)
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
one still builds.
"""
import json
import os
import tomllib
@@ -40,3 +42,14 @@ def authors(repo_root):
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")
def blind_test(repo_root):
"""The blind test of the judged seasons (tools/season_blind_test.json, written by
tools/season_judge.py score), or None when there is none."""
for base in (repo_root, REAL_ROOT):
path = os.path.join(base or REAL_ROOT, "tools", "season_blind_test.json")
if os.path.isfile(path):
with open(path, encoding="utf-8") as f:
return json.load(f)
return None
+83 -6
View File
@@ -172,8 +172,15 @@ def months(rec):
return sorted({x for x in (m or []) if isinstance(x, int) and 1 <= x <= 12})
def season_text(rec):
"""The phrase on the trail page: [hike].season, else built from the months."""
def season_estimated(rec):
"""True when no page states the season: it was estimated (season_basis "estimate"), or set by
judgement from pages that differ (it carries a season_method). Such a season reads "About"."""
h = hike.table(rec)
return bool(h.get("season")) and (h.get("season_basis") == "estimate" or bool((h.get("season_method") or "").strip()))
def season_phrase(rec):
"""The phrase on the trail page as the record gives it: [hike].season, else built from the months."""
phrase = (hike.table(rec).get("season") or "").strip()
if phrase:
return phrase[:1].upper() + phrase[1:]
@@ -185,6 +192,74 @@ def season_text(rec):
return words.join_names(MONTHS[m - 1] for m in ms)
def season_text(rec):
"""The season as a page shows it: the phrase, or "About ..." where it is estimated, so an
estimate never reads as a stated fact ("About June to September", "About all year")."""
phrase = season_phrase(rec)
if not phrase or not season_estimated(rec):
return phrase
if phrase.lower().startswith("about"):
return phrase
if phrase.lower() == "all year":
phrase = phrase.lower()
return "About " + phrase
def season_kind(rec):
"""How the season is known: "stated" (a page states it), "judged" (set by judgement from pages
that differ), "estimated" (no page states one), or "" when the trail has no season."""
if not hike.table(rec).get("season"):
return ""
if not season_estimated(rec):
return "stated"
return "judged" if season_basis(rec) == "sources" else "estimated"
SEASON_CONFIDENCE = re.compile(r"\s*Confidence: (high|medium|low)\.\s*$")
JUDGED_LEAD = "Judged from the climate at the trail's elevation and from similar trails."
def season_confidence(rec):
""""high", "medium" or "low" from the end of the season's method; "" when it names none."""
found = SEASON_CONFIDENCE.search(hike.table(rec).get("season_method") or "")
return found.group(1) if found else ""
def season_reason(rec):
"""What the season's method says sets the season, without its standard first sentence and its
closing confidence."""
text = SEASON_CONFIDENCE.sub("", (hike.table(rec).get("season_method") or "").strip()).strip()
if text.startswith(JUDGED_LEAD):
text = text[len(JUDGED_LEAD):].strip()
return text
def season_pages_differ(rec):
"""True for a season set by judgement from pages that state different seasons."""
return season_estimated(rec) and season_basis(rec) == "sources"
def season_note(rec):
"""Says an estimated season is not a page's statement, how it was worked out, what sets it
there and how far to trust it; "" when a page states the season."""
if not season_estimated(rec):
return ""
reason = season_reason(rec)
if season_pages_differ(rec):
lead = "No one page states this season."
else:
lead = ("No page states a season. This is estimated from the climate at the trail's "
"elevation and from similar trails.")
parts = [lead]
if reason:
parts.append(reason)
conf = season_confidence(rec)
if conf:
parts.append(f"Confidence: {conf}.")
parts.append("People do walk it outside these months.")
return " ".join(parts)
SEASON_BASIS_TEXT = {
"primary": "The season comes from the page of the body that manages the trail or the trail's own association or, for a route, its author.",
"sources": "Two or more pages from different publishers agree on the season.",
@@ -203,10 +278,12 @@ def season_basis(rec):
def season_basis_line(rec):
"""One sentence for "About this data"; "" when the season has no recorded basis."""
basis = season_basis(rec)
if basis == "estimate":
method = (hike.table(rec).get("season_method") or "").strip()
return (method + " No page states a season.").strip()
return SEASON_BASIS_TEXT.get(basis, "")
if not season_estimated(rec):
return SEASON_BASIS_TEXT.get(basis, "")
method = (hike.table(rec).get("season_method") or "").strip()
if season_pages_differ(rec):
return (method + " It is a judgement, not any one page's statement.").strip()
return (method + " No page states a season.").strip()
# Terrain, Walking, Shape ----------------------------------------------------
+17 -10
View File
@@ -193,6 +193,9 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals
if search:
data["search"] = searchtext.attribute(rec)
attrs = "".join(f' data-{k}="{esc(v)}"' for k, v in data.items())
estimated = facets.season_estimated(rec)
if estimated:
attrs += ' data-estimate="yes"'
if common.line_differs(rec):
attrs += ' data-partial="yes"'
h = f"h{level}"
@@ -203,6 +206,9 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals
desc = entry_desc(rec)
desc_html = f'\n <p class="entry__desc">{esc(desc)}</p>' if desc else ""
time_html = esc(facets.time_text(rec)) + (' <small class="entry__est">estimate</small>' if est else "")
season_html = (f'\n <div class="entry__season"><dt>{facets.SEASON}</dt><dd>{esc(facets.season_text(rec))}'
+ ('<small class="entry__est">estimate</small>' if estimated else "") + "</dd></div>"
if facets.months(rec) else "")
climb_html = (f'\n <div class="entry__climb"><dt>Climb</dt><dd>{words.elevation(climb_m, "stack")}'
f'<small class="entry__est">computed</small></dd></div>') if climb_m is not None else ""
if hidden:
@@ -227,7 +233,7 @@ def entry(rec, *, level=3, extra="", routes_list=False, hidden=False, eager=Fals
<dl class="entry__facts">{lead_html}
<div class="entry__length"><dt>Length</dt><dd>{words.length(rec["length_km"], "stack", rec["derived"]["length_mi"])}<span class="loglen" style="--km: {rec["length_km"]}" aria-hidden="true"></span></dd></div>
<div class="entry__time"><dt>Time</dt><dd>{time_html}</dd></div>
<div class="entry__line"><dt>GPX</dt><dd class="line line--{"yes" if facets.gpx_here(rec) else "no"}">{gpx_cell(rec)}</dd></div>{climb_html}{more_html}
<div class="entry__line"><dt>GPX</dt><dd class="line line--{"yes" if facets.gpx_here(rec) else "no"}">{gpx_cell(rec)}</dd></div>{season_html}{climb_html}{more_html}
</dl>{extra}
</li>"""
@@ -352,10 +358,14 @@ def finder_form(records, c=None, steps=None, where="all"):
</fieldset>""")
if facets.offered(records, "season") and _narrows(c, "month", range(1, 13)):
month_opts = "".join(_opt(str(i), m, c[f"month:{i}"]) for i, m in enumerate(facets.MONTHS, 1) if c[f"month:{i}"])
# A way to leave estimated seasons out, offered only where some of these trails have one.
stated_box = ('\n <label class="field__check"><input type="checkbox" name="stated" value="1" disabled> '
'Leave out estimated seasons</label>'
if any(facets.season_estimated(r) for r in records) else "")
first.append(f"""<div class="field" data-facet="month">
<label class="field__label" for="month">{facets.SEASON}</label>
<select class="select" id="month" name="month"><option value="">Any month</option>{month_opts}</select>
<p class="field__hint">Trails usually walked in that month.</p>
<p class="field__hint">Trails usually walked in that month. Estimated seasons are marked.</p>{stated_box}
{_missing(records, "season")}
</div>""")
if _narrows(c, "kind", facets.KINDS):
@@ -535,7 +545,7 @@ def key(official=True):
def results(recs=None, *, finder=False, groups=None, routes_list=False, default_sort="name", saved=False, top=3,
ranked="", lead=None, more=None, tools=True, by=None, every=False, wholly=None):
ranked="", lead=None, more=None, tools=True, by=None, every=False, wholly=None, season=False):
"""The list of trails, as every page shows it: div.results > head, key, list head, ol.entries.
Every list carries the same "Sort by" control. The rows are written in
@@ -544,6 +554,7 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
finder: a list driven by the filter bar over it (listing(): live count, empty state).
every: the list holds every trail (the home page's).
season: show each row's season (a month's list), as app.js does when a month is chosen.
groups: [(heading, trails, extra_fn)] to list the trails under headings (level `top`);
sorting is within each group and the groups keep their order. A heading may be a pair
(heading HTML, intro HTML): the intro is a sentence under the heading (an author's summary).
@@ -624,18 +635,14 @@ def results(recs=None, *, finder=False, groups=None, routes_list=False, default_
tools = sort_select(default_sort, saved=saved, ranked=ranked, wholly=wholly)
dflt = SAVED_ORDER[0] if saved else "rank" if ranked else HERE_ORDER if wholly else default_sort
finder_attr = " data-finder" if finder else ""
# Under the count, while a month is chosen: how many trails are left out for having no season on
# file, and a way to see them (app.js fills it in from the rows, the same ones the list is).
unseasoned = ('\n <p class="results-note" data-unseasoned hidden><span data-unseasoned-text></span> '
'<button class="results-note__show" type="button" data-unseasoned-show>Show them</button></p>'
if finder else "")
return Markup(f"""<div class="results"{finder_attr} data-sortable data-default-sort="{esc(dflt)}">
season_attr = " data-season-shown" if season else ""
return Markup(f"""<div class="results"{finder_attr}{season_attr} data-sortable data-default-sort="{esc(dflt)}">
<div class="results-head">
{count}
<div class="results-tools">
{tools}
</div>
</div>{unseasoned}
</div>
{key(official=not only_routes)}
{list_head(default_sort)}{lists}{empty}
</div>""")
+1 -1
View File
@@ -105,7 +105,7 @@ def page(p, records, site, all_pages):
</div></header>
</div></div>
<div class="container section place">
{home.browse_view(home.listing(recs, default_sort=lst.sort, top=2, where=""), home.overview_map(recs, f"Map of the trails in {name}: {lst.title}", place=bounds.place_box(info["key"])),
{home.browse_view(home.listing(recs, default_sort=lst.sort, top=2, where="", season=lst.group == "month"), home.overview_map(recs, f"Map of the trails in {name}: {lst.title}", place=bounds.place_box(info["key"])),
about=summary.facts(recs, records, place=(name, [info["key"]])), about_title=f"About these trails in {name}")}
<nav class="region-nav" aria-label="Lists"><a href="{esc(browse.path(lst))}">{esc(lst.title)} everywhere</a> · <a href="/lists/">All lists</a></nav>
{nav}
+32 -2
View File
@@ -96,6 +96,32 @@ def verified(records):
return out
def _pct(share):
return f"{share * 100:.0f} percent"
def season_section(records, blind):
"""The paragraphs and table saying where seasons come from, how many trails have each kind, and how
the estimates did in the blind test (read from tools/season_blind_test.json, never typed)."""
n = len(records)
kinds = collections.Counter(facets.season_kind(r) for r in records)
basis = collections.Counter(facets.season_basis(r) for r in records if facets.season_kind(r) == "stated")
rows = [["The body that manages the trail, its association, or for a route its author", str(basis["primary"])],
["Two or more pages from different publishers that agree", str(basis["sources"])],
["One page", str(basis["source"])],
["Pages that differ, so set by judgement from all of them", str(kinds["judged"])],
["No page states one, so estimated from climate", str(kinds["estimated"])],
["All trails", str(n)]]
out = [f"""<p>Every trail has a season. Where a page states one, the season is that page&rsquo;s. Where the pages that state one differ and none is the trail&rsquo;s holder, its association or its route&rsquo;s author, the season is set by judgement from all of them and the climate, and the page says so. Where no page states one, the season is estimated from the climate at the trail&rsquo;s elevation and from similar trails: it reads &ldquo;About&rdquo; with a note, is marked in lists and is left out of the data search engines read. People do walk many trails outside their estimated months, and an estimate is replaced when a page that states a season is found.</p>
{pagekit.table(["Where a trail's season comes from", "Trails"], rows, caption="Where the seasons come from", numeric=(1,))}"""]
if blind:
by = blind["by_confidence"]
conf = ", ".join(f"{name} {by[name]['matched']} of {by[name]['tested']} ({_pct(by[name]['share'])})"
for name in ("high", "medium", "low") if by[name]["tested"])
out.append(f"""<p>How the estimates were tested. On {esc(blind["date"])} the method was run blind on {blind["tested"]} trails whose seasons a page does state, with those seasons hidden. It matched {blind["matched"]} of them ({_pct(blind["share"])}) within one month at each end of the season the page states. By the confidence it gave each estimate: {esc(conf)}. This measures how the method did where the answer is known, not a promise for any one trail.</p>""")
return "\n ".join(out)
def method_page(records, site, repo_root):
"""(title, description, body) for /method/."""
meaning = schema_meanings(repo_root)
@@ -120,12 +146,15 @@ def method_page(records, site, repo_root):
(a, b), (c, d_) = facets.PACE_KM, facets.PACE_KM_CROSS
coverage = []
for label, fn in (("A usual time stated by a source", lambda r: not facets.time_days(r)[2]),
("A season", lambda r: bool(facets.months(r))), ("A high point", lambda r: bool(hike.table(r).get("high_point_m"))),
("A season a page states", lambda r: facets.season_kind(r) == "stated"),
("A season set from pages that differ", lambda r: facets.season_kind(r) == "judged"),
("A season estimated from climate", lambda r: facets.season_kind(r) == "estimated"), ("A high point", lambda r: bool(hike.table(r).get("high_point_m"))),
("Terrain", lambda r: bool(facets.terrain(r))), ("What the walking is", lambda r: bool(facets.walking(r))),
("A computed climb that covers the whole trail", lambda r: facets.row_climb_m(r) is not None),
("A track included here", common.has_line)):
have = sum(1 for r in records if fn(r))
coverage.append([label, str(have), str(n - have)])
season_html = season_section(records, datafiles.blind_test(repo_root))
rows = [[label, str(k), f"{k / len(ver) * 100:.0f}%" if ver else ""] for label, k in bands]
body = (pagekit.head("How the figures are measured", (
f"What each figure on this site means, and how far to trust it. {len(ver)} of the {n} trails have a track whose "
@@ -145,7 +174,8 @@ def method_page(records, site, repo_root):
<p>Climb is the total ascent along the track.{(" It uses " + esc(model) + ", sampled every " + words.fmt_int(spacing) + " metres, with " + esc(smoothing[:1].lower() + smoothing[1:]) + ".") if model and spacing else ""} {esc(limits_text)}</p>
<p>A climb is ranked or shown in a list only where its track covers the whole trail: a track that covers part of the trail, or more than the trail, would mislead.</p>
<h2>Season and high point</h2>
<p>{esc(_sentence(meaning.get("season", "")))} {esc(_sentence(meaning.get("high_point_m", "").split(" May be given")[0]))} Not every record has them, so a page built from them says how many records it covers.</p>
<p>{esc(_sentence(meaning.get("season", "")))} {esc(_sentence(meaning.get("high_point_m", "").split(" May be given")[0]))} </p>
{season_html}
<h2>What the records have</h2>
{pagekit.table(["Figure", "Records with it", "Records without"], coverage, caption="How many records carry each figure", numeric=(1, 2))}
<p>Every fact is read on a page that the record names. See the <a href="/sources/">sources</a>, the <a href="/data/schema/">record schema</a> and <a href="{GLOSSARY}">the glossary</a>.</p>
+1 -1
View File
@@ -390,7 +390,7 @@ def list_page(lst, recs, total, site, *, records=None, before="", after="", lead
</div></header>
</div></div>
<div class="container section place">
{home.browse_view(home.listing(recs, default_sort=lst.sort, top=2, lead=lead),
{home.browse_view(home.listing(recs, default_sort=lst.sort, top=2, lead=lead, season=lst.group == "month"),
home.overview_map(recs, f"Map of the trails in the list {lst.title}"),
about=f"{about}{before}{f'<p>{esc(note.strip())}</p>' if note else ''}<p class=\"finder__foot\">{rule}</p>",
about_title="About this list")}
+2 -1
View File
@@ -284,7 +284,8 @@ def _properties(rec):
props.append(_pv("Shape", facets.SHAPES[shape]))
props.append(_pv("Start", h.get("start", "")) if h.get("start") else None)
props.append(_pv("End", h.get("end", "")) if h.get("end") else None)
props.append(_pv("Usual season", h["season"]) if h.get("season") else None)
# Only a season a page states: an estimate is not a fact about the trail to hand to a search engine.
props.append(_pv("Usual season", h["season"]) if h.get("season") and not facets.season_estimated(rec) else None)
if common.is_route(rec):
route = rec.get("route", {})
props.append(_pv("Route author", route["creator"]) if route.get("creator") else None)
+3 -1
View File
@@ -45,14 +45,16 @@ def time_cell(rec):
def season_cell(rec):
return facets.season_text(rec) or "Not on file"
return facets.season_text(rec)
def figures_note(recs):
"""What the times and climbs of these trails mean, with the caveats the records state."""
est = sum(1 for r in recs if facets.time_days(r)[2])
unstated = sum(1 for r in recs if facets.season_estimated(r))
parts = [f"Times that start with “About” are estimated from the length ({est} of these). "
"Otherwise a source states the time.",
f"Seasons that start with “About” are estimated from climate ({unstated} of these)." if unstated else "",
climb_caveat(recs)]
return " ".join(p for p in parts if p)
+3 -1
View File
@@ -148,7 +148,9 @@ def detail(rec):
out.append(f"Its high point is {esc(name + ', ') if name else ''}{words.elevation(m)}.")
season = facets.season_text(rec)
if season:
out.append(f"Season: {esc(season)}.")
how = (", judged from pages that differ" if facets.season_pages_differ(rec)
else ", estimated from climate" if facets.season_estimated(rec) else "")
out.append(f"Season: {esc(season)}{how}.")
rest = _rest_of_summary(rec)
if rest:
out.append(f'<span class="record-text">{esc(rest)}</span>')
+17 -5
View File
@@ -282,6 +282,7 @@ def _name_html(rec):
MAX_BRIEF = 4 # sentences in the "In brief" paragraph
PINNED = -1 # the priority of a sentence that is kept besides those (an estimated season)
MONTH_WORDS = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
SEASON_WORDS = ("spring", "summer", "fall", "autumn", "winter", "late", "early", "mid", "from", "about")
SENTENCE_VERBS = re.compile(r"\b(is|are|can|start|starts|hikes?|hiked|travelled|traveled|bring|brings|closed|best)\b", re.I)
@@ -292,6 +293,13 @@ def season_sentence(rec):
seasons, ("sentence", "Northbound hikes start late February to early April") for one the record
already words as a sentence, or None when the record has none or it is too long to say briefly.
The caller adds the full stop. Only the record's own words are used."""
if facets.season_estimated(rec):
# Never worded as a fact, and never joined to the GPX clause with "and".
phrase = facets.season_phrase(rec).rstrip(". ")
phrase = phrase.lower() if phrase.lower() == "all year" else phrase
if facets.season_pages_differ(rec):
return ("estimate", f"The pages differ on the season; it is judged to be about {phrase}")
return ("estimate", f"No source gives a season; the climate suggests about {phrase}")
text = facets.season_text(rec).strip().rstrip(". ")
if not text:
return None
@@ -431,19 +439,23 @@ def brief_sentences(rec):
# When to walk it and whether this site has a GPX: one sentence where the season is a plain range.
clause = gpx_clause(rec) or ("this site has no GPX for it" + _see_clause(rec))
season = season_sentence(rec)
if season and not re.search(r"[,;]", season[1]):
if season and season[0] != "estimate" and not re.search(r"[,;]", season[1]):
# "The usual season is May to July, and this page has a GPX of the track to download."
items.append((3, 5, f"{esc(season[1])}, and {esc(clause)}."))
else:
if season:
items.append((3.5, 5, esc(season[1]) + "."))
# An estimated season is always said, so it is never left for a reader to take as a fact
# by omission: it is the one sentence that may stand beyond MAX_BRIEF.
items.append((PINNED if season[0] == "estimate" else 3.5, 5, esc(season[1]) + "."))
items.append((3, 6, esc(clause[:1].upper() + clause[1:]) + "."))
permit = permit_sentence(rec)
if permit:
items.append((6, 7, esc(permit)))
# At most MAX_BRIEF sentences: the lowest priorities are kept, shown in reading order.
kept = sorted(sorted(items, key=lambda i: (i[0], i[1]))[:MAX_BRIEF], key=lambda i: i[1])
pinned = [i for i in items if i[0] == PINNED]
rest = sorted((i for i in items if i[0] != PINNED), key=lambda i: (i[0], i[1]))[:MAX_BRIEF]
kept = sorted(rest + pinned, key=lambda i: i[1])
return [text for _, _, text in kept]
@@ -624,7 +636,7 @@ def glance(rec, records=None):
rows.append(glance_row(facets.TIME, facets.time_text(rec), time_note(rec, records)))
season = facets.season_text(rec)
if season:
rows.append(glance_row(facets.SEASON, season))
rows.append(glance_row(facets.SEASON, season, facets.season_note(rec)))
if facets.walking(rec):
walking = facets.WALKING_VALUES[facets.walking(rec)]
if facets.walking(rec) in facets.CROSS_COUNTRY:
@@ -692,7 +704,7 @@ def glance(rec, records=None):
unfinished = ""
if h.get("unfinished"):
unfinished = f'<p class="glance__warn"><strong>Not finished.</strong> {common.rich(common.sentence(h["unfinished"]))}</p>'
missing = [name for name, have in ((facets.SEASON, season), (facets.TERRAIN, terrain),
missing = [name for name, have in ((facets.TERRAIN, terrain),
(facets.WALKING, facets.walking(rec)),
(PERMITS, h.get("permit"))) if not have]
pending = ""