Trophy case: a board for the longest leg

Six disciplines measured the whole walk — how far it travelled, how far
out it reached, how many nodes it touched. None of them measured a single
link, and that is its own game: a node reached over a chain of short hops
scores far, not long, while one huge jump between two relays scores
nothing today.

Longest leg (🏹) takes the greatest distance the walk crossed in one hop,
both ends positioned. The measurement rides the loop that already sums
the circuit, so it costs nothing extra, and it carries the ids of the two
ends it spanned — our own end left null — so the record card can name the
link on THE path widget, ★ at home like every other route we draw. A
record set before the discipline existed simply has no leg lane.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-11 01:29:41 -04:00
1 parent ce86e86693
commit 80f18e235a
6 files changed
+142 -15

No files matched your search

+40 -5
View File
@@ -9,8 +9,9 @@ hop and the final hop's transmission lands back on us. Every trace is one:
→ us``, which starts and ends at us just the same.
So any successful trace can be scored, and the trophy case keeps the record-setters in
six disciplines — the longest distance, the farthest node, the most nodes (with and
without revisits), the weakest surviving link, and the widest enclosed loop. This module
seven disciplines — the longest distance, the farthest node, the longest single link,
the most nodes (with and without revisits), the weakest surviving link, and the widest
enclosed loop. This module
is pure measurement: :func:`walk_from_trace` turns a reply into a spec, a canonical
route, and its :class:`WalkStats`; :func:`walk_scores` scores those stats against every
discipline at once (a walk found while tracing one thing still counts everywhere it
@@ -95,6 +96,13 @@ class WalkStats:
km_complete: Whether every segment was positioned (``km_travelled`` exact).
far_km: The furthest hop's distance from us (km), when both ends are
positioned; ``None`` without our own or any hop's position.
leg_km: The longest single link of the circuit (km) — one hop's transmission,
end to end — when both of its ends are positioned; ``None`` when no
segment had both. A different game from ``far_km``: a distant node reached
over a chain of short hops scores far, not long.
leg_link: The ids of that link's two ends, in walk order, with ``None`` for our
own node (a link touching us is the first or last segment). ``None``
alongside a ``None`` ``leg_km``.
area_km2: The unsigned area enclosed by the circuit's positioned points in
walk order (km², shoelace over a local plane). ``None`` below three
positioned points; self-crossing walks score their net algebraic area.
@@ -110,6 +118,8 @@ class WalkStats:
km_complete: bool
far_km: Optional[float]
area_km2: Optional[float]
leg_km: Optional[float] = None
leg_link: Optional[tuple[Optional[str], Optional[str]]] = None
def as_dict(self) -> dict:
"""The stats as a JSON-serializable dict (the ``stats_json`` column)."""
@@ -123,6 +133,10 @@ class WalkStats:
"km_complete": self.km_complete,
"far_km": round(self.far_km, 3) if self.far_km is not None else None,
"area_km2": round(self.area_km2, 3) if self.area_km2 is not None else None,
"leg_km": round(self.leg_km, 3) if self.leg_km is not None else None,
# A list, not a tuple, because this round-trips through JSON; our own end
# stays null so the reader draws it as the app-wide ★ rather than a name.
"leg_link": list(self.leg_link) if self.leg_link is not None else None,
}
@@ -172,6 +186,10 @@ def _score_far_point(stats: WalkStats) -> Optional[float]:
return stats.far_km
def _score_long_leg(stats: WalkStats) -> Optional[float]:
return stats.leg_km if stats.leg_km else None
def _score_grand_tour(stats: WalkStats) -> Optional[float]:
return float(stats.distinct_nodes) if stats.distinct_nodes else None
@@ -192,7 +210,7 @@ def _score_big_loop(stats: WalkStats) -> Optional[float]:
return stats.area_km2
#: The six disciplines. Ids are stable database keys and must never change; titles and
#: The seven disciplines. Ids are stable database keys and must never change; titles and
#: descriptions are display-only and kept plain and descriptive.
CATEGORIES: tuple[Category, ...] = (
Category(
@@ -205,6 +223,11 @@ CATEGORIES: tuple[Category, ...] = (
description="reach the node furthest from here",
score=_score_far_point, needs_positions=True,
),
Category(
id="long_leg", title="Longest leg", icon="🏹", unit="km",
description="cross the greatest distance in a single hop",
score=_score_long_leg, needs_positions=True,
),
Category(
id="grand_tour", title="Most nodes", icon="🧳", unit="nodes",
description="visit the most nodes, passing through some twice is fine",
@@ -274,13 +297,23 @@ def compute_walk_stats(
points.extend(positions.get(node) for node in ids)
points.append(self_pos)
# The circuit's segments carry their endpoints alongside their positions, so the
# longest one can name the link it was: ``None`` at either end is our own node,
# which the walk leaves from and comes home to.
ends: list[Optional[str]] = [None, *ids, None]
km = 0.0
complete = True
for a, b in zip(points, points[1:]):
leg_km: Optional[float] = None
leg_link: Optional[tuple[Optional[str], Optional[str]]] = None
for i, (a, b) in enumerate(zip(points, points[1:])):
if a is None or b is None:
complete = False
continue
km += haversine_km(a[0], a[1], b[0], b[1])
span = haversine_km(a[0], a[1], b[0], b[1])
km += span
if leg_km is None or span > leg_km:
leg_km, leg_link = span, (ends[i], ends[i + 1])
far: Optional[float] = None
if self_pos is not None:
@@ -313,6 +346,8 @@ def compute_walk_stats(
km_complete=complete,
far_km=far,
area_km2=area,
leg_km=leg_km,
leg_link=leg_link,
)
+3 -3
View File
@@ -76,7 +76,7 @@ class TrophyCaseTool(Tool):
Args:
ctx: Shared application context.
category: Only this category id, or ``None`` for all six.
category: Only this category id, or ``None`` for every discipline.
width: Only this hash width, or ``None`` for every width.
Returns:
@@ -136,8 +136,8 @@ class TrophyCaseTool(Tool):
None,
"--category",
"-c",
help="Only this discipline (long_haul, far_point, grand_tour, "
"clean_trail, thin_thread, big_loop)",
help="Only this discipline (long_haul, far_point, long_leg, "
"grand_tour, clean_trail, thin_thread, big_loop)",
),
width: Optional[int] = typer.Option(
None, "--width", "-w", help="Only records at this hash width (1, 2, or 4)"
+28 -6
View File
@@ -2,10 +2,10 @@
A read-only board over the ``discovered_paths`` table (:meth:`Repository.discoveries`),
opened from the main menu. Every successful trace — a *Trace target* boomerang or a
*Trace path* walk — is scored against all six disciplines and offered to their boards
*Trace path* walk — is scored against every discipline and offered to their boards
(see :mod:`~meshterm.services.records`); this screen is where the survivors live.
* the browser groups the six disciplines, each under its heading with a one-line
* the browser groups the disciplines, each under its heading with a one-line
description of the game (word-wrapped when it must) — the two pin overhead together as
one block while that board scrolls, so a row deep in a discipline still says which game
it is winning and what that game scores — then the discipline's records ranked
@@ -14,8 +14,9 @@ opened from the main menu. Every successful trace — a *Trace target* boomerang
hops). A discipline holding records at more than one hash width tags each row with its
width, since the widths are genuinely different games;
* opening a record floats :class:`RecordDialog` — every stat the walk was measured by
(the far point named with the node it reached), the walk drawn two ways: on THE route
graph (the Message paths dialog's shape, us at both ends, drawn no taller than one lane
(the far point named with the node it reached, the longest leg with the link it spanned),
the walk drawn two ways: on THE route graph (the Message paths dialog's shape, us at both
ends, drawn no taller than one lane
needs) and, beside the stats, as the enclosed area it swept on a braille mini-map (us and
every positioned hop, coloured node pins, no labels); then the full route — the path
widget again, unlabelled across the card's whole width, wrapping at hop boundaries — and
@@ -146,7 +147,8 @@ class RecordDialog(Screen):
"""One record's full story, floating over the screen beneath.
Every stat the walk was measured by — a reliability read from the far node's trace
history, the far point named with the node it reached — with the walk's enclosed area
history, the far point named with the node it reached, the longest leg drawn as the
link it spanned (our own end on the app-wide ★) — with the walk's enclosed area
drawn beside them on a braille mini-map (us at the origin, every positioned hop pinned
in its own name hue, no labels) when the terminal has the room; below, the walk on THE
route graph (us at both ends, relays wearing their map marker over a node-type key),
@@ -310,7 +312,9 @@ class RecordDialog(Screen):
Which lanes appear varies by discipline — a walk with no positions has no distance,
far point, or area — so callers size to the returned list rather than a fixed count.
The far-point lane carries the reached node's name when one is known.
The far-point lane carries the reached node's name when one is known, and the
longest-leg lane the link it spanned; a record set before a stat existed simply has
no lane for it.
"""
record, category = self._record, self._category
stats = record.stats
@@ -347,6 +351,24 @@ class RecordDialog(Screen):
value.append(" ")
value.append(self._far_label, style=name_style(self._far_label, self._far_id))
lanes.append(self._lane("far point", value))
leg = stats.get("leg_km")
if leg is not None:
value = Text(f"{leg:.1f} km")
link = stats.get("leg_link")
if link and len(link) == 2:
# The link itself on THE path widget, both ends named the way the walk
# below names them — our own end on the app-wide ★, since a leg that
# starts or ends at home is the commonest kind there is.
value.append(" ")
value.append_text(path_line(
list(link),
self._resolve,
self_name=self._device_label,
bare_self=True,
dim_self=False,
show_hash=False,
).text())
lanes.append(self._lane("longest leg", value))
area = stats.get("area_km2")
if area is not None:
lanes.append(self._lane("area", Text(f"{area:.1f} km²")))
+1
View File
@@ -560,6 +560,7 @@ _GLYPH_MAP: dict[str, str] = {
"🕸": "∟", # mesh walk (route family)
"🚨": "⚠", # watchtower alert
"🛣": "∟", # longest-haul route (route family)
"🏹": "►", # longest leg — the arrow in flight (▶ is the run *action*, not this)
"🧳": "→", # trip/journey
"🔆": "°", # brightest sighting
"📶": "≥", # TX power sweep — the power ramp
+39 -1
View File
@@ -65,6 +65,42 @@ def test_walk_stats_unpositioned_segments_score_a_lower_bound() -> None:
assert 1.0 < stats.km_travelled < 1.3 # only the positioned us→Hub leg counts
def test_longest_leg_measures_one_link_and_names_its_ends() -> None:
"""The longest single segment of the circuit, with the two nodes it spanned.
Hub sits ~1.11 km north and Leaf ~1.11 km south, so the Hub→Leaf crossing (~2.2 km)
beats both of the legs touching us — a link between two hops, neither of them ours.
"""
stats = compute_walk_stats(
(HUB_ID, LEAF_ID), _result(8.0, 6.0, 7.0).hops, rtt_ms=None,
positions=POSITIONS, self_pos=SELF_POS,
)
assert stats.leg_km is not None and 2.0 < stats.leg_km < 2.5
assert stats.leg_link == (HUB_ID, LEAF_ID)
# Far point measures reach, not span: the furthest node is only half as far away.
assert stats.far_km is not None and stats.far_km < stats.leg_km
assert stats.as_dict()["leg_link"] == [HUB_ID, LEAF_ID] # JSON-shaped for storage
def test_longest_leg_names_our_own_end_as_none() -> None:
"""A leg that leaves or comes home marks our end ``None`` — the ★ the UI draws."""
stats = compute_walk_stats(
(HUB_ID,), _result(8.0, 7.0).hops, rtt_ms=None,
positions=POSITIONS, self_pos=SELF_POS,
)
assert stats.leg_link == (None, HUB_ID) # us → Hub, the outbound half
def test_longest_leg_needs_two_positioned_ends() -> None:
"""No segment with both ends placed scores nothing rather than a bogus zero."""
stats = compute_walk_stats(
(HUB_ID,), _result(8.0, 7.0).hops, rtt_ms=None,
positions=POSITIONS, self_pos=None,
)
assert stats.leg_km is None and stats.leg_link is None
assert "long_leg" not in walk_scores(stats)
def test_cross_category_scores_score_every_game_at_once() -> None:
"""One walk competes everywhere it can — the every-board-at-once rule."""
stats = compute_walk_stats(
@@ -77,6 +113,7 @@ def test_cross_category_scores_score_every_game_at_once() -> None:
assert scores["thin_thread"] == -11.0 # the weakest surviving link
assert scores["long_haul"] > 3.0
assert scores["far_point"] > 1.0
assert scores["long_leg"] > 0.5
def test_category_titles_are_plain_and_ids_are_stable() -> None:
@@ -86,7 +123,8 @@ def test_category_titles_are_plain_and_ids_are_stable() -> None:
assert CATEGORY_BY_ID["long_haul"].title == "Longest distance"
# Every id still resolves — the persisted keys never changed under the rename.
assert set(CATEGORY_BY_ID) == {
"long_haul", "far_point", "grand_tour", "clean_trail", "thin_thread", "big_loop"
"long_haul", "far_point", "long_leg", "grand_tour", "clean_trail", "thin_thread",
"big_loop",
}
+31
View File
@@ -194,6 +194,37 @@ def test_record_dialog_names_the_far_point() -> None:
assert re.search(r"far point\s+1\.5 km\s+Far", body)
def test_record_dialog_names_the_link_the_longest_leg_spanned() -> None:
"""The leg lane carries its distance and the two nodes it crossed between."""
record = _record(
category="long_leg", score=12.4,
stats={"hop_count": 2, "distinct_nodes": 2, "km_travelled": 21.0,
"km_complete": True, "leg_km": 12.4, "leg_link": [HUB_ID, FAR_ID]},
)
body = _plain(_dialog(record).render_body(60))
assert re.search(r"longest leg\s+12\.4 km\s+YUL-Cartierville → Far", body)
def test_record_dialog_stars_our_own_end_of_the_longest_leg() -> None:
"""A leg that leaves home takes the app-wide ★ at our end, never our name."""
record = _record(
category="long_leg", score=12.4,
stats={"hop_count": 1, "distinct_nodes": 1, "leg_km": 12.4,
"leg_link": [None, HUB_ID]},
)
lane = next(
line for line in _plain(_dialog(record).render_body(60)).splitlines()
if "longest leg" in line
)
assert "★ → YUL-Cartierville" in lane and "Homestead" not in lane
def test_record_dialog_skips_the_leg_lane_for_a_record_stored_without_one() -> None:
"""Records set before the discipline existed simply have no leg to show."""
body = _plain(_dialog(_record()).render_body(60))
assert "longest leg" not in body
def test_record_dialog_shows_reliability_when_the_far_node_has_history() -> None:
"""The reliability lane reads the % and its sample count; absent without history."""
with_rate = _plain(_dialog(_record(), reliability=(0.875, 7, 8)).render_body(60))