Site: show precomputed statistics; drop the upload and the click-to-select route map (#12)
Step 4a of the Python-first core. - analysis/stats/measures.yaml (declarative): outcomes and denominators, route targets and comparison groups, encounter contexts, the route map's stages, six filter presets and the route thresholds (5, 10, 20, 30). - analysis/stats/site_stats.py computes every number the page shows, for every preset, and writes data/public/stats.json: factor tables, models, chance events, encounters, the route map for every outcome, route rankings with q-values at every threshold, the valley map's place and step counts, and The Odds' summary cards. - The page now only displays: app.js, ui.js and explorer.js read stats.json; engine.js is no longer loaded. The three filter controls become one "Runs" menu; minimum runs become fixed thresholds. Removed: "Load a newer route export", click-to-select and "Follow" on the Deep Dive route map, and the unused old valley renderer. The coded runs are a CSV download. - tests/parity/compare_stats.py: every number matches what engine.js computed, for all six presets (factor tables, models, encounters, route rankings at every threshold, route map). Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
963b08c522
commit
d04b88e7b4
+5
-212
@@ -1,10 +1,8 @@
|
||||
/* valley.js — the watercolour valley map.
|
||||
* Every place on the map is a step in a run. Trails are drawn from the coded runs (engine.js):
|
||||
* thickness = riders who walked it, colour = share of those riders who reached the chosen outcome.
|
||||
* Dashed trails are routes the community has described but the form does not record. */
|
||||
* Places, the painted ground, and their names; explorer.js draws routes and traffic on top. How many riders
|
||||
* reached each place and walked each step is counted in Python (analysis/stats/site_stats.py). */
|
||||
(function () {
|
||||
"use strict";
|
||||
const E = window.ThreshEngine;
|
||||
const $ = (q, el = document) => el.querySelector(q);
|
||||
const $$ = (q, el = document) => [...el.querySelectorAll(q)];
|
||||
const NS = "http://www.w3.org/2000/svg";
|
||||
@@ -76,54 +74,8 @@
|
||||
"meadow:Blue": { x: 836, y: 100, name: "Meadow Blue", colour: "Blue", kind: "dragon", lab: "right", desc: "The rare meadow Blue. Most riders who approach it are burned, even with the community's best answers." },
|
||||
};
|
||||
// routes described by the community that the form does not record
|
||||
const KNOWN = [
|
||||
["treeRed", "greens", "Wait and pursue the Green"],
|
||||
["redwood", "greens", "Retreat, then find the Green"],
|
||||
["redwood", "valley", "Retreat toward the valley"],
|
||||
["comp:1 Squadmate", "comp:Alone", "Leave your squadmate"],
|
||||
["comp:2 Squadmates", "comp:Alone", "Leave your squadmates"],
|
||||
];
|
||||
const SIGHT_NODES = new Set(Object.keys(L).filter((k) => k.startsWith("see:")));
|
||||
|
||||
function path(r) {
|
||||
const s = [];
|
||||
if (L["comp:" + r.company]) s.push("comp:" + r.company);
|
||||
if (!["East", "West", "Center"].includes(r.direction)) return s;
|
||||
s.push("dir:" + r.direction);
|
||||
const sight = `see:${r.direction}:${r.first_sighting}`;
|
||||
if (SIGHT_NODES.has(sight)) s.push(sight);
|
||||
if (r.scream === "DIED at first sighting" || r.scream === "Unknown") return s;
|
||||
s.push("scream");
|
||||
if (r.scream === "Investigate & help") {
|
||||
s.push("bully");
|
||||
if (L["res:" + r.resolution]) s.push("res:" + r.resolution);
|
||||
if (r.resolution.startsWith("DIED")) return s;
|
||||
if (["Forest", "West", "East"].includes(r.post_path)) s.push("fork:" + r.post_path);
|
||||
} else if (r.scream === "Ignore the scream") {
|
||||
s.push("wounded");
|
||||
if (L["res:" + r.resolution]) s.push("res:" + r.resolution);
|
||||
} else if (r.scream === "Investigate & leave") s.push("away");
|
||||
if (r.hour !== "Tree" && r.hour !== "Valley") return s;
|
||||
s.push("hour");
|
||||
if (r.hour === "Tree") {
|
||||
s.push("tree");
|
||||
if (r.branch === "Descend quickly: Red") s.push("treeRed");
|
||||
else if (r.branch === "Descend quickly: let the Red pass") { s.push("treeRed"); s.push("greens"); }
|
||||
else if (r.branch === "Descend slowly: two Greens") s.push("greens");
|
||||
else if (r.branch === "Shadow (rare)") { s.push("stream"); if (r.enc_Blue || r.enc_Black) s.push("redwood"); if (r.enc_Black) s.push("black"); }
|
||||
} else {
|
||||
s.push("valley");
|
||||
if (r.branch === "Valley Red") s.push("valleyRed");
|
||||
else if (r.branch === "Passed the Red: meadow") {
|
||||
s.push("meadow");
|
||||
const tried = r.enc_Blue ? "Blue" : (r.outcome_color === "Orange" || r.outcome_color === "Brown") ? r.outcome_color : r.enc_Orange ? "Orange" : r.enc_Brown ? "Brown" : null;
|
||||
if (tried) s.push("meadow:" + tried);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ painting
|
||||
// the routes runs take through these places are counted in Python (analysis/stats/site_stats.py, place_path)
|
||||
|
||||
function defs(svg) {
|
||||
const d = el("defs", {}, svg);
|
||||
d.innerHTML = `
|
||||
@@ -217,175 +169,16 @@
|
||||
const WING = "M50 30 L18 6 L27 21 L3 16 L25 32 Z M50 30 L82 6 L73 21 L97 16 L75 32 Z M37 30 Q50 23 63 30 Q50 37 37 30 Z M63 30 L76 26 L80 28 L73 31 Z M37 30 Q24 37 10 34 Q22 33 36 31 Z";
|
||||
|
||||
// ------------------------------------------------------------ rendering
|
||||
let target = "bond_Blue", selected = "meadow:Blue", lastState = null, tipEl = null;
|
||||
const TGT = ["bond_Blue", "bond_Black", "see_Blue", "see_shadow", "bond_Red", "bond_Green", "bond_Orange", "bond_Brown", "bond_any"];
|
||||
function tip(e, html) {
|
||||
tipEl = tipEl || $("#tip");
|
||||
tipEl.innerHTML = html; tipEl.hidden = false;
|
||||
const r = tipEl.getBoundingClientRect();
|
||||
tipEl.style.left = Math.min(window.innerWidth - r.width - 8, e.clientX + 14) + "px";
|
||||
tipEl.style.top = Math.min(window.innerHeight - r.height - 8, e.clientY + 14) + "px";
|
||||
}
|
||||
const hideTip = () => { if (tipEl) tipEl.hidden = true; };
|
||||
|
||||
function renderTargets() {
|
||||
$("#valley-targets").innerHTML = TGT.map((t) => {
|
||||
const c = E.TARGETS[t].color ? DV[E.TARGETS[t].color] : "--dr-any";
|
||||
return `<button type="button" class="tchip${t.startsWith("bond_B") ? " featured" : ""}" data-vt="${t}" aria-pressed="${t === target}" style="--c: var(${c})"><span class="sw"></span>${esc(E.TARGETS[t].label)}</button>`;
|
||||
}).join("");
|
||||
$$("#valley-targets .tchip").forEach((b) => b.addEventListener("click", () => { target = b.dataset.vt; render(lastState); }));
|
||||
}
|
||||
|
||||
function curve(A, B, bend) {
|
||||
const mx = (A.x + B.x) / 2, my = (A.y + B.y) / 2, dx = B.x - A.x, dy = B.y - A.y;
|
||||
return `M${A.x} ${A.y} Q${mx - dy * bend} ${my + dx * bend} ${B.x} ${B.y}`;
|
||||
}
|
||||
const isDeath = (r) => r.outcome === "Incinerated" || r.outcome === "Died before the hour";
|
||||
|
||||
function render(state) {
|
||||
if (!state || !state.res || !$("#valley")) return;
|
||||
lastState = state;
|
||||
renderTargets();
|
||||
const svg = $("#valley");
|
||||
svg.setAttribute("viewBox", "0 0 1000 790");
|
||||
svg.innerHTML = "";
|
||||
defs(svg); paint(svg);
|
||||
const T = E.TARGETS[target].fn;
|
||||
const nodes = new Map(), edges = new Map();
|
||||
state.runs.forEach((r) => {
|
||||
const seq = path(r), hit = T(r) ? 1 : 0;
|
||||
seq.forEach((id, i) => {
|
||||
const n = nodes.get(id) || { id, n: 0, k: 0, runs: [], endDeaths: 0 };
|
||||
n.n++; n.k += hit; n.runs.push(r);
|
||||
if (i === seq.length - 1 && isDeath(r)) n.endDeaths++;
|
||||
nodes.set(id, n);
|
||||
if (i) { const key = seq[i - 1] + ">" + id; const e = edges.get(key) || { a: seq[i - 1], b: id, n: 0, k: 0 }; e.n++; e.k += hit; edges.set(key, e); }
|
||||
});
|
||||
});
|
||||
const minN = state.minN || 10;
|
||||
const ES = [...edges.values()];
|
||||
const maxN = Math.max(1, ...ES.map((e) => e.n));
|
||||
const pmax = Math.max(0.005, ...ES.filter((e) => e.n >= minN).map((e) => e.k / e.n));
|
||||
const tcol = E.TARGETS[target].color ? INK[E.TARGETS[target].color] : "#8a3f6e";
|
||||
$(".valley-shell").style.setProperty("--vt", cssVar(E.TARGETS[target].color ? DV[E.TARGETS[target].color] : "--dr-any"));
|
||||
const colourOf = (e) => (e.n < minN ? "#a58a70" : mix(PAPER.trailLow, tcol, Math.pow(Math.min(1, e.k / e.n / pmax), 0.7)));
|
||||
|
||||
// known-but-untracked routes
|
||||
const gK = el("g", { "pointer-events": "stroke" }, svg);
|
||||
KNOWN.forEach(([a, b, label]) => {
|
||||
const A = L[a], B = L[b];
|
||||
const p = el("path", { d: curve(A, B, 0.18), fill: "none", stroke: PAPER.ink, "stroke-opacity": 0.45, "stroke-width": 2, "stroke-dasharray": "2 7", "stroke-linecap": "round" }, gK);
|
||||
p.addEventListener("mousemove", (ev) => tip(ev, `<div class="t">${esc(label)}</div>A route the community has described. The form doesn't record it, so it has no numbers.`));
|
||||
p.addEventListener("mouseleave", hideTip);
|
||||
});
|
||||
// trails
|
||||
const gT = el("g", { filter: "url(#vm-brush)" }, svg);
|
||||
ES.sort((a, b) => b.n - a.n).forEach((e) => {
|
||||
const A = L[e.a], B = L[e.b];
|
||||
if (!A || !B) return;
|
||||
const w = 2 + 24 * Math.sqrt(e.n / maxN);
|
||||
const d = curve(A, B, 0.08);
|
||||
el("path", { d, fill: "none", stroke: PAPER.halo, "stroke-width": w + 3, "stroke-opacity": 0.45, "stroke-linecap": "round" }, gT);
|
||||
const p = el("path", { d, fill: "none", stroke: colourOf(e), "stroke-width": w, "stroke-opacity": e.n >= minN ? 0.85 : 0.45, "stroke-linecap": "round" }, gT);
|
||||
p.addEventListener("mousemove", (ev) => tip(ev, `<div class="t">${esc(name(e.a))} → ${esc(name(e.b))}</div>${e.n.toLocaleString()} riders<br>${esc(E.TARGETS[target].label)}: <b>${pct(e.k / e.n, 1)}</b> (${e.k}/${e.n})${e.n < minN ? "<br><i>Too few riders to read</i>" : ""}`));
|
||||
p.addEventListener("mouseleave", hideTip);
|
||||
});
|
||||
// places
|
||||
const gN = el("g", {}, svg);
|
||||
const total = Math.max(1, ...[...nodes.values()].map((n) => n.n));
|
||||
Object.entries(L).forEach(([id, P]) => {
|
||||
const nd = nodes.get(id) || { n: 0, k: 0, runs: [], endDeaths: 0 };
|
||||
const g = el("g", { class: "loc", tabindex: 0, role: "button", "aria-label": `${name(id)}: ${nd.n} riders` }, gN);
|
||||
const sel = id === selected;
|
||||
if (P.kind === "dragon") {
|
||||
const r = 11 + 9 * Math.sqrt(nd.n / total);
|
||||
el("circle", { cx: P.x, cy: P.y, r: r + 4, fill: PAPER.halo, "fill-opacity": 0.85, stroke: sel ? "#1d0a12" : INK[P.colour], "stroke-width": sel ? 3 : 1.6 }, g);
|
||||
el("circle", { cx: P.x, cy: P.y, r, fill: "#fbf0d6", stroke: INK[P.colour], "stroke-width": 2.2 }, g);
|
||||
el("path", { d: WING, fill: INK[P.colour], transform: `translate(${P.x - r * 0.82} ${P.y - r * 0.5}) scale(${(r * 1.64) / 100})` }, g);
|
||||
} else if (P.kind === "start") {
|
||||
el("path", { d: `M${P.x} ${P.y - 11} L${P.x + 9} ${P.y} L${P.x} ${P.y + 11} L${P.x - 9} ${P.y} Z`, fill: sel ? "#1d0a12" : PAPER.ink, stroke: PAPER.halo, "stroke-width": 2 }, g);
|
||||
} else {
|
||||
const r = P.kind === "small" ? 5 : 7 + 5 * Math.sqrt(nd.n / total);
|
||||
el("circle", { cx: P.x, cy: P.y, r: r + 2.5, fill: PAPER.halo, stroke: sel ? "#1d0a12" : "none", "stroke-width": 2.5 }, g);
|
||||
el("circle", { cx: P.x, cy: P.y, r, fill: P.kind === "small" ? "#7a5236" : PAPER.ink }, g);
|
||||
}
|
||||
// deaths that ended here
|
||||
if (nd.endDeaths) {
|
||||
const bx = P.x + (P.kind === "dragon" ? 18 : 10), by = P.y - (P.kind === "dragon" ? 16 : 10);
|
||||
el("circle", { cx: bx, cy: by, r: 8.5, fill: PAPER.death, stroke: PAPER.halo, "stroke-width": 1.4 }, g);
|
||||
const t = el("text", { x: bx, y: by + 3.2, "text-anchor": "middle", "font-size": 8.5, fill: "#fff3e0", "font-family": "var(--font-data)" }, g);
|
||||
t.textContent = nd.endDeaths > 999 ? Math.round(nd.endDeaths / 100) / 10 + "k" : nd.endDeaths;
|
||||
}
|
||||
// labels (first sightings are labelled by their dragon glyph and tooltip only)
|
||||
if (!P.first) {
|
||||
const pos = P.lab || "right", off = P.kind === "dragon" ? 24 : 12;
|
||||
let x = P.x, y = P.y + 4, anchor = "middle";
|
||||
if (pos === "right") { x = P.x + off; anchor = "start"; }
|
||||
else if (pos === "left") { x = P.x - off; anchor = "end"; }
|
||||
else if (pos === "below") y = P.y + off + 12;
|
||||
else if (pos === "above") y = P.y - off - 18;
|
||||
const t1 = el("text", { x, y, "text-anchor": anchor, "font-family": "var(--font-display)", "font-size": P.kind === "small" ? 12.5 : 15, fill: PAPER.ink, "paint-order": "stroke", stroke: PAPER.halo, "stroke-width": 3.5, "stroke-linejoin": "round" }, g);
|
||||
t1.textContent = P.name;
|
||||
if (P.kind !== "small") {
|
||||
const t2 = el("text", { x, y: y + 14, "text-anchor": anchor, "font-size": 11, fill: PAPER.ink, "fill-opacity": 0.85, "paint-order": "stroke", stroke: PAPER.halo, "stroke-width": 3, "font-family": "var(--font-body)" }, g);
|
||||
t2.textContent = `${nd.n.toLocaleString()} riders${P.sub ? " · " + P.sub : ""}`;
|
||||
}
|
||||
}
|
||||
const pick = () => { selected = id; render(state); };
|
||||
g.addEventListener("click", pick);
|
||||
g.addEventListener("keydown", (ev) => { if (ev.key === "Enter" || ev.key === " ") { ev.preventDefault(); pick(); } });
|
||||
g.addEventListener("mousemove", (ev) => tip(ev, `<div class="t">${esc(name(id))}</div>${nd.n.toLocaleString()} riders${nd.endDeaths ? ` · ${nd.endDeaths} died here` : ""}<br>${esc(E.TARGETS[target].label)}: ${pct(nd.n ? nd.k / nd.n : null, 1)}`));
|
||||
g.addEventListener("mouseleave", hideTip);
|
||||
});
|
||||
// sighting captions per direction
|
||||
["West", "Center", "East"].forEach((dname) => {
|
||||
const xs = Object.keys(L).filter((k) => k.startsWith(`see:${dname}:`)).map((k) => L[k]);
|
||||
const cx = xs.reduce((a, p) => a + p.x, 0) / xs.length, cy = Math.min(...xs.map((p) => p.y)) - 26;
|
||||
const t = el("text", { x: cx, y: cy, "text-anchor": "middle", "font-size": 10.5, "letter-spacing": "0.12em", fill: PAPER.ink, "fill-opacity": 0.8, "font-family": "var(--font-label)", "paint-order": "stroke", stroke: PAPER.halo, "stroke-width": 3 }, svg);
|
||||
t.textContent = "FIRST DRAGON · ROLL";
|
||||
});
|
||||
// compass
|
||||
const cr = el("g", { transform: "translate(52 726)", "aria-hidden": "true" }, svg);
|
||||
el("circle", { r: 24, fill: PAPER.halo, "fill-opacity": 0.7, stroke: PAPER.ink, "stroke-opacity": 0.5 }, cr);
|
||||
el("path", { d: "M0 -20 L5 0 L0 20 L-5 0 Z", fill: PAPER.ink }, cr);
|
||||
const nT = el("text", { y: -28, "text-anchor": "middle", "font-size": 11, fill: PAPER.ink, "font-family": "var(--font-display)" }, cr); nT.textContent = "N";
|
||||
overlay(svg);
|
||||
renderCard(nodes, edges);
|
||||
$("#valley-legend").innerHTML = `<span>Trail width = riders who walked it</span>
|
||||
<span style="display:inline-flex;gap:6px;align-items:center">0% <span class="ramp" style="background:linear-gradient(90deg, ${PAPER.trailLow}, ${tcol})"></span> ${pct(pmax)}</span>
|
||||
<span><span style="display:inline-block;width:12px;height:12px;border-radius:50%;background:${PAPER.death};vertical-align:-2px"></span> riders who died at that spot</span>
|
||||
<span>Dotted = described by the community, not tracked by the form</span>
|
||||
<span>Faded = fewer than ${minN} riders · positions are illustrative</span>`;
|
||||
}
|
||||
function name(id) {
|
||||
const P = L[id];
|
||||
if (!P) return id;
|
||||
if (P.first) { const [, d, c] = id.split(":"); return `${c} dragon (first sighting, ${d === "Center" ? "forest centre" : d.toLowerCase()})`; }
|
||||
return P.name;
|
||||
}
|
||||
function renderCard(nodes, edges) {
|
||||
const P = L[selected], nd = nodes.get(selected) || { n: 0, k: 0, runs: [], endDeaths: 0 };
|
||||
const card = $("#loc-card");
|
||||
card.style.setProperty("--lc", P.colour ? cssVar(DV[P.colour]) : cssVar("--accent"));
|
||||
const w = E.wilson(nd.k, nd.n);
|
||||
const out = [...edges.values()].filter((e) => e.a === selected).sort((a, b) => b.n - a.n);
|
||||
const outN = out.reduce((a, e) => a + e.n, 0);
|
||||
const ends = {};
|
||||
nd.runs.forEach((r) => {
|
||||
const k = r.outcome === "Bonded" ? "Bonded " + r.outcome_color : r.outcome === "Incinerated" ? "Incinerated" : r.outcome === "Died before the hour" ? "Died before the hour" : "Not recorded";
|
||||
ends[k] = (ends[k] || 0) + 1;
|
||||
});
|
||||
const order = ["Bonded Red", "Bonded Orange", "Bonded Brown", "Bonded Green", "Bonded Blue", "Bonded Black", "Incinerated", "Died before the hour", "Not recorded"];
|
||||
const bar = (label, n, of, c) => `<div class="bar" style="--c:${c}"><span>${esc(label)}</span><i style="width:${(100 * n) / Math.max(1, of)}%"></i><span>${n} · ${pct(n / Math.max(1, nd.n))}</span></div>`;
|
||||
const maxEnd = Math.max(1, ...Object.values(ends));
|
||||
const P2 = P.first ? { desc: "The game rolls which dragon finds you first. Lower your eyes and keep still." } : P;
|
||||
card.innerHTML = `<span class="eyebrow">${P.kind === "dragon" ? "A dragon waits here" : "Selected place"}</span><h3>${esc(name(selected))}</h3>
|
||||
<p class="small muted">${esc(P2.desc || "")}</p>
|
||||
<p class="small"><b>${nd.n.toLocaleString()}</b> logged runs reached this spot${nd.endDeaths ? `, and <b style="color:var(--ember)">${nd.endDeaths}</b> died here` : ""}. ${esc(E.TARGETS[target].label)}: <b>${pct(w.p, 1)}</b> of them (95% CI ${pct(w.lo, 1)}–${pct(w.hi, 1)}).</p>
|
||||
${out.length ? `<span class="eyebrow">Where they went next</span><div class="bars">${out.map((e) => bar(name(e.b).replace(/ \(first sighting.*\)/, " first"), e.n, out[0].n, L[e.b].colour ? `var(${DV[L[e.b].colour]})` : "var(--accent)")).join("")}</div>` : ""}
|
||||
<span class="eyebrow">How those runs ended</span><div class="bars">${order.filter((k) => ends[k]).map((k) => bar(k, ends[k], maxEnd, k.startsWith("Bonded") ? `var(${DV[k.split(" ")[1]]})` : k === "Incinerated" ? "var(--ember)" : "var(--faint)")).join("") || '<span class="small muted">No runs.</span>'}</div>`;
|
||||
}
|
||||
// shared with the route planner (planner.js), which paints the same valley and draws the solver's options on it
|
||||
const paintBase = (svg) => { defs(svg); paint(svg); };
|
||||
window.ValleyMap = { render, path, places: L, paintBase, finish: overlay, name, curve, INK, PAPER, WING };
|
||||
window.ValleyMap = { places: L, paintBase, finish: overlay, name, curve, INK, PAPER, WING };
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user