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:
ekcSchiano
2026-11-03 21:37:10 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 963b08c522
commit d04b88e7b4
14 changed files with 866 additions and 424 deletions
+78 -155
View File
@@ -1,17 +1,26 @@
/* app.js — renders the Threshing Route Atlas from engine.js results. All numbers come from ThreshEngine. */
/* app.js — renders the Threshing Route Atlas. Every number comes precomputed from data/stats.json
(analysis/stats/site_stats.py); this file only displays them. */
(function () {
"use strict";
const E = window.ThreshEngine;
const $ = (s, el = document) => el.querySelector(s);
const $$ = (s, el = document) => [...el.querySelectorAll(s)];
const NS = "http://www.w3.org/2000/svg";
const state = {
raw: null, bundled: null, allRuns: [], runs: [], res: null, missing: [],
filters: { source: "all", goal: "all", excludeFlagged: false },
target: "bond_any", widthMode: "traffic", minN: 10, conds: {},
stats: null, preset: "all", P: null, res: null,
target: "bond_any", widthMode: "traffic", minN: 10,
fxOutcome: "blue_meadow", fxFactor: "resolution", rtTarget: "see_Blue", rtMin: 10,
};
const META = () => state.stats.meta;
const TARGET = (t) => META().targets[t];
const MISSING = () => new Set(META().missing_values);
const isMissing = (v) => v === null || v === undefined || v === "" || MISSING().has(v);
/** A precomputed route ranking at one of the fixed thresholds: rows with at least minN runs, their q-values. */
function routesAt(target, minN) {
const R = state.P.routes[target], b = R.by_threshold[String(minN)];
const rows = R.rows.map((r, i) => ({ ...r, q: b.q[i], mh_q: b.mh_q[i] })).filter((r) => r.n >= minN);
return { target, overall: R.overall, minN, n_routes_tested: b.n_routes_tested, rows };
}
// ------------------------------------------------------------ formatting
const pct = (p, d = 1) => (p === null || p === undefined || isNaN(p) ? "–" : (p * 100).toFixed(p > 0 && p < 0.001 ? 2 : d) + "%");
@@ -38,7 +47,7 @@
}
const DRAGON_VAR = { Red: "--dr-red", Green: "--dr-green", Orange: "--dr-orange", Brown: "--dr-brown", Blue: "--dr-blue", Black: "--dr-black" };
const dragonColor = (c) => cssVar(DRAGON_VAR[c] || "--dr-any");
const targetColor = (t) => dragonColor(E.TARGETS[t].color);
const targetColor = (t) => dragonColor(TARGET(t).color);
function svgEl(tag, attrs = {}, parent) {
const e = document.createElementNS(NS, tag);
@@ -73,42 +82,22 @@
const hideTip = () => (tip.hidden = true);
// ------------------------------------------------------------ data loading
async function loadBundled() {
const resp = await fetch("data/form_responses.json");
const raw = await resp.json();
state.bundled = raw;
useRaw(raw, `bundled snapshot (${raw.source_file}, exported ${raw.exported})`);
}
function useRaw(raw, label) {
const { runs, missing } = E.codeRows(raw.rows, raw.headers);
state.raw = raw; state.allRuns = runs; state.missing = missing; state.dataLabel = label;
state.conds = {};
async function loadStats() {
state.stats = await (await fetch("data/stats.json")).json();
const sel = $("#f-preset");
sel.innerHTML = Object.entries(META().presets).map(([k, l]) => `<option value="${k}">${esc(l)}</option>`).join("");
sel.value = state.preset;
const th = META().route_thresholds;
for (const id of ["#minn", "#rt-min"]) {
$(id).innerHTML = th.map((m) => `<option value="${m}">${m}</option>`).join("");
$(id).value = String(state.minN);
}
recompute();
}
$("#upload").addEventListener("change", async (e) => {
const f = e.target.files[0];
if (!f) return;
try {
const buf = await f.arrayBuffer();
const wb = XLSX.read(buf, { type: "array", cellDates: true });
const name = wb.SheetNames.find((n) => /form responses/i.test(n)) || wb.SheetNames[0];
const ws = wb.Sheets[name];
const headers = (XLSX.utils.sheet_to_json(ws, { header: 1, blankrows: false })[0] || []).map(String);
const rows = XLSX.utils.sheet_to_json(ws, { defval: null, raw: true });
useRaw({ rows, headers, source_file: f.name, exported: new Date().toISOString().slice(0, 10) }, `uploaded file ${f.name} (sheet "${name}")`);
$("#btn-reset-data").hidden = false;
toast(`Loaded ${rows.length} rows from ${f.name}`);
} catch (err) {
toast("That file could not be read. Export the responses sheet as .xlsx or .csv and try again.");
console.error(err);
}
e.target.value = "";
});
$("#btn-reset-data").addEventListener("click", () => { useRaw(state.bundled, `bundled snapshot (${state.bundled.source_file}, exported ${state.bundled.exported})`); $("#btn-reset-data").hidden = true; });
function recompute() {
state.runs = E.applyFilters(state.allRuns, state.filters);
state.res = E.analyse(state.allRuns, state.filters);
state.P = state.stats.presets[state.preset];
state.res = state.P.analyse;
renderAll();
}
@@ -116,17 +105,13 @@
function renderStatus() {
const m = state.res.meta;
const src = Object.entries(m.sources).sort((a, b) => b[1] - a[1]).map(([k, v]) => `${k} ${v.toLocaleString()}`).join(" · ");
const filt = [];
if (state.filters.source !== "all") filt.push(state.filters.source === "form" ? "form submissions only" : "bulk logs only");
if (state.filters.goal !== "all") filt.push(state.filters.goal === "exclude_rare" ? "not chasing Blue/Black" : "chasing Blue/Black");
if (state.filters.excludeFlagged) filt.push("flagged rows dropped");
const total = state.stats.data.runs;
$("#data-status").innerHTML = `
<span><b>${state.res.n.toLocaleString()}</b> runs${state.res.n !== state.allRuns.length ? ` of ${state.allRuns.length.toLocaleString()}` : ""}</span>
<span><b>${state.res.n.toLocaleString()}</b> runs${state.res.n !== total ? ` of ${total.toLocaleString()}` : ""}</span>
<span>${esc(src)}</span>
<span>Form dates ${m.date_min || "?"} → ${m.date_max || "?"}</span>
<span class="pill">${esc(state.dataLabel)}</span>
${filt.length ? `<span class="pill warn">Filtered: ${esc(filt.join(", "))}</span>` : ""}
${state.missing.length ? `<span class="pill warn">Questions not found in this file: ${esc(state.missing.join(", "))}</span>` : ""}`;
<span class="pill">Snapshot of the community form${state.stats.data.exported ? `, exported ${esc(state.stats.data.exported)}` : ""}</span>
${state.preset !== "all" ? `<span class="pill warn">Showing: ${esc(state.P.label)}</span>` : ""}`;
}
// ------------------------------------------------------------ findings
@@ -158,7 +143,7 @@
const mb = r.models.blue_meadow;
if (mb) {
const sig = mb.terms.filter((t) => ROUTE_FACTORS.includes(t.factor) && t.p < 0.05 && !NOT_A_CHOICE.test(t.level));
const rk = E.rankRoutes(state.runs, "see_Blue", state.rtMin);
const rk = routesAt("see_Blue", state.rtMin);
const adjSig = rk.rows.filter((x) => x.mh_q !== undefined && x.mh_q < 0.05);
let t = sig.length
? `<p><b>After adjusting for reporting bias, ${sig.length === 1 ? "one recorded choice was" : sig.length + " recorded choices were"} linked to the Blue appearing:</b> ${sig.map((s) => `${esc(labelFactor(s.factor))}: ${esc(s.level)} (OR ${fmtOR(s.or)}, 95% CI ${fmtOR(s.lo)}–${fmtOR(s.hi)}, p = ${fmtP(s.p)})`).join("; ")}.</p>`
@@ -171,8 +156,7 @@
}
if (cs.overall.n) {
const bulkS = stratumRate(cs, "Bulk"), formS = Object.entries(cs.by_stratum).filter(([k]) => k.startsWith("Form"));
const fk = formS.reduce((a, [, w]) => a + w.k, 0), fn = formS.reduce((a, [, w]) => a + w.n, 0);
const fw = E.wilson(fk, fn);
const fw = cs.form_overall, fn = fw.n;
let t = `<p><b>The tree shadow showed up in ${rateTxt(cs.overall)} of logged tree climbs.</b>${fn ? ` Form submissions: ${rateTxt(fw)}.` : ""}`;
if (bulkS && bulkS.n >= 30 && fn >= 30 && fw.lo > bulkS.hi) t += ` Bulk logs: ${rateTxt(bulkS)}. Those two cannot both be the true rate for the same game. The form figure is the one exposed to selective reporting, so the true rate is probably nearer the bulk logs, whose 95% upper bound is ${pct(bulkS.hi)} per climb.`;
t += `</p>`;
@@ -213,8 +197,8 @@
const OTHER_T = ["see_Blue", "see_shadow"];
function renderTargets() {
const chip = (t, featured) => {
const c = E.TARGETS[t].color ? DRAGON_VAR[E.TARGETS[t].color] : "--dr-any";
return `<button type="button" class="tchip${featured ? " featured" : ""}" data-t="${t}" aria-pressed="${state.target === t}" style="--c: var(${c})"><span class="sw"></span>${esc(E.TARGETS[t].label)}</button>`;
const c = TARGET(t).color ? DRAGON_VAR[TARGET(t).color] : "--dr-any";
return `<button type="button" class="tchip${featured ? " featured" : ""}" data-t="${t}" aria-pressed="${state.target === t}" style="--c: var(${c})"><span class="sw"></span>${esc(TARGET(t).label)}</button>`;
};
$("#targets-rare").innerHTML = RARE_T.map((t) => chip(t, false)).join("");
$("#targets-other").innerHTML = OTHER_T.map((t) => chip(t, false)).join("");
@@ -237,25 +221,24 @@
"Tree: shadow → Blue/Black": "Tree: shadow (Blue→Black)", "Meadow (no attempt recorded)": "Meadow: none recorded", "Unknown → Unknown": "Unknown",
};
const short = (v) => SHORT[v] || v;
const condSets = () => Object.fromEntries(Object.entries(state.conds).map(([k, v]) => [k, new Set(v)]));
function renderMap() {
const svg = $("#map");
svg.innerHTML = "";
const runs = state.runs;
const base = E.buildGraph(runs, state.target, {});
const sel = E.buildGraph(runs, state.target, condSets());
const hasSel = Object.values(state.conds).some((v) => v.length);
const selNode = new Map(sel.nodes.map((n) => [n.id, n]));
// the precomputed route map, with the chosen outcome's counts and intervals on every box and band
const G = state.P.map, BT = G.by_target[state.target];
const sel = { nodes: G.nodes.map((n, i) => ({ ...n, ...BT.nodes[i] })), links: G.links.map((l, i) => ({ ...l, ...BT.links[i] })) };
const base = sel;
const STAGES = META().stages;
const minN = state.minN;
const tcol = targetColor(state.target), low = cssVar("--link-low"), surface = cssVar("--raised");
const shell = $(".map-scroll");
const W = Math.max(1440, shell.clientWidth || 1440), H = 660, top = 40, bottom = 16, left = 10, right = 168, nodeW = 12;
svg.setAttribute("width", W); svg.setAttribute("height", H); svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
const S = E.STAGES.length;
const S = STAGES.length;
const colX = (i) => left + (i * (W - left - right - nodeW)) / (S - 1);
const cols = E.STAGES.map((s, i) => {
const cols = STAGES.map((s, i) => {
const ns = base.nodes.filter((n) => n.stage === i);
const ord = ORDER[s.key];
ns.sort((a, b) => {
@@ -284,8 +267,8 @@
const colorFor = (o) => (o.n < minN ? low : mix(low, tcol, Math.pow(Math.min(1, o.p / pmax), 0.75)));
// stage headers
E.STAGES.forEach((s, i) => {
const chance = s.key === "first_sighting" || s.key === "encounter";
STAGES.forEach((s, i) => {
const chance = s.chance;
const t = svgEl("text", { x: colX(i), y: 18, class: "stage-label" + (chance ? " stage-chance" : "") }, svg);
t.textContent = s.label;
if (chance) { const r = svgEl("text", { x: colX(i), y: 31, class: "stage-label stage-chance" }, svg); r.textContent = "game roll"; }
@@ -322,7 +305,7 @@
el = svgEl("path", { d: `M${x0},${y0}C${xm},${y0} ${xm},${y1} ${x1},${y1}`, fill: "none", stroke: colorFor(l), "stroke-width": w, "stroke-opacity": l.n >= minN ? 0.8 : 0.3, "stroke-linecap": "round", class: "link" }, gLinks);
}
const sv = pos.get(l.source).n.value, tv = pos.get(l.target).n.value;
el.addEventListener("mousemove", (e) => showTip(e, `<div class="t">${esc(sv)} → ${esc(tv)}</div>${l.n} runs${hasSel ? " (in your selection)" : ""}<br>${esc(E.TARGETS[state.target].label)}: <b>${pct(l.p)}</b> (${kn(l)})<br>95% CI ${ci(l)}${l.n < minN ? "<br><i>Too few runs to read</i>" : ""}`));
el.addEventListener("mousemove", (e) => showTip(e, `<div class="t">${esc(sv)} → ${esc(tv)}</div>${l.n} runs<br>${esc(TARGET(state.target).label)}: <b>${pct(l.p)}</b> (${kn(l)})<br>95% CI ${ci(l)}${l.n < minN ? "<br><i>Too few runs to read</i>" : ""}`));
el.addEventListener("mouseleave", hideTip);
});
@@ -331,66 +314,26 @@
cols.forEach((ns, i) => {
let lastLabelBottom = -1e9;
ns.forEach((bn) => {
const p = pos.get(bn.id), sn = selNode.get(bn.id);
const isSel = (state.conds[E.STAGES[i].key] || []).includes(bn.value);
const g = svgEl("g", { class: "node" + (isSel ? " sel" : "") + (hasSel && !sn ? " dim" : ""), tabindex: 0, role: "button", "aria-label": `${E.STAGES[i].label}: ${bn.value}, ${bn.n} runs` }, gNodes);
const shown = sn || { n: 0, k: 0, p: null };
svgEl("rect", { x: p.x, y: p.y, width: nodeW, height: p.h, rx: 2, fill: sn ? colorFor(sn) : low }, g);
const p = pos.get(bn.id), sn = bn;
const g = svgEl("g", { class: "node", tabindex: 0, "aria-label": `${STAGES[i].label}: ${bn.value}, ${bn.n} runs` }, gNodes);
svgEl("rect", { x: p.x, y: p.y, width: nodeW, height: p.h, rx: 2, fill: colorFor(sn) }, g);
const lx = p.x + nodeW + 5, ly = p.y + p.h / 2 + 4;
if (ly - 11 > lastLabelBottom || isSel) {
if (ly - 11 > lastLabelBottom) {
const t = svgEl("text", { x: lx, y: ly, "paint-order": "stroke", stroke: surface, "stroke-width": 3, "stroke-linejoin": "round" }, g);
const lab = short(bn.value), maxC = i === S - 1 ? 30 : Math.floor((colX(1) - colX(0) - nodeW - 36) / 5.8);
t.textContent = lab.length > maxC ? lab.slice(0, maxC - 1) + "…" : lab;
const t2 = svgEl("tspan", { fill: cssVar("--muted"), dx: 4 }, t);
t2.textContent = sn && sn.n >= minN ? pct(sn.p, 0) : sn ? `n=${sn.n}` : "";
t2.textContent = sn.n >= minN ? pct(sn.p, 0) : `n=${sn.n}`;
lastLabelBottom = ly;
}
const html = () => `<div class="t">${esc(E.STAGES[i].label)}: ${esc(bn.value)}</div>${hasSel ? `${shown.n} of ${bn.n} runs in your selection` : `${bn.n} runs`}<br>${esc(E.TARGETS[state.target].label)}: <b>${pct(shown.p)}</b> (${shown.k}/${shown.n})<br>95% CI ${ci(sn)}<br><span class="muted">Click to ${isSel ? "remove from" : "add to"} the selection</span>`;
const html = () => `<div class="t">${esc(STAGES[i].label)}: ${esc(bn.value)}</div>${bn.n} runs<br>${esc(TARGET(state.target).label)}: <b>${pct(sn.p)}</b> (${sn.k}/${sn.n})<br>95% CI ${ci(sn)}`;
g.addEventListener("mousemove", (e) => showTip(e, html()));
g.addEventListener("focus", (e) => { const r = e.target.getBoundingClientRect(); showTip({ clientX: r.right, clientY: r.top }, html()); });
g.addEventListener("mouseleave", hideTip);
const toggle = () => {
const k = E.STAGES[i].key, cur = new Set(state.conds[k] || []);
cur.has(bn.value) ? cur.delete(bn.value) : cur.add(bn.value);
state.conds[k] = [...cur];
if (!state.conds[k].length) delete state.conds[k];
hideTip(); renderMap();
};
g.addEventListener("click", toggle);
g.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); toggle(); } });
g.addEventListener("blur", hideTip);
});
});
renderCondChips(); renderSelSummary(sel); renderLegend(pmax, tcol, low);
}
function renderCondChips() {
const entries = Object.entries(state.conds).filter(([, v]) => v.length);
$("#cond-chips").innerHTML = entries.length
? entries.map(([k, vals]) => vals.map((v) => `<span class="cchip">${esc(E.STAGES.find((s) => s.key === k).label)}: ${esc(v)}<button type="button" aria-label="Remove ${esc(v)}" data-k="${esc(k)}" data-v="${esc(v)}">×</button></span>`).join("")).join("")
: `<span class="small muted">Showing all runs. Click a box to follow only the runs through it.</span>`;
$$("#cond-chips button").forEach((b) => b.addEventListener("click", () => {
state.conds[b.dataset.k] = (state.conds[b.dataset.k] || []).filter((v) => v !== b.dataset.v);
if (!state.conds[b.dataset.k].length) delete state.conds[b.dataset.k];
renderMap();
}));
}
function renderSelSummary(sel) {
const T = E.TARGETS[state.target];
const cs = condSets();
const inSel = (r) => Object.entries(cs).every(([k, set]) => !set.size || set.has(E.stageValue(r, k)));
const pool = state.runs.filter(T.pool);
const A = pool.filter(inSel), B = pool.filter((r) => !inSel(r));
const wa = E.wilson(A.filter(T.fn).length, A.length), wb = E.wilson(B.filter(T.fn).length, B.length);
const hasSel = Object.keys(state.conds).length > 0;
let cmp = "";
if (hasSel && A.length && B.length) {
const o = E.oddsRatio(wa.k, wa.n - wa.k, wb.k, wb.n - wb.k);
cmp = `<div>Everyone else: ${pct(wb.p)} (${kn(wb)}). Odds ratio ${fmtOR(o.or)} (95% CI ${fmtOR(o.or_lo)}–${fmtOR(o.or_hi)}), Fisher p = ${fmtP(o.fisher_p)}. This is unadjusted: if your selection mixes in a lot of Blue-chasers, expect it to look better than it is.</div>`;
}
$("#sel-summary").innerHTML = `
<span class="eyebrow">${hasSel ? "Your selection" : "All runs"} · ${esc(T.label)}</span>
<div><span class="big">${pct(wa.p)}</span> <span class="muted">${kn(wa)} runs that could reach it · 95% CI ${ci(wa)}</span></div>
${cmp}`;
renderLegend(pmax, tcol, low);
}
function renderLegend(pmax, tcol, low) {
@@ -402,22 +345,15 @@
}
function renderBestRoutes() {
const rk = E.rankRoutes(state.runs, state.target, state.minN);
const rk = routesAt(state.target, state.minN);
const rows = rk.rows.slice(0, 8);
const sigN = rk.rows.filter((r) => r.mh_q !== undefined && r.mh_q < 0.05 && r.mh_or > 1).length;
$("#best-routes").innerHTML = `<div class="panel">
<h3>Top routes for "${esc(E.TARGETS[state.target].label)}" <span class="small muted">routes with ≥ ${state.minN} runs, ranked by the lower end of the 95% interval</span></h3>
<h3>Top routes for "${esc(TARGET(state.target).label)}" <span class="small muted">routes with ≥ ${state.minN} runs, ranked by the lower end of the 95% interval</span></h3>
<p class="small">${rows.length ? `Overall rate in the comparison group: ${rateTxt(rk.overall)}. <b>${sigN} of ${rk.n_routes_tested} routes are better than the rest after adjusting for reporting bias and multiple testing.</b> ${sigN === 0 ? "Treat the ordering below as noise unless a newer export changes this." : ""}` : "No route has enough runs at this threshold. Lower the minimum."}</p>
${rows.length ? `<div class="tbl-wrap"><table><thead><tr><th>Route (choices up to the hour)</th><th class="num">Runs</th><th class="num">Rate</th><th class="num">95% CI</th><th class="num">Adj. OR</th><th class="num">Adj. q</th><th></th></tr></thead><tbody>
${rows.map((r, i) => `<tr class="${r.mh_q < 0.05 && r.mh_or > 1 ? "sig" : ""}"><td class="route-cell">${esc(r.route)}</td><td class="num">${r.n}</td><td class="num">${pct(r.p)}</td><td class="num">${ci(r)}</td><td class="num">${fmtOR(r.mh_or)}</td><td class="num">${fmtP(r.mh_q)}</td><td><button type="button" data-i="${i}">Follow</button></td></tr>`).join("")}
${rows.length ? `<div class="tbl-wrap"><table><thead><tr><th>Route (choices up to the hour)</th><th class="num">Runs</th><th class="num">Rate</th><th class="num">95% CI</th><th class="num">Adj. OR</th><th class="num">Adj. q</th></tr></thead><tbody>
${rows.map((r, i) => `<tr class="${r.mh_q < 0.05 && r.mh_or > 1 ? "sig" : ""}"><td class="route-cell">${esc(r.route)}</td><td class="num">${r.n}</td><td class="num">${pct(r.p)}</td><td class="num">${ci(r)}</td><td class="num">${fmtOR(r.mh_or)}</td><td class="num">${fmtP(r.mh_q)}</td></tr>`).join("")}
</tbody></table></div>` : ""}</div>`;
$$("#best-routes button[data-i]").forEach((b) => b.addEventListener("click", () => {
const r = rows[+b.dataset.i];
state.conds = {};
E.STAGES.slice(0, 6).forEach((s, i) => { if (r.values[i]) state.conds[s.key] = [r.values[i]]; });
renderMap();
$("#map-sec").scrollIntoView({ behavior: "smooth" });
}));
}
// ------------------------------------------------------------ small charts
@@ -488,10 +424,10 @@
const blueCol = dragonColor("Blue"), blackCol = dragonColor("Black");
const strataRows = (c, col) => [{ label: "All rows", ...c.overall, color: cssVar("--ink") }].concat(
STRATUM_ORDER.filter((s) => c.by_stratum[s]).map((s) => ({ label: s, ...c.by_stratum[s], color: col })),
Object.entries(c.by_attempt).filter(([k]) => !E.isMissing(k)).map(([k, w]) => ({ label: k, ...w, color: cssVar("--accent") })));
Object.entries(c.by_attempt).filter(([k]) => !isMissing(k)).map(([k, w]) => ({ label: k, ...w, color: cssVar("--accent") })));
ciBars($("#ch-blue-strata"), strataRows(r.chance.blue_meadow, blueCol), { labelW: 180 });
ciBars($("#ch-shadow-strata"), strataRows(r.chance.shadow, blackCol), { labelW: 180 });
const termsOf = (m, skip = []) => (m ? m.terms.filter((t) => t.n >= 5 && !skip.includes(t.factor) && !E.isMissing(t.level)) /* the "goal not asked" stratum stays in the model as an adjustment, but is not a finding */.map((t) => ({ label: `${labelFactor(t.factor)}: ${t.level}`, or: t.or, lo: t.lo, hi: t.hi, p: t.p, n: t.n })) : []);
const termsOf = (m, skip = []) => (m ? m.terms.filter((t) => t.n >= 5 && !skip.includes(t.factor) && !isMissing(t.level)) /* the "goal not asked" stratum stays in the model as an adjustment, but is not a finding */.map((t) => ({ label: `${labelFactor(t.factor)}: ${t.level}`, or: t.or, lo: t.lo, hi: t.hi, p: t.p, n: t.n })) : []);
const mb = r.models.blue_meadow, ms = r.models.shadow;
forest($("#ch-model-blue"), termsOf(mb));
forest($("#ch-model-shadow"), termsOf(ms));
@@ -513,11 +449,11 @@
const svg = svgEl("svg", { viewBox: `0 0 ${W} ${H}`, width: W, height: H, role: "img" });
const x = (i) => l + (d.length === 1 ? (W - l - rgt) / 2 : (i * (W - l - rgt)) / (d.length - 1));
const panels = [
{ y0: top, y1: mid - 14, k: "blue_k", n: "meadow_n", col: dragonColor("Blue"), name: "Blue in meadow" },
{ y0: mid + 6, y1: H - bottom, k: "shadow_k", n: "tree_n", col: dragonColor("Black"), name: "Shadow at tree" },
{ y0: top, y1: mid - 14, w: "blue", col: dragonColor("Blue"), name: "Blue in meadow" },
{ y0: mid + 6, y1: H - bottom, w: "shadow", col: dragonColor("Black"), name: "Shadow at tree" },
];
panels.forEach((P) => {
const vals = d.map((r) => E.wilson(r[P.k], r[P.n]));
const vals = d.map((r) => r[P.w]);
const ymax = Math.min(1, Math.max(0.05, ...vals.filter((v) => v.n >= 5).map((v) => v.hi)));
const y = (v) => P.y1 - (v / ymax) * (P.y1 - P.y0);
const ga = svgEl("g", { class: "axis" }, svg);
@@ -559,11 +495,11 @@
box.innerHTML = `<h3>Bond rate once the encounter starts</h3><div class="chart" id="ch-enc-inner"></div>`;
ciBars($("#ch-enc-inner"), rows, { labelW: 220, max: 1, rowH: 22 });
const g = r.green_rescue;
const parts = [["Bonded a Green", g.bonded_green, dragonColor("Green")], ["Rescued, bonded the Orange", g.rescued_orange, dragonColor("Orange")], ["Rescued, bonded the Brown", g.rescued_brown, dragonColor("Brown")], ["Incinerated", g.incinerated, cssVar("--faint")], ["No outcome recorded", g.green_encounters - g.bonded_green - g.rescued_orange - g.rescued_brown - g.incinerated, cssVar("--line")]];
const parts = [["Bonded a Green", g.bonded_green, dragonColor("Green"), "bonded_green"], ["Rescued, bonded the Orange", g.rescued_orange, dragonColor("Orange"), "rescued_orange"], ["Rescued, bonded the Brown", g.rescued_brown, dragonColor("Brown"), "rescued_brown"], ["Incinerated", g.incinerated, cssVar("--faint"), "incinerated"], ["No outcome recorded", g.no_outcome, cssVar("--line"), "no_outcome"]];
const tot = g.green_encounters || 1;
$("#green-rescue").innerHTML = `<p class="small muted">${g.green_encounters} tree runs that descended slowly to the two Greens. A wrong answer sometimes brings an Orange or Brown swooping in to bond you instead.</p>
$("#green-rescue").innerHTML = `<p class="small muted">${g.green_encounters} tree runs that met the two Greens (climbing down slowly, or quickly and letting the Red pass). A wrong answer sometimes brings an Orange or Brown swooping in to bond you instead.</p>
<div style="display:flex;height:16px;border-radius:3px;overflow:hidden;border:1px solid var(--line)">${parts.map(([, n, c]) => `<span style="width:${(100 * n) / tot}%;background:${c}"></span>`).join("")}</div>
<div class="tbl-wrap"><table><tbody>${parts.map(([l, n, c]) => { const w = E.wilson(n, g.green_encounters); return `<tr><td><span style="display:inline-block;width:10px;height:10px;border-radius:2px;background:${c};margin-right:6px"></span>${l}</td><td class="num">${n}</td><td class="num">${pct(w.p)}</td><td class="num">${ci(w)}</td></tr>`; }).join("")}</tbody></table></div>`;
<div class="tbl-wrap"><table><tbody>${parts.map(([l, n, c, key]) => { const w = g.rates[key]; return `<tr><td><span style="display:inline-block;width:10px;height:10px;border-radius:2px;background:${c};margin-right:6px"></span>${l}</td><td class="num">${n}</td><td class="num">${pct(w.p)}</td><td class="num">${ci(w)}</td></tr>`; }).join("")}</tbody></table></div>`;
// "Unsure" / blank first sightings are missing information, not a colour: left out of the table and its totals
const cols = ["Red", "Orange", "Brown", "Green"];
const POOL = { "Alone|East": ["Red", "Orange"], "Alone|West": ["Red", "Brown", "Green"], "Alone|Center": ["Red", "Brown"], "1 Squadmate|East": ["Green", "Orange", "Red"], "1 Squadmate|West": ["Red", "Brown", "Green"], "1 Squadmate|Center": ["Red", "Brown"], "2 Squadmates|East": ["Red", "Orange"], "2 Squadmates|West": ["Green", "Brown", "Red"], "2 Squadmates|Center": ["Red", "Brown"] };
@@ -574,12 +510,12 @@
function renderRouteTable() {
const sel = $("#rt-target");
if (!sel.options.length) {
sel.innerHTML = Object.entries(E.TARGETS).map(([k, t]) => `<option value="${k}">${esc(t.label)}</option>`).join("");
sel.innerHTML = Object.entries(META().targets).map(([k, t]) => `<option value="${k}">${esc(t.label)}</option>`).join("");
sel.value = state.rtTarget;
sel.addEventListener("change", () => { state.rtTarget = sel.value; renderRouteTable(); });
$("#rt-min").addEventListener("change", (e) => { state.rtMin = Math.max(1, +e.target.value || 10); renderRouteTable(); renderFindings(); });
$("#rt-min").addEventListener("change", (e) => { state.rtMin = +e.target.value; renderRouteTable(); renderFindings(); });
}
const rk = E.rankRoutes(state.runs, state.rtTarget, state.rtMin);
const rk = routesAt(state.rtTarget, state.rtMin);
const sig = rk.rows.filter((x) => x.mh_q < 0.05 && x.mh_or > 1).length;
$("#rt-note").innerHTML = `${rk.n_routes_tested} routes tested · comparison group ${rateTxt(rk.overall)} · <b>${sig}</b> clearly better after adjustment`;
const bar = (w) => `<span class="cibar" aria-hidden="true"><i style="left:${w.lo * 90}px;width:${Math.max(1, (w.hi - w.lo) * 90)}px"></i><b style="left:${w.p * 90 - 1}px"></b></span>`;
@@ -592,8 +528,8 @@
function renderFactors() {
const so = $("#fx-outcome"), sf = $("#fx-factor");
if (!so.options.length) {
so.innerHTML = Object.entries(E.OUTCOMES).map(([k, o]) => `<option value="${k}">${esc(o.label)}</option>`).join("");
sf.innerHTML = E.FACTORS.map((f) => `<option value="${f}">${esc(labelFactor(f))}</option>`).join("");
so.innerHTML = Object.entries(META().outcomes).map(([k, o]) => `<option value="${k}">${esc(o.label)}</option>`).join("");
sf.innerHTML = META().factors.map((f) => `<option value="${f}">${esc(labelFactor(f))}</option>`).join("");
so.value = state.fxOutcome; sf.value = state.fxFactor;
so.addEventListener("change", () => { state.fxOutcome = so.value; renderFactors(); });
sf.addEventListener("change", () => { state.fxFactor = sf.value; renderFactors(); });
@@ -616,16 +552,12 @@
<div class="panel"><h3>Who logged the runs</h3><div class="tbl-wrap"><table><thead><tr><th>Source</th><th class="num">Runs</th><th class="num">Blue in meadow</th><th class="num">Shadow at tree</th></tr></thead><tbody>
${Object.entries(m.sources).sort((a, b) => b[1] - a[1]).map(([s, n]) => { const b = sourceRate("blue_meadow", s), t = sourceRate("shadow", s); return `<tr><td>${esc(s)}</td><td class="num">${n}</td><td class="num">${pct(b.p)} <span class="muted">${kn(b)}</span></td><td class="num">${pct(t.p)} <span class="muted">${kn(t)}</span></td></tr>`; }).join("")}
</tbody></table></div><p class="small">Bulk logs come from players who recorded every run, so they are the least selective rows. Their rare-dragon rates are several times lower than the form's, which is the strongest sign of reporting bias in this data.</p></div>
<div class="panel"><h3>Rows flagged for contradictions</h3><p class="small muted">${m.n_flagged} of ${r.n} rows (${pct(m.n_flagged / r.n)}). Flagged rows stay in unless you drop them above.</p><div class="tbl-wrap"><table><tbody>${flags.map(([f, n]) => `<tr><td>${esc(f)}</td><td class="num">${n}</td></tr>`).join("") || `<tr><td>None</td></tr>`}</tbody></table></div></div>
<div class="panel"><h3>Rows flagged for contradictions</h3><p class="small muted">${m.n_flagged} of ${r.n} rows (${pct(m.n_flagged / r.n)}). Flagged rows stay in unless you pick "Rows without data-quality flags" above.</p><div class="tbl-wrap"><table><tbody>${flags.map(([f, n]) => `<tr><td>${esc(f)}</td><td class="num">${n}</td></tr>`).join("") || `<tr><td>None</td></tr>`}</tbody></table></div></div>
<div class="panel"><h3>How runs ended</h3><div class="tbl-wrap"><table><tbody>${outs.map(([f, n]) => `<tr><td>${esc(f)}</td><td class="num">${n}</td><td class="num">${pct(n / r.n)}</td></tr>`).join("")}</tbody></table></div><p class="small muted">"No outcome recorded" rows reached the hour but the form shows no Bonded or Incinerated. They count toward reaching a branch but not toward bond rates.</p></div>
<div class="panel"><h3>Independence</h3><p class="small">The form has no player ID. One player's 50 runs count as 50 independent runs, so intervals are somewhat narrower than they should be. ${pct((r.n - (m.sources["Form"] || 0)) / r.n, 0)} of rows arrived as bulk imports, each probably one player's or one group's log.</p></div>
<div class="panel"><h3>What the form does not ask</h3><p class="small">The redesigned form asks how you reacted to the first dragon (answered in ${r.factors.reach_hour.rows.filter((x) => x.factor === "sighting_action" && !["Unknown", "(not asked)"].includes(x.level)).reduce((a, x) => a + x.n, 0)} rows; most riders answer "Unsure") and how the bully fight went (${r.factors.reach_hour.rows.filter((x) => x.factor === "combat_first" && x.level !== "(not recorded)").reduce((a, x) => a + x.n, 0)} rows). It still does not record most choices inside the bonding encounters. Theories that rely on those choices cannot be confirmed or refuted here.</p></div>`;
}
function sourceRate(outKey, source) {
const O = E.OUTCOMES[outKey];
const D = state.runs.filter((r) => r.source === source).filter(O.denom);
return E.wilson(D.filter(O.event).length, D.length);
}
const sourceRate = (outKey, source) => state.res.source_rates[outKey][source];
// ------------------------------------------------------------ share
function redditPost() {
@@ -634,7 +566,7 @@
const encB = r.encounters.find((e) => e.context === "Blue (meadow)"), encK = r.encounters.find((e) => e.context === "Black (shadow)");
const mb = r.models.blue_meadow;
const sigRoute = mb ? mb.terms.filter((t) => ROUTE_FACTORS.includes(t.factor) && t.p < 0.05 && !NOT_A_CHOICE.test(t.level)) : [];
const rk = E.rankRoutes(state.runs, "see_Blue", state.rtMin);
const rk = routesAt("see_Blue", state.rtMin);
const adjSig = rk.rows.filter((x) => x.mh_q < 0.05 && x.mh_or > 1).length;
const leads = r.factors.shadow.rows.filter((x) => ["post_path", "attempt_group"].includes(x.factor) && x.q < 0.05 && x.or > 1 && !NOT_A_CHOICE.test(x.level));
const L = [];
@@ -659,13 +591,7 @@
L.push(`*Caveats: self-reported data, no player IDs (so runs from one person aren't independent), and the form doesn't record every in-game choice. The author has said there's a ~10% chaos roll, so nothing is guaranteed.*`);
return L.join("\n");
}
function runsCSV() {
const cols = Object.keys(state.runs[0] || {});
const q = (v) => { if (v === null || v === undefined) return ""; const s = String(v); return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s; };
return [cols.join(","), ...state.runs.map((r) => cols.map((c) => q(r[c])).join(","))].join("\n");
}
$("#cp-reddit").addEventListener("click", () => copyText(redditPost(), "Reddit post"));
$("#cp-csv").addEventListener("click", () => copyText(runsCSV(), `${state.runs.length} coded runs`));
$("#cp-json").addEventListener("click", () => copyText(JSON.stringify(state.res, null, 1), "results JSON"));
$$("button[data-src]").forEach((b) => b.addEventListener("click", async () => {
const pre = $("#srcview");
@@ -679,11 +605,8 @@
$$("#width-mode button").forEach((x) => x.setAttribute("aria-pressed", x === b));
renderMap();
}));
$("#minn").addEventListener("change", (e) => { state.minN = Math.max(1, +e.target.value || 10); renderMap(); });
$("#f-source").addEventListener("change", (e) => { state.filters.source = e.target.value; recompute(); });
$("#f-goal").addEventListener("change", (e) => { state.filters.goal = e.target.value; recompute(); });
$("#f-flag").addEventListener("change", (e) => { state.filters.excludeFlagged = e.target.checked; recompute(); });
$("#btn-clear").addEventListener("click", () => { state.conds = {}; renderMap(); $("#best-routes").innerHTML = ""; });
$("#minn").addEventListener("change", (e) => { state.minN = +e.target.value; renderMap(); if ($("#best-routes").innerHTML) renderBestRoutes(); });
$("#f-preset").addEventListener("change", (e) => { state.preset = e.target.value; recompute(); });
$("#btn-best").addEventListener("click", renderBestRoutes);
function renderAll() {
@@ -698,7 +621,7 @@
new MutationObserver(rerender).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
let rz; window.addEventListener("resize", () => { clearTimeout(rz); rz = setTimeout(() => state.res && renderMap(), 200); });
window.ThreshAtlas = { state, redditPost, runsCSV };
window.ThreshAtlas = { state, redditPost };
if (window.DragonRegister) window.DragonRegister.mount({ copy: copyText, toast });
loadBundled().catch((e) => { $("#data-status").innerHTML = `<span class="pill warn">The bundled data could not load (${esc(e.message)}). Use "Load a newer export" to load the responses file.</span>`; console.error(e); });
loadStats().catch((e) => { $("#data-status").innerHTML = `<span class="pill warn">The statistics (data/stats.json) could not load: ${esc(e.message)}.</span>`; console.error(e); });
})();
+11 -18
View File
@@ -433,18 +433,10 @@
}
function drawTraffic(g) {
if (!st.runs) return;
const edges = new Map();
st.runs.forEach((r) => {
const seq = V.path(r);
for (let i = 1; i < seq.length; i++) {
const k = seq[i - 1] + ">" + seq[i];
edges.set(k, (edges.get(k) || 0) + 1);
}
});
const max = Math.max(1, ...edges.values());
[...edges.entries()].sort((a, b) => b[1] - a[1]).forEach(([k, n]) => {
const [a, b] = k.split(">");
// how many logged runs went from each place to the next (precomputed in data/stats.json)
if (!st.edges) return;
const max = Math.max(1, ...st.edges.map((e) => e[2]));
st.edges.forEach(([a, b, n]) => {
if (!L[a] || !L[b]) return;
el("path", { d: curve(L[a], L[b], 0.05), fill: "none", stroke: "#6b4a33", "stroke-opacity": 0.32, "stroke-width": 1.5 + 18 * Math.sqrt(n / max), "stroke-linecap": "round" }, g);
});
@@ -655,7 +647,7 @@
info = `<div class="ex-card"><span class="eyebrow">First sighting · ${dir === "Center" ? "forest centre" : dir.toLowerCase()}</span>
<p class="small">The first dragon is a roll of the dice: nobody bonds here, it decides what you face next.${fs ? ` Going ${dir === "Center" ? "to the forest centre" : dir.toLowerCase()}, riders met: ${Object.entries(fs).sort((a, b) => b[1] - a[1]).filter(([, p]) => p > 0.005).map(([k, p]) => `${k} ${pct(p)}`).join(", ")}.` : ""}</p></div>`;
}
return `<span class="eyebrow">Unofficial atlas · built from ${st.runs ? st.runs.length.toLocaleString() : "thousands of"} logged runs</span>
return `<span class="eyebrow">Unofficial atlas · built from ${st.nRuns ? st.nRuns.toLocaleString() : "thousands of"} logged runs</span>
<h2 id="h-valley">The valley</h2>
<p class="small muted">Every dragon is drawn where riders meet it. The fainter it is, the fewer riders reach it. Choose one to see its best route and the choices on it. Or click a key moment on the map, including the entrance, to see the choices you make there and your best chance at each dragon from it.</p>
${chooser()}${info}
@@ -852,10 +844,11 @@
if (wrap && !wrap.dataset.centred && wrap.scrollWidth > wrap.clientWidth) { wrap.scrollLeft = (wrap.scrollWidth - wrap.clientWidth) / 2; wrap.dataset.centred = "1"; }
}
function setRuns(state) {
st.runs = state.runs;
st.counts = {};
state.runs.forEach((r) => V.path(r).forEach((id) => (st.counts[id] = (st.counts[id] || 0) + 1)));
/** The runs selected on the page (one preset of data/stats.json): how many reached each place, and each step. */
function setStats(P) {
st.nRuns = P.analyse.n;
st.counts = P.valley.counts;
st.edges = P.valley.edges;
render();
}
@@ -867,6 +860,6 @@
render();
}).catch(() => { $("#ex-panel").innerHTML = '<p class="small muted">The route model (data/policy.json) could not be loaded.</p>'; });
}
window.ValleyExplorer = { setRuns, fromHash, state: st, render };
window.ValleyExplorer = { setStats, fromHash, state: st, render };
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init); else init();
})();
+16 -22
View File
@@ -58,9 +58,10 @@ section { display: grid; gap: 16px; scroll-margin-top: 16px; }
.controls { display: flex; flex-wrap: wrap; gap: 12px 22px; align-items: end; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ctl { display: grid; gap: 4px; min-width: 0; }
.ctl label, .ctl .lbl { font-size: var(--step--1); color: var(--muted); }
select, input[type="number"], button, .filebtn { font: inherit; font-size: var(--step--1); color: var(--ink); background: var(--raised); border: 1px solid var(--line); border-radius: 5px; padding: 6px 10px; }
select, input[type="number"], button, .filebtn, .btnlike { font: inherit; font-size: var(--step--1); color: var(--ink); background: var(--raised); border: 1px solid var(--line); border-radius: 5px; padding: 6px 10px; }
input[type="number"] { width: 5.5em; }
button, .filebtn { cursor: pointer; }
button, .filebtn, .btnlike { cursor: pointer; }
.btnlike { display: inline-block; text-decoration: none; }
button:hover, .filebtn:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible, .filebtn:focus-within, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
@@ -239,7 +240,7 @@ body { background: radial-gradient(140% 90% at 50% -10%, #2b0f1f 0%, var(--bg) 5
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; }
h2 { font-size: var(--step-2); letter-spacing: 0.04em; }
.panel h3, .truth h3, .gal-group h3, .loc-card h3 { font-family: var(--font-display); font-weight: 400; letter-spacing: 0.03em; }
button, .filebtn { border-radius: 999px; border: 1px solid color-mix(in srgb, var(--accent) 70%, transparent); background: color-mix(in srgb, var(--raised) 80%, #000); color: var(--ink); font-size: 0.74rem; padding: 8px 16px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35), 0 0 12px rgba(232,180,131,0.08); }
button, .filebtn, .btnlike { border-radius: 999px; border: 1px solid color-mix(in srgb, var(--accent) 70%, transparent); background: color-mix(in srgb, var(--raised) 80%, #000); color: var(--ink); font-size: 0.74rem; padding: 8px 16px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35), 0 0 12px rgba(232,180,131,0.08); }
button:hover, .filebtn:hover { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35), 0 0 14px rgba(232,180,131,0.25); }
button.primary { background: var(--accent); color: var(--accent-ink); }
select, input[type="number"], input[type="search"] { background: var(--raised) !important; color: var(--ink) !important; border: 1px solid var(--line) !important; border-radius: 8px !important; }
@@ -498,7 +499,7 @@ a { color: var(--accent); text-underline-offset: 2px; }
<div class="section-head">
<span class="eyebrow">Interactive</span>
<h2 id="h-map">Route map</h2>
<p class="muted small">Pick an outcome. Click any box to keep only the runs that passed through it, and click more boxes to narrow further. Hover or tap a box or band for its numbers.</p>
<p class="muted small">Pick an outcome to colour every step by how often runs through it reached that outcome. Hover or tap a box or band for its numbers. To follow one route step by step, use <a href="#valley">The Valley</a>.</p>
</div>
<div class="controls" id="map-controls">
<div class="target-group">
@@ -513,21 +514,15 @@ a { color: var(--accent); text-underline-offset: 2px; }
<div class="controls">
<div class="ctl"><span class="lbl">Band width shows</span>
<div class="seg" id="width-mode"><button type="button" data-v="traffic" aria-pressed="true">How many runs</button><button type="button" data-v="prob" aria-pressed="false">Chance of outcome</button></div></div>
<div class="ctl"><label for="minn">Grey out steps with fewer runs than</label><input id="minn" type="number" min="1" max="200" value="10"></div>
<div class="ctl"><label for="f-source">Data source</label>
<select id="f-source"><option value="all">All rows</option><option value="form">Form submissions only</option><option value="bulk">Bulk logs only (imports)</option></select></div>
<div class="ctl"><label for="f-goal">Players chasing</label>
<select id="f-goal"><option value="all">Any goal</option><option value="exclude_rare">Not chasing Blue/Black</option><option value="only_rare">Chasing Blue/Black</option></select></div>
<label class="check" for="f-flag"><input id="f-flag" type="checkbox"> Drop rows with data-quality flags</label>
<div class="ctl"><label for="minn">Grey out steps with fewer runs than</label><select id="minn"></select></div>
<div class="ctl"><label for="f-preset">Runs</label><select id="f-preset"></select></div>
</div>
<div class="map-shell deco">
<div class="map-top">
<div class="cond-chips" id="cond-chips"><span class="small muted">Showing all runs. Click a box to follow only the runs through it.</span></div>
<div class="btnrow"><button type="button" id="btn-best">Show top routes for this outcome</button><button type="button" id="btn-clear">Clear selection</button></div>
<div class="btnrow"><button type="button" id="btn-best">Show top routes for this outcome</button></div>
</div>
<div class="map-scroll"><svg id="map" role="img" aria-label="Route map"></svg></div>
<div class="map-foot">
<div class="sel-summary" id="sel-summary"></div>
<div class="legend" id="legend"></div>
</div>
</div>
@@ -580,7 +575,7 @@ a { color: var(--accent); text-underline-offset: 2px; }
<h2 id="h-routes">Route table</h2>
<p class="muted small">A route here means every choice up to the hour. Routes are ranked by the lower end of their 95% interval, so a route needs both a high rate and enough runs to rank high. Each route is compared with every other route that could reach the same outcome. "Adjusted" holds data source and chase goal fixed (Mantel–Haenszel). q-values correct for testing many routes at once.</p>
</div>
<div class="controls"><div class="ctl"><label for="rt-target">Outcome</label><select id="rt-target"></select></div><div class="ctl"><label for="rt-min">Minimum runs per route</label><input id="rt-min" type="number" min="1" max="200" value="10"></div><p class="small muted" id="rt-note" style="align-self:center"></p></div>
<div class="controls"><div class="ctl"><label for="rt-target">Outcome</label><select id="rt-target"></select></div><div class="ctl"><label for="rt-min">Minimum runs per route</label><select id="rt-min"></select></div><p class="small muted" id="rt-note" style="align-self:center"></p></div>
<div class="tbl-wrap" id="tbl-routes"></div>
</section>
<section id="factors" aria-labelledby="h-factors">
@@ -608,18 +603,18 @@ a { color: var(--accent); text-underline-offset: 2px; }
<section id="data-sec" aria-labelledby="h-data">
<div class="section-head"><span class="eyebrow">Where the numbers come from</span><h2 id="h-data">Data</h2></div>
<div class="data-status" id="data-status"><span class="loading">Loading data…</span></div>
<div class="btnrow"><label class="filebtn" for="upload">Load a newer route export…<input id="upload" type="file" accept=".xlsx,.csv" hidden></label><button id="btn-reset-data" type="button" hidden>Back to bundled data</button></div>
<p class="small muted">The data refresh every day from the community sources. Every number on this page is computed in Python (<code>analysis/stats/site_stats.py</code>) from the coded runs and published as <a href="data/stats.json">data/stats.json</a>; the coded runs themselves are <a href="data/runs_clean.csv" download>data/runs_clean.csv</a>.</p>
</section>
<section id="share" aria-labelledby="h-share">
<div class="section-head"><span class="eyebrow">Open by design</span><h2 id="h-share">Share &amp; reproduce</h2>
<p class="muted small">Everything on this page is recomputed in your browser from the raw form export. To update it, download the latest responses sheet (File → Download → Microsoft Excel) and load it with "Load a newer route export" above. Column order does not matter, because questions are matched by their wording.</p></div>
<p class="muted small">Everything on this page is computed from the community form export by the code in the <a href="https://github.com/ekcSchiano/threshing-atlas" target="_blank" rel="noopener">GitHub repository</a>, which updates the data every day. The rules for reading each answer are in <code>core/spec/form.yaml</code>, the game in <code>core/spec/game.yaml</code>, and what is measured in <code>analysis/stats/measures.yaml</code>.</p></div>
<div class="grid2">
<div class="panel"><h3>Copy the outputs</h3>
<div class="btnrow"><button type="button" id="cp-reddit" class="primary">Copy Reddit post (Markdown)</button><button type="button" id="cp-csv">Copy coded runs (CSV)</button><button type="button" id="cp-json">Copy all results (JSON)</button></div>
<p class="small muted">The Reddit post is written from the current numbers and filters.</p></div>
<div class="btnrow"><button type="button" id="cp-reddit" class="primary">Copy Reddit post (Markdown)</button><a class="btnlike" href="data/runs_clean.csv" download>Download coded runs (CSV)</a><button type="button" id="cp-json">Copy all results (JSON)</button></div>
<p class="small muted">The Reddit post is written from the numbers for the runs selected above.</p></div>
<div class="panel"><h3>Read the code</h3>
<div class="btnrow"><button type="button" data-src="engine.js">engine.js (all rules and statistics)</button><button type="button" data-src="app.js">app.js (this page)</button><button type="button" data-src="python/coding.py">coding.py</button><button type="button" data-src="python/form.yaml">form.yaml (every answer's meaning)</button><button type="button" data-src="python/analyze.py">analyze.py</button><button type="button" data-src="python/stats_core.py">stats_core.py</button><button type="button" data-src="solver.js">solver.js (best routes)</button><button type="button" data-src="explorer.js">explorer.js (the valley map)</button><button type="button" data-src="register.js">register.js</button><button type="button" data-src="README.md">README</button></div>
<p class="small muted">The Python files are an independent second implementation. The test scripts confirm that both produce identical coded runs and identical odds ratios, p-values and model estimates.</p>
<div class="btnrow"><button type="button" data-src="python/form.yaml">form.yaml (every answer's meaning)</button><button type="button" data-src="python/coding.py">coding.py (the coding rules)</button><button type="button" data-src="python/measures.yaml">measures.yaml (what is measured)</button><button type="button" data-src="python/site_stats.py">site_stats.py (every number on this page)</button><button type="button" data-src="python/stats_core.py">stats_core.py</button><button type="button" data-src="app.js">app.js (this page)</button><button type="button" data-src="solver.js">solver.js (best routes)</button><button type="button" data-src="explorer.js">explorer.js (the valley map)</button><button type="button" data-src="register.js">register.js</button><button type="button" data-src="README.md">README</button></div>
<p class="small muted">The page itself computes nothing: it displays the numbers the Python code publishes. Tests in the repository check every rule and every number.</p>
<pre id="srcview" hidden></pre></div>
</div>
</section>
@@ -628,7 +623,7 @@ a { color: var(--accent); text-underline-offset: 2px; }
<div class="mtabs" role="tablist" aria-label="Methods"><button type="button" role="tab" class="mtab" id="mt-0" aria-controls="mt-0-panel" aria-selected="true" tabindex="0">1. Runs</button><button type="button" role="tab" class="mtab" id="mt-1" aria-controls="mt-1-panel" aria-selected="false" tabindex="-1">2. Rates</button><button type="button" role="tab" class="mtab" id="mt-2" aria-controls="mt-2-panel" aria-selected="false" tabindex="-1">3. Comparisons</button><button type="button" role="tab" class="mtab" id="mt-3" aria-controls="mt-3-panel" aria-selected="false" tabindex="-1">4. Reporting bias</button><button type="button" role="tab" class="mtab" id="mt-4" aria-controls="mt-4-panel" aria-selected="false" tabindex="-1">5. Limits</button><button type="button" role="tab" class="mtab" id="mt-5" aria-controls="mt-5-panel" aria-selected="false" tabindex="-1">6. Best routes</button><button type="button" role="tab" class="mtab" id="mt-6" aria-controls="mt-6-panel" aria-selected="false" tabindex="-1">Missing answers</button></div>
<div class="mpanel method" role="tabpanel" id="mt-0-panel" aria-labelledby="mt-0">
<h3>1. From form answers to runs</h3>
<p>Each row of the <a href="https://docs.google.com/spreadsheets/d/1gnw1AdRg1XT4JsOfRM6QTA0jSaS3n9ZF-rPWnYewzv0" target="_blank" rel="noopener">"Threshing Routes" form</a> (and each row pasted in from players' own logs) is one threshing run. The page reads the raw export and codes every row with the same fixed rules, which are visible in <code>engine.js</code>:</p>
<p>Each row of the <a href="https://docs.google.com/spreadsheets/d/1gnw1AdRg1XT4JsOfRM6QTA0jSaS3n9ZF-rPWnYewzv0" target="_blank" rel="noopener">"Threshing Routes" form</a> (and each row pasted in from players' own logs) is one threshing run. Every row is coded with the same fixed rules, written down in <code>core/spec/form.yaml</code> and <code>core/atlas/coding.py</code> (both viewable under Share &amp; reproduce):</p>
<ul>
<li><b>Source.</b> Rows with a real timestamp are form submissions. Rows labelled "Data Import", "Manual Upload" or "Historical import" were bulk-pasted from players' own run logs and are called <i>bulk logs</i> here.</li>
<li><b>Leaving your squadmates.</b> The form only offered "&gt; Left them" from 27 October 2026. Squad runs before that date, or without a date, are coded as unknown rather than as "stayed together".</li>
@@ -695,7 +690,6 @@ adjusted OR = exp(βⱼ), 95% CI = exp(βⱼ ± 1.96·SEⱼ)</div>
<p><b>Unofficial fan analysis,</b> not affiliated with <a href="https://dragonkind.com" target="_blank" rel="noopener">Dragonkind</a> or its authors. A 10% "chaos" chance of incineration on any choice has been described by the author, so <b>no route guarantees a bond</b>.</p></div></footer>
<div id="tip" hidden></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script src="engine.js"></script>
<script src="solver.js"></script>
<script src="register.js"></script>
<script src="app.js"></script>
+4 -10
View File
@@ -185,15 +185,9 @@
const tag = (txt) => `<span class="how">${txt}</span>`;
// A cadet who walks in and either dies or bonds. Deliberate deaths are left out: a rider burned at a bonding
// encounter they did not genuinely attempt (they were after another colour and planned to seek Malek). Runs with
// no recorded outcome are left out too. Same rule the solver uses for encounter odds (ThreshSolver.genuineAttempt).
const S = window.ThreshSolver;
const ended = state.runs.filter((x) => ["Bonded", "Incinerated", "Died before the hour"].includes(x.outcome));
const deliberate = (x) => { if (x.outcome !== "Incinerated" || !S) return false; const v = S.prepareRun(x); return !!v.encCtx && !S.genuineAttempt(x, v.encCtx); };
const cadets = ended.filter((x) => !deliberate(x));
const nDeliberate = ended.length - cadets.length;
const bonded = cadets.filter((x) => x.outcome === "Bonded").length;
const dead = cadets.length - bonded;
const earlyDeaths = cadets.filter((x) => x.outcome === "Died before the hour").length;
// no recorded outcome are left out too. Same rule the route model uses for encounter odds (precomputed in Python).
const O = state.P.overview;
const cadets = { length: O.cadets }, nDeliberate = O.deliberate, bonded = O.bonded, dead = O.dead, earlyDeaths = O.early_deaths;
const cards = [
{ c: "--accent", big: pct(bonded / cadets.length), what: "become a rider", how: `${bonded.toLocaleString()} of ${cadets.length.toLocaleString()} cadets bonded a dragon. ${pct(1 - earlyDeaths / cadets.length)} made it to the tree-or-valley choice alive.`, w: { k: bonded, n: cadets.length } },
{ c: "--death", big: dead.toLocaleString(), what: "riders sent to Malek", how: `${pct(dead / cadets.length)} of cadets were burned or killed. Deliberate deaths (${nDeliberate.toLocaleString()} runs where the rider chose to die and try again) are not counted.`, w: { k: dead, n: cadets.length }, death: true },
@@ -240,7 +234,7 @@
window.AtlasUI = {
render(state) {
renderOverview(state);
if (window.ValleyExplorer) window.ValleyExplorer.setRuns(state);
if (window.ValleyExplorer) window.ValleyExplorer.setStats(state.P);
},
showTab,
};
+5 -212
View File
@@ -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 };
})();