Valley map: show the paths of all riders (per source, plus deaths); the six traced silhouettes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f3bbde24b7
commit
a9836c3191
@@ -88,3 +88,19 @@ presets:
|
||||
route_thresholds: [5, 10, 20, 30]
|
||||
|
||||
rare_goals: [Blue, Black, Blue or Black]
|
||||
|
||||
# "Show the paths of all riders" on the valley map (site/atlas/explorer.js): one layer per source that records a
|
||||
# route, and two layers of deaths. Unlike everything above, the layers use every source of runs_clean.csv. A layer
|
||||
# takes runs by source (and, for the spreadsheet, by its row label `entry`); the death layers take every death from
|
||||
# the route-recording sources: "deliberate" = burned at an encounter the rider did not genuinely attempt (the route
|
||||
# model's rule), "failed" = every other death. Discord has no runs yet: its layer is ready for when it is imported.
|
||||
path_layers:
|
||||
- { key: form, label: "Google Sheet: form posts", sources: [reddit spreadsheet], entry: [Form] }
|
||||
- { key: bulk, label: "Google Sheet: bulk logs", sources: [reddit spreadsheet], entry_not: [Form] }
|
||||
- { key: reported, label: "Reported on the Atlas", sources: [reported] }
|
||||
- { key: bot, label: "DragonKind bot", sources: [bot] }
|
||||
- { key: discord, label: "Discord", sources: [discord] }
|
||||
- { key: died_deliberate, label: "Deaths: chose to die", death: deliberate }
|
||||
- { key: died_failed, label: "Deaths: failed runs", death: failed }
|
||||
# sources that record which dragon bonded but not the route: counted on the map, not drawn
|
||||
path_unrouted: [reddit thread, register]
|
||||
|
||||
@@ -399,7 +399,7 @@ def place_path(r):
|
||||
s.append("bully")
|
||||
if "res:" + r["resolution"] in L:
|
||||
s.append("res:" + r["resolution"])
|
||||
if r["resolution"].startswith("DIED"):
|
||||
if (r.get("resolution") or "").startswith("DIED"):
|
||||
return s
|
||||
if r.get("post_path") in ("Forest", "West", "East"):
|
||||
s.append("fork:" + r["post_path"])
|
||||
@@ -452,17 +452,54 @@ def valley(runs):
|
||||
return {"counts": counts, "edges": [[*k.split(">"), n] for k, n in sorted(edges.items(), key=lambda kv: -kv[1])]}
|
||||
|
||||
|
||||
DEATHS = ("Incinerated", "Died before the hour")
|
||||
|
||||
|
||||
def deliberate(r):
|
||||
"""A deliberate death: burned at a bonding encounter the rider did not genuinely attempt (chasing another colour,
|
||||
choosing to die and try again). The route model's own rule."""
|
||||
if r["outcome"] != "Incinerated":
|
||||
return False
|
||||
try:
|
||||
v = model.prepare_run(r)
|
||||
return bool(v.get("encCtx")) and not model.genuine_attempt(r, v["encCtx"])
|
||||
except (KeyError, TypeError, ValueError): # a source coded from other questions (e.g. the bot): not known
|
||||
return False
|
||||
|
||||
|
||||
def path_layers(runs):
|
||||
"""'Show the paths of all riders' on the valley map: for every layer in measures.yaml path_layers, how many runs
|
||||
went from each place to the next (like valley()), plus where the death layers' runs ended. Every source is used
|
||||
here, not only the statistics' sources. Sources that record no route are counted only (path_unrouted)."""
|
||||
cfg = M["path_layers"]
|
||||
routed = sorted({s for layer in cfg for s in layer.get("sources", [])})
|
||||
out = []
|
||||
for layer in cfg:
|
||||
if "death" in layer:
|
||||
sel = [r for r in runs if r["source"] in routed and r["outcome"] in DEATHS
|
||||
and deliberate(r) == (layer["death"] == "deliberate")]
|
||||
else:
|
||||
sel = [r for r in runs if r["source"] in layer["sources"]
|
||||
and (not layer.get("entry") or r.get("entry") in layer["entry"])
|
||||
and (not layer.get("entry_not") or r.get("entry") not in layer["entry_not"])]
|
||||
v = valley(sel)
|
||||
item = {"key": layer["key"], "label": layer["label"], "runs": len(sel), "edges": v["edges"]}
|
||||
if "death" in layer:
|
||||
ends = {}
|
||||
for r in sel:
|
||||
seq = place_path(r)
|
||||
if seq:
|
||||
ends[seq[-1]] = ends.get(seq[-1], 0) + 1
|
||||
item["ends"] = dict(sorted(ends.items(), key=lambda kv: -kv[1]))
|
||||
out.append(item)
|
||||
unrouted = {s: sum(1 for r in runs if r["source"] == s) for s in M.get("path_unrouted", [])}
|
||||
return {"layers": out, "unrouted": unrouted}
|
||||
|
||||
|
||||
def overview(runs):
|
||||
"""The Odds' summary cards: cadets who went in and either bonded or died. Deliberate deaths (burned at an
|
||||
encounter the rider did not genuinely attempt) and runs with no recorded outcome are left out."""
|
||||
ended = [r for r in runs if r["outcome"] in ("Bonded", "Incinerated", "Died before the hour")]
|
||||
|
||||
def deliberate(r):
|
||||
if r["outcome"] != "Incinerated":
|
||||
return False
|
||||
v = model.prepare_run(r)
|
||||
return bool(v.get("encCtx")) and not model.genuine_attempt(r, v["encCtx"])
|
||||
|
||||
cadets = [r for r in ended if not deliberate(r)]
|
||||
bonded = sum(1 for r in cadets if r["outcome"] == "Bonded")
|
||||
return {"cadets": len(cadets), "bonded": bonded, "dead": len(cadets) - bonded, "deliberate": len(ended) - len(cadets),
|
||||
@@ -483,7 +520,7 @@ def clean(o):
|
||||
return o
|
||||
|
||||
|
||||
def build(runs, rows, exported=None):
|
||||
def build(runs, rows, exported=None, every_run=None):
|
||||
global PLACES
|
||||
PLACES = place_ids()
|
||||
th = M["route_thresholds"]
|
||||
@@ -506,6 +543,8 @@ def build(runs, rows, exported=None):
|
||||
"routes": {t: rank_routes(sub, t, th) for t in TARGETS},
|
||||
"map": route_map(sub), "valley": valley(sub), "overview": overview(sub),
|
||||
}
|
||||
if every_run is not None:
|
||||
out["paths"] = path_layers(every_run)
|
||||
return clean(out)
|
||||
|
||||
|
||||
@@ -515,7 +554,7 @@ def main(argv=None):
|
||||
ap.add_argument("--out", default=str(ROOT / "data/public/stats.json"))
|
||||
a = ap.parse_args(argv)
|
||||
runs = runs_io.read(a.data, sources=M["sources"])
|
||||
out = build(runs, len(runs), exported())
|
||||
out = build(runs, len(runs), exported(), every_run=runs_io.read(a.data))
|
||||
Path(a.out).write_text(json.dumps(out, separators=(",", ":"), ensure_ascii=False), encoding="utf-8")
|
||||
print(f"{a.out}: {len(runs)} runs, {len(out['presets'])} presets, {Path(a.out).stat().st_size / 1e6:.1f} MB")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user