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
@@ -29,6 +29,7 @@ jobs:
|
||||
run: |
|
||||
node analysis/network/build-graph.js
|
||||
npm run policy
|
||||
npm run stats
|
||||
npm test
|
||||
# The PR is opened with ATLAS_BOT_TOKEN (a fine-grained token, see docs/REPO_SETTINGS.md) when it is set:
|
||||
# changes made with the built-in GITHUB_TOKEN do not start other workflows, so its merge would not
|
||||
|
||||
@@ -4,6 +4,8 @@ Making sense of the data.
|
||||
|
||||
| Folder | What it does |
|
||||
|---|---|
|
||||
| `stats/measures.yaml` | **Declarative.** What the site measures: outcomes and their denominators, route targets and comparison groups, the bonding-encounter contexts, the route map's stages, the filter presets and the route thresholds. |
|
||||
| `stats/site_stats.py` | Computes every number the Atlas page shows for every preset and writes `data/public/stats.json`; the page computes nothing itself. `tests/parity/compare_stats.py` checks it against the old in-browser engine until that is removed. |
|
||||
| `stats/` | General statistics in Python (`analyze.py`, `stats_core.py`): rates with Wilson intervals, odds ratios with Fisher's test and Benjamini–Hochberg, ridge logistic models that adjust for data source and chase goal. `core/engine.js` computes the same numbers for the site, and `tests/parity/` checks they match. |
|
||||
| `network/` | `build-graph.js` combines every source into `data/public/graph.json` (the decision-variable graph and the bot's scene graph). CI fails if the committed graph is out of date. |
|
||||
| `reports/` | Generated reports. `POLICY.md` is written by `planner/policy_report.py`; do not edit it by hand. |
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
# What the site measures: outcomes and their denominators, route targets and their comparison groups, the
|
||||
# bonding-encounter contexts, the stages of the route map, the filter presets and the minimum-run thresholds.
|
||||
# analysis/stats/site_stats.py reads this file and writes data/public/stats.json, which the page only displays.
|
||||
#
|
||||
# Conditions: {field: value} means equal; {field: {in: [...]}}, {field: {not: value}}, {field: {exists: true}}
|
||||
# (not blank), {any: [condition, ...]} (at least one). Several fields in one condition must all hold.
|
||||
version: 1
|
||||
|
||||
colours: [Red, Green, Orange, Brown, Blue, Black]
|
||||
|
||||
# Outcomes for the factor tables and models: who could have had the outcome (denom), and the outcome (event).
|
||||
outcomes:
|
||||
blue_meadow:
|
||||
label: Blue appears in the meadow
|
||||
denom: { branch: "Passed the Red: meadow" }
|
||||
event: { saw_blue_meadow: true }
|
||||
shadow:
|
||||
label: Shadow option appears at the tree
|
||||
denom: { hour: Tree, branch: { exists: true } }
|
||||
event: { saw_shadow: true }
|
||||
bond_blue_meadow:
|
||||
label: Bond, given you approached the meadow Blue
|
||||
denom: { branch: "Passed the Red: meadow", enc_Blue: { in: ["Bonded!", "Incinerated"] } }
|
||||
event: { enc_Blue: "Bonded!" }
|
||||
reach_hour:
|
||||
label: Survive to the hour (tree/valley choice)
|
||||
denom: {}
|
||||
event: { hour: { in: [Tree, Valley] } }
|
||||
# one more outcome per colour: "Run ends bonded to <colour>", among runs that reached the hour
|
||||
bonded_outcome:
|
||||
label: Run ends bonded to {colour}
|
||||
denom: { hour: { in: [Tree, Valley] } }
|
||||
event: { outcome: Bonded, outcome_color: "{colour}" }
|
||||
|
||||
# Factors compared in the factor tables (each answer against the other answers to the same question)
|
||||
factors: [company, direction, first_sighting, scream, resolution, combat_first, post_path, hour, wing, squad,
|
||||
attempt_group, source, goal, sighting_action, combat_second, malek_intent]
|
||||
|
||||
# Route targets: the outcome (event) and which runs could have reached it at all (pool)
|
||||
targets:
|
||||
bond_Blue: { label: Bond Blue, colour: Blue, event: { outcome: Bonded, outcome_color: Blue }, pool: { hour: Valley } }
|
||||
bond_Black: { label: Bond Black, colour: Black, event: { outcome: Bonded, outcome_color: Black }, pool: { hour: Tree } }
|
||||
see_Blue: { label: Meet a Blue (meadow), colour: Blue, event: { saw_blue_meadow: true }, pool: { branch: "Passed the Red: meadow" } }
|
||||
see_shadow: { label: Get the tree shadow, colour: Black, event: { saw_shadow: true }, pool: { hour: Tree, branch: { exists: true } } }
|
||||
bond_Red: { label: Bond Red, colour: Red, event: { outcome: Bonded, outcome_color: Red }, pool: { hour: { in: [Tree, Valley] } } }
|
||||
bond_Green: { label: Bond Green, colour: Green, event: { outcome: Bonded, outcome_color: Green }, pool: { hour: Tree } }
|
||||
bond_Orange: { label: Bond Orange, colour: Orange, event: { outcome: Bonded, outcome_color: Orange }, pool: { hour: { in: [Tree, Valley] } } }
|
||||
bond_Brown: { label: Bond Brown, colour: Brown, event: { outcome: Bonded, outcome_color: Brown }, pool: { hour: { in: [Tree, Valley] } } }
|
||||
bond_any: { label: Bond any dragon, colour: null, event: { outcome: Bonded }, pool: { hour: { in: [Tree, Valley] } } }
|
||||
|
||||
# Bonding encounters: which recorded attempt (column) belongs to which in-game encounter (where)
|
||||
encounters:
|
||||
- { context: "Red (tree, descend quickly)", colour: Red, column: enc_Red, where: { hour: Tree, branch: "Descend quickly: Red" } }
|
||||
- { context: "Green (two Greens)", colour: Green, column: enc_Green, where: { hour: Tree, any: [ { branch: "Descend slowly: two Greens" }, { branch: "Descend quickly: let the Red pass" } ] } }
|
||||
- { context: "Blue (shadow)", colour: Blue, column: enc_Blue, where: { hour: Tree, branch: "Shadow (rare)" } }
|
||||
- { context: "Black (shadow)", colour: Black, column: enc_Black, where: { hour: Tree, branch: "Shadow (rare)" } }
|
||||
- { context: "Red (valley)", colour: Red, column: enc_Red, where: { hour: Valley, branch: Valley Red } }
|
||||
- { context: "Orange (meadow)", colour: Orange, column: enc_Orange, where: { hour: Valley, branch: "Passed the Red: meadow" } }
|
||||
- { context: "Brown (meadow)", colour: Brown, column: enc_Brown, where: { hour: Valley, branch: "Passed the Red: meadow" } }
|
||||
- { context: "Blue (meadow)", colour: Blue, column: enc_Blue, where: { hour: Valley, branch: "Passed the Red: meadow" } }
|
||||
|
||||
# The route map's columns, in order. "chance": steps the game rolls, not the rider.
|
||||
stages:
|
||||
- { key: company, label: Company }
|
||||
- { key: direction, label: Direction }
|
||||
- { key: first_sighting, label: First sighting, chance: true }
|
||||
- { key: cadet, label: Cadet encounter }
|
||||
- { key: post_path, label: Fork in the road }
|
||||
- { key: hour, label: After an hour }
|
||||
- { key: encounter, label: Encounter, chance: true }
|
||||
- { key: end, label: Outcome }
|
||||
|
||||
# Filter presets: the page shows one at a time (no statistics are computed in the browser)
|
||||
presets:
|
||||
all: { label: All runs, filters: { source: all, goal: all, excludeFlagged: false } }
|
||||
form: { label: Form submissions only, filters: { source: form, goal: all, excludeFlagged: false } }
|
||||
bulk: { label: Bulk logs only (imports), filters: { source: bulk, goal: all, excludeFlagged: false } }
|
||||
not_chasing: { label: Not chasing Blue/Black, filters: { source: all, goal: exclude_rare, excludeFlagged: false } }
|
||||
chasing: { label: Chasing Blue/Black, filters: { source: all, goal: only_rare, excludeFlagged: false } }
|
||||
unflagged: { label: Rows without data-quality flags, filters: { source: all, goal: all, excludeFlagged: true } }
|
||||
|
||||
# Minimum runs a full route needs before it is ranked (q-values are corrected within each threshold)
|
||||
route_thresholds: [5, 10, 20, 30]
|
||||
|
||||
rare_goals: [Blue, Black, Blue or Black]
|
||||
@@ -0,0 +1,530 @@
|
||||
"""Every number the Atlas page shows, precomputed: data/public/stats.json.
|
||||
|
||||
The page only displays these; it computes no statistics itself. What is measured (outcomes, route targets,
|
||||
encounters, the route map's stages, the filter presets and route thresholds) is declared in measures.yaml.
|
||||
|
||||
python analysis/stats/site_stats.py [--out data/public/stats.json]
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import math
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
ROOT = HERE.parents[1]
|
||||
sys.path.insert(0, str(ROOT / "core"))
|
||||
sys.path.insert(0, str(HERE))
|
||||
from atlas import coding, model # noqa: E402
|
||||
from stats_core import Z95, bh, logistic_ridge, mantel_haenszel, odds_ratio, p_from_z # noqa: E402
|
||||
from stats_core import wilson as _wilson # noqa: E402
|
||||
|
||||
M = yaml.safe_load(open(HERE / "measures.yaml", encoding="utf-8"))
|
||||
COLOURS = M["colours"]
|
||||
is_missing = coding.is_missing
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- conditions from measures.yaml
|
||||
|
||||
def match(r, cond):
|
||||
for k, want in cond.items():
|
||||
if k == "any":
|
||||
if not any(match(r, c) for c in want):
|
||||
return False
|
||||
continue
|
||||
v = r.get(k)
|
||||
if isinstance(want, dict):
|
||||
if "in" in want and v not in want["in"]:
|
||||
return False
|
||||
if "not" in want and v == want["not"]:
|
||||
return False
|
||||
if "exists" in want and (v is not None and v != "") != want["exists"]:
|
||||
return False
|
||||
elif v != want:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _fill(cond, colour):
|
||||
return json.loads(json.dumps(cond).replace("{colour}", colour))
|
||||
|
||||
|
||||
OUTCOMES = {k: v for k, v in M["outcomes"].items()}
|
||||
for c in COLOURS:
|
||||
b = M["bonded_outcome"]
|
||||
OUTCOMES["bonded_" + c] = {"label": b["label"].replace("{colour}", c), "denom": b["denom"], "event": _fill(b["event"], c)}
|
||||
TARGETS = M["targets"]
|
||||
STAGES = M["stages"]
|
||||
|
||||
|
||||
def W(k, n):
|
||||
p, lo, hi = _wilson(k, n)
|
||||
return {"k": int(k), "n": int(n), "p": p, "lo": lo, "hi": hi}
|
||||
|
||||
|
||||
def rate(runs, pred):
|
||||
return W(sum(1 for r in runs if pred(r)), len(runs))
|
||||
|
||||
|
||||
def group_by(runs, key):
|
||||
out = {}
|
||||
for r in runs:
|
||||
k = key(r) if callable(key) else r.get(key)
|
||||
out.setdefault(_key(k), []).append(r)
|
||||
return out
|
||||
|
||||
|
||||
def _key(v):
|
||||
"""Object keys as JavaScript writes them (true/false/null), so the page can look them up as before."""
|
||||
if v is True:
|
||||
return "true"
|
||||
if v is False:
|
||||
return "false"
|
||||
if v is None:
|
||||
return "null"
|
||||
if isinstance(v, float) and v.is_integer():
|
||||
return str(int(v))
|
||||
return str(v)
|
||||
|
||||
|
||||
def is_rare(goal):
|
||||
return goal in M["rare_goals"]
|
||||
|
||||
|
||||
def stratum(r):
|
||||
if r["source"] != "Form":
|
||||
return "Bulk logs (imports)"
|
||||
g = r["goal"]
|
||||
return {"Blue": "Form: chasing Blue", "Black": "Form: chasing Black", "Blue or Black": "Form: chasing Blue or Black"}.get(g, "Form: other/blank goal")
|
||||
|
||||
|
||||
def goal2(r):
|
||||
return r["goal"] if is_rare(r["goal"]) else "Blank/not asked" if r["goal"] == "(not asked/blank)" else "Other colour/any"
|
||||
|
||||
|
||||
def apply_filters(runs, f):
|
||||
def ok(r):
|
||||
if f.get("source") == "form" and r["source"] != "Form":
|
||||
return False
|
||||
if f.get("source") == "bulk" and r["source"] == "Form":
|
||||
return False
|
||||
if f.get("goal") == "exclude_rare" and is_rare(r["goal"]):
|
||||
return False
|
||||
if f.get("goal") == "only_rare" and not is_rare(r["goal"]):
|
||||
return False
|
||||
if f.get("excludeFlagged") and r["data_flags"]:
|
||||
return False
|
||||
return True
|
||||
return [r for r in runs if ok(r)]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- tables and models
|
||||
|
||||
def odds(a, b, c, d):
|
||||
or_, lo, hi, p, corr = odds_ratio(a, b, c, d)
|
||||
return {"or": or_, "or_lo": lo, "or_hi": hi, "fisher_p": p, "corrected": corr}
|
||||
|
||||
|
||||
def factor_table(runs, key, min_n=5):
|
||||
O = OUTCOMES[key]
|
||||
D = [r for r in runs if match(r, O["denom"])]
|
||||
ev = lambda r: match(r, O["event"]) # noqa: E731
|
||||
rows, missing = [], {}
|
||||
for f in M["factors"]:
|
||||
known = [r for r in D if not is_missing(r.get(f))]
|
||||
missing[f] = len(D) - len(known)
|
||||
groups = group_by(known, f)
|
||||
nf, ef = len(known), sum(1 for r in known if ev(r))
|
||||
for lv in sorted(groups):
|
||||
g = groups[lv]
|
||||
k, n = sum(1 for r in g if ev(r)), len(g)
|
||||
row = {"factor": f, "level": lv, **W(k, n)}
|
||||
rk, rn = ef - k, nf - n
|
||||
if n >= min_n and rn >= min_n and 0 < ef < nf:
|
||||
row.update(odds(k, n - k, rk, rn - rk))
|
||||
rows.append(row)
|
||||
tested = [r for r in rows if "fisher_p" in r]
|
||||
for r, q in zip(tested, bh([r["fisher_p"] for r in tested])):
|
||||
r["q"] = q
|
||||
return {"outcome": key, "label": O["label"], "overall": W(sum(1 for r in D if ev(r)), len(D)), "rows": rows, "missing": missing}
|
||||
|
||||
|
||||
def fit_model(runs, key, factors, lam=1.0):
|
||||
import numpy as np
|
||||
O = OUTCOMES[key]
|
||||
D = []
|
||||
for r in runs:
|
||||
if not match(r, O["denom"]):
|
||||
continue
|
||||
o = {"y": 1 if match(r, O["event"]) else 0, **{name: fn(r) for name, fn in factors.items()}}
|
||||
if all(o[f] is not None for f in factors):
|
||||
D.append(o)
|
||||
if len(D) < 20:
|
||||
return None
|
||||
cols, names, refs = [np.ones(len(D))], [], {}
|
||||
for f in factors:
|
||||
counts = group_by(D, f)
|
||||
levels = sorted(counts, key=lambda lv: (-len(counts[lv]), lv))
|
||||
refs[f] = levels[0]
|
||||
for lv in levels[1:]:
|
||||
cols.append(np.array([1.0 if _key(o[f]) == lv else 0.0 for o in D]))
|
||||
names.append((f, lv, len(counts[lv])))
|
||||
y = np.array([o["y"] for o in D])
|
||||
b, se = logistic_ridge(np.column_stack(cols), y, lam)
|
||||
terms = [{"term": f"{f} = {lv}", "factor": f, "level": lv, "n": n, "or": math.exp(b[i + 1]),
|
||||
"lo": math.exp(b[i + 1] - Z95 * se[i + 1]), "hi": math.exp(b[i + 1] + Z95 * se[i + 1]),
|
||||
"p": float(p_from_z(b[i + 1] / se[i + 1]))} for i, (f, lv, n) in enumerate(names)]
|
||||
return {"outcome": key, "label": O["label"], "n": len(D), "events": int(y.sum()), "refs": refs, "lambda": lam, "terms": terms}
|
||||
|
||||
|
||||
def route_key(r):
|
||||
return [r["company"], r["direction"], r["first_sighting"], r["scream"], r["resolution"], r.get("post_path") or "—", r.get("hour") or "—"]
|
||||
|
||||
|
||||
def analyse(all_runs, filters):
|
||||
runs = apply_filters(all_runs, filters)
|
||||
res = {"filters": filters, "n": len(runs)}
|
||||
|
||||
flag_counts = {}
|
||||
for r in runs:
|
||||
for f in (r["data_flags"].split("; ") if r["data_flags"] else []):
|
||||
k = "first sighting outside documented pool" if f.startswith("first sighting") else f
|
||||
flag_counts[k] = flag_counts.get(k, 0) + 1
|
||||
dates = sorted(r["date"] for r in runs if r.get("date"))
|
||||
outs = group_by(runs, lambda r: r["outcome"] + (" " + r["outcome_color"] if r.get("outcome_color") else ""))
|
||||
res["meta"] = {
|
||||
"sources": {k: len(v) for k, v in group_by(runs, "source").items()},
|
||||
"date_min": dates[0] if dates else None, "date_max": dates[-1] if dates else None,
|
||||
"n_flagged": sum(1 for r in runs if r["data_flags"]), "flag_counts": flag_counts,
|
||||
"outcomes": {k: len(v) for k, v in outs.items()},
|
||||
}
|
||||
|
||||
res["chance"] = {}
|
||||
for key in ("blue_meadow", "shadow"):
|
||||
O = OUTCOMES[key]
|
||||
D = [r for r in runs if match(r, O["denom"])]
|
||||
ev = lambda r, O=O: match(r, O["event"]) # noqa: E731
|
||||
by = lambda k: {s: rate(g, ev) for s, g in sorted(group_by(D, k).items())} # noqa: E731
|
||||
form = [r for r in D if r["source"] == "Form"]
|
||||
res["chance"][key] = {"label": O["label"], "overall": rate(D, ev), "by_stratum": by(stratum), "by_goal": by("goal"),
|
||||
"by_attempt": by("attempt_group"), "form_overall": rate(form, ev)}
|
||||
|
||||
fs = group_by([r for r in runs if not is_missing(r["direction"]) and not is_missing(r["company"])], lambda r: r["company"] + "|" + r["direction"])
|
||||
res["first_sighting"] = [{"key": k, "n": len(g), "colors": {c: len(v) for c, v in sorted(group_by(g, "first_sighting").items())}}
|
||||
for k, g in sorted(fs.items())]
|
||||
|
||||
res["encounters"] = []
|
||||
for e in M["encounters"]:
|
||||
col, colour = e["column"], e["colour"]
|
||||
A = [r for r in runs if match(r, e["where"]) and r.get(col) in ("Bonded!", "Incinerated")]
|
||||
win = lambda r, col=col: r.get(col) == "Bonded!" # noqa: E731
|
||||
intent = [r for r in A if r["goal"] == colour or r["goal"].startswith("Any") or (r["goal"] == "Blue or Black" and colour in ("Blue", "Black"))]
|
||||
res["encounters"].append({"context": e["context"], "color": colour, "overall": rate(A, win), "intent_matched": rate(intent, win),
|
||||
"by_stratum": {s: rate(g, win) for s, g in sorted(group_by(A, stratum).items())}})
|
||||
greens_where = next(e["where"] for e in M["encounters"] if e["colour"] == "Green")
|
||||
greens = [r for r in runs if match(r, greens_where) and r.get("enc_Green")]
|
||||
g = {"green_encounters": len(greens),
|
||||
"bonded_green": sum(1 for r in greens if r["enc_Green"] == "Bonded!"),
|
||||
"rescued_orange": sum(1 for r in greens if r["rescued"] and r.get("outcome_color") == "Orange"),
|
||||
"rescued_brown": sum(1 for r in greens if r["rescued"] and r.get("outcome_color") == "Brown"),
|
||||
"incinerated": sum(1 for r in greens if r["outcome"] == "Incinerated")}
|
||||
g["no_outcome"] = g["green_encounters"] - g["bonded_green"] - g["rescued_orange"] - g["rescued_brown"] - g["incinerated"]
|
||||
g["rates"] = {k: W(g[k], g["green_encounters"]) for k in ("bonded_green", "rescued_orange", "rescued_brown", "incinerated", "no_outcome")}
|
||||
res["green_rescue"] = g
|
||||
|
||||
res["factors"] = {k: factor_table(runs, k) for k in OUTCOMES}
|
||||
|
||||
first2 = lambda r: r["first_sighting"] if r["first_sighting"] in ("Red", "Brown", "Orange", "Green") else None # noqa: E731
|
||||
known = lambda f: (lambda r: None if is_missing(r.get(f)) else r[f]) # noqa: E731
|
||||
src2 = lambda r: "Form submission" if r["source"] == "Form" else "Bulk log (import)" # noqa: E731
|
||||
res["models"] = {
|
||||
"blue_meadow": fit_model(runs, "blue_meadow", {"source": src2, "goal": goal2, "direction": known("direction"),
|
||||
"first_sighting": first2, "resolution": known("resolution"), "company": known("company")}),
|
||||
"shadow": fit_model(runs, "shadow", {"source": src2, "goal": goal2, "attempt": known("attempt_group"), "direction": known("direction")}),
|
||||
"bond_blue_meadow": fit_model(runs, "bond_blue_meadow", {"source": src2, "goal": goal2, "direction": known("direction"), "resolution": known("resolution")}),
|
||||
}
|
||||
|
||||
res["daily"] = []
|
||||
for d, gr in sorted(group_by([r for r in runs if r.get("date")], "date").items()):
|
||||
m = [r for r in gr if match(r, OUTCOMES["blue_meadow"]["denom"])]
|
||||
t = [r for r in gr if match(r, OUTCOMES["shadow"]["denom"])]
|
||||
bk, sk = sum(1 for r in m if r["saw_blue_meadow"]), sum(1 for r in t if r["saw_shadow"])
|
||||
res["daily"].append({"date": d, "runs": len(gr), "meadow_n": len(m), "blue_k": bk, "tree_n": len(t), "shadow_k": sk,
|
||||
"blue": W(bk, len(m)), "shadow": W(sk, len(t))})
|
||||
|
||||
res["source_rates"] = {key: {s: rate([r for r in g if match(r, OUTCOMES[key]["denom"])], lambda r, k=key: match(r, OUTCOMES[k]["event"]))
|
||||
for s, g in group_by(runs, "source").items()} for key in ("blue_meadow", "shadow")}
|
||||
return res
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- route map and route rankings
|
||||
|
||||
def stage_value(r, key):
|
||||
if key in ("company", "direction", "post_path"):
|
||||
return None if is_missing(r.get(key)) else r[key]
|
||||
if key == "first_sighting":
|
||||
return None if r["scream"] == "DIED at first sighting" or is_missing(r["first_sighting"]) else r["first_sighting"]
|
||||
if key == "cadet":
|
||||
if r["scream"].startswith("DIED") or is_missing(r["scream"]) or is_missing(r["resolution"]):
|
||||
return None
|
||||
return "Help → " + r["resolution"] if r["scream"] == "Investigate & help" else r["scream"] + " → " + r["resolution"]
|
||||
if key == "hour":
|
||||
return "Climb the tree" if r.get("hour") == "Tree" else "Valley centre" if r.get("hour") == "Valley" else None
|
||||
if key == "encounter":
|
||||
if not r.get("branch"):
|
||||
return None
|
||||
if r["hour"] == "Tree":
|
||||
if r["branch"] == "Shadow (rare)":
|
||||
return "Tree: shadow → Blue/Black"
|
||||
if r["branch"] == "Descend quickly: Red":
|
||||
return "Tree: Red below"
|
||||
return "Tree: two Greens"
|
||||
if r["branch"] == "Valley Red":
|
||||
return "Valley: bond the Red"
|
||||
for cond, label in ((r.get("enc_Blue"), "Meadow: Blue"), (r.get("enc_Orange") and r.get("enc_Brown"), "Meadow: Orange/Brown"),
|
||||
(r.get("enc_Orange"), "Meadow: Orange"), (r.get("enc_Brown"), "Meadow: Brown")):
|
||||
if cond:
|
||||
return label
|
||||
return "Meadow (no attempt recorded)"
|
||||
if key == "end":
|
||||
if r["outcome"] == "Bonded":
|
||||
return "Bonded " + r["outcome_color"]
|
||||
if r["outcome"] in ("Incinerated", "Died before the hour"):
|
||||
return r["outcome"]
|
||||
return None
|
||||
|
||||
|
||||
def route_map(runs):
|
||||
"""The route map: nodes and links with run counts, and for every target the hits and their Wilson interval."""
|
||||
nodes, links = {}, {}
|
||||
hits = {t: {} for t in TARGETS}
|
||||
for r in runs:
|
||||
prev = None
|
||||
hit = {t: match(r, T["event"]) for t, T in TARGETS.items()}
|
||||
for si, s in enumerate(STAGES):
|
||||
v = stage_value(r, s["key"])
|
||||
if v is None:
|
||||
continue
|
||||
nid = f"{si}|{v}"
|
||||
nd = nodes.setdefault(nid, {"id": nid, "stage": si, "stageKey": s["key"], "value": v, "n": 0})
|
||||
nd["n"] += 1
|
||||
for t in TARGETS:
|
||||
hits[t][nid] = hits[t].get(nid, 0) + hit[t]
|
||||
if prev:
|
||||
lid = prev + "→" + nid
|
||||
ln = links.setdefault(lid, {"id": lid, "source": prev, "target": nid, "n": 0, "chance": bool(s.get("chance"))})
|
||||
ln["n"] += 1
|
||||
for t in TARGETS:
|
||||
hits[t][lid] = hits[t].get(lid, 0) + hit[t]
|
||||
prev = nid
|
||||
nl, ll = list(nodes.values()), list(links.values())
|
||||
by_target = {t: {"nodes": [W(hits[t][n["id"]], n["n"]) for n in nl], "links": [W(hits[t][l["id"]], l["n"]) for l in ll]} for t in TARGETS}
|
||||
return {"nodes": nl, "links": ll, "by_target": by_target}
|
||||
|
||||
|
||||
def rank_routes(runs, target, thresholds):
|
||||
"""Full routes (every choice up to the hour), ranked for one target. Each route with at least min_n runs is
|
||||
compared with all other runs that could reach the target (Fisher), and within data-source / chase-goal strata
|
||||
(Mantel-Haenszel). q-values are corrected within each threshold. Ranked by the lower end of the 95% interval."""
|
||||
T = TARGETS[target]
|
||||
ev = lambda r: match(r, T["event"]) # noqa: E731
|
||||
key_stages = [s["key"] for s in STAGES[:6]]
|
||||
pool = [r for r in runs if match(r, T["pool"])]
|
||||
tot_k, tot_n = sum(1 for r in pool if ev(r)), len(pool)
|
||||
full = [r for r in pool if all(stage_value(r, k) or (k == "post_path" and r.get("post_path") is None) for k in key_stages)]
|
||||
groups = group_by(full, lambda r: " › ".join(stage_value(r, k) or "—" for k in key_stages))
|
||||
strata = list(group_by(pool, stratum).values())
|
||||
rows = []
|
||||
for key, g in groups.items():
|
||||
if len(g) < min(thresholds):
|
||||
continue
|
||||
k, n = sum(1 for r in g if ev(r)), len(g)
|
||||
o = {"route": key, "values": [stage_value(g[0], s) for s in key_stages], **W(k, n)}
|
||||
o.update(odds(k, n - k, tot_k - k, tot_n - n - (tot_k - k)))
|
||||
ids = {id(r) for r in g}
|
||||
tabs = []
|
||||
for sg in strata:
|
||||
a = sum(1 for r in sg if id(r) in ids and ev(r))
|
||||
nin = sum(1 for r in sg if id(r) in ids)
|
||||
c = sum(1 for r in sg if id(r) not in ids and ev(r))
|
||||
tabs.append([a, nin - a, c, len(sg) - nin - c])
|
||||
mh = mantel_haenszel(tabs)
|
||||
o.update(dict(zip(("mh_or", "mh_lo", "mh_hi", "mh_p"), mh)) if mh else {"mh_or": None, "mh_lo": None, "mh_hi": None, "mh_p": None})
|
||||
rows.append(o)
|
||||
rows.sort(key=lambda r: (-r["lo"], -r["n"]))
|
||||
out = {"target": target, "overall": W(tot_k, tot_n), "rows": rows, "by_threshold": {}}
|
||||
for m in thresholds:
|
||||
idx = [i for i, r in enumerate(rows) if r["n"] >= m]
|
||||
q = bh([rows[i]["fisher_p"] for i in idx])
|
||||
mi = [i for i in idx if rows[i]["mh_p"] is not None]
|
||||
mq = bh([rows[i]["mh_p"] for i in mi])
|
||||
out["by_threshold"][str(m)] = {"n_routes_tested": len(idx), "q": {str(i): v for i, v in zip(idx, q)},
|
||||
"mh_q": {str(i): v for i, v in zip(mi, mq)}}
|
||||
return out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- the valley map and the summary cards
|
||||
|
||||
def place_ids():
|
||||
"""The places drawn on the valley map (the keys of L in site/atlas/valley.js)."""
|
||||
src = (ROOT / "site/atlas/valley.js").read_text(encoding="utf-8")
|
||||
body = src[src.index("const L = {"):]
|
||||
body = body[:body.index("\n };")]
|
||||
return set(re.findall(r'^\s{4}"?([^":{}\n]+(?::[^":{}\n]+)*)"?:\s*\{\s*x:', body, re.M))
|
||||
|
||||
|
||||
PLACES = None
|
||||
|
||||
|
||||
def place_path(r):
|
||||
"""The places a run passed through, as drawn on the valley map (mirrors path() in valley.js)."""
|
||||
L = PLACES
|
||||
s = []
|
||||
if "comp:" + str(r["company"]) in L:
|
||||
s.append("comp:" + r["company"])
|
||||
if r["direction"] not in ("East", "West", "Center"):
|
||||
return s
|
||||
s.append("dir:" + r["direction"])
|
||||
sight = f"see:{r['direction']}:{r['first_sighting']}"
|
||||
if sight in L:
|
||||
s.append(sight)
|
||||
if r["scream"] in ("DIED at first sighting", "Unknown"):
|
||||
return s
|
||||
s.append("scream")
|
||||
if r["scream"] == "Investigate & help":
|
||||
s.append("bully")
|
||||
if "res:" + r["resolution"] in L:
|
||||
s.append("res:" + r["resolution"])
|
||||
if r["resolution"].startswith("DIED"):
|
||||
return s
|
||||
if r.get("post_path") in ("Forest", "West", "East"):
|
||||
s.append("fork:" + r["post_path"])
|
||||
elif r["scream"] == "Ignore the scream":
|
||||
s.append("wounded")
|
||||
if "res:" + r["resolution"] in L:
|
||||
s.append("res:" + r["resolution"])
|
||||
elif r["scream"] == "Investigate & leave":
|
||||
s.append("away")
|
||||
if r.get("hour") not in ("Tree", "Valley"):
|
||||
return s
|
||||
s.append("hour")
|
||||
b = r.get("branch")
|
||||
if r["hour"] == "Tree":
|
||||
s.append("tree")
|
||||
if b == "Descend quickly: Red":
|
||||
s.append("treeRed")
|
||||
elif b == "Descend quickly: let the Red pass":
|
||||
s += ["treeRed", "greens"]
|
||||
elif b == "Descend slowly: two Greens":
|
||||
s.append("greens")
|
||||
elif b == "Shadow (rare)":
|
||||
s.append("stream")
|
||||
if r.get("enc_Blue") or r.get("enc_Black"):
|
||||
s.append("redwood")
|
||||
if r.get("enc_Black"):
|
||||
s.append("black")
|
||||
else:
|
||||
s.append("valley")
|
||||
if b == "Valley Red":
|
||||
s.append("valleyRed")
|
||||
elif b == "Passed the Red: meadow":
|
||||
s.append("meadow")
|
||||
oc = r.get("outcome_color")
|
||||
tried = "Blue" if r.get("enc_Blue") else oc if oc in ("Orange", "Brown") else "Orange" if r.get("enc_Orange") else "Brown" if r.get("enc_Brown") else None
|
||||
if tried:
|
||||
s.append("meadow:" + tried)
|
||||
return s
|
||||
|
||||
|
||||
def valley(runs):
|
||||
counts, edges = {}, {}
|
||||
for r in runs:
|
||||
seq = place_path(r)
|
||||
for i, p in enumerate(seq):
|
||||
counts[p] = counts.get(p, 0) + 1
|
||||
if i:
|
||||
k = seq[i - 1] + ">" + p
|
||||
edges[k] = edges.get(k, 0) + 1
|
||||
return {"counts": counts, "edges": [[*k.split(">"), n] for k, n in sorted(edges.items(), key=lambda kv: -kv[1])]}
|
||||
|
||||
|
||||
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),
|
||||
"early_deaths": sum(1 for r in cadets if r["outcome"] == "Died before the hour")}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- everything
|
||||
|
||||
def clean(o):
|
||||
if isinstance(o, dict):
|
||||
return {str(k): clean(v) for k, v in o.items()}
|
||||
if isinstance(o, (list, tuple)):
|
||||
return [clean(v) for v in o]
|
||||
if hasattr(o, "item"):
|
||||
o = o.item()
|
||||
if isinstance(o, float) and (math.isinf(o) or math.isnan(o)):
|
||||
return None
|
||||
return o
|
||||
|
||||
|
||||
def build(runs, rows, exported=None):
|
||||
global PLACES
|
||||
PLACES = place_ids()
|
||||
th = M["route_thresholds"]
|
||||
out = {
|
||||
"schema": 1,
|
||||
"data": {"form_rows": rows, "runs": len(runs), "exported": exported},
|
||||
"meta": {
|
||||
"presets": {k: v["label"] for k, v in M["presets"].items()}, "route_thresholds": th,
|
||||
"targets": {k: {"label": t["label"], "color": t["colour"]} for k, t in TARGETS.items()},
|
||||
"outcomes": {k: {"label": o["label"]} for k, o in OUTCOMES.items()},
|
||||
"factors": M["factors"], "stages": [{"key": s["key"], "label": s["label"], "chance": bool(s.get("chance"))} for s in STAGES],
|
||||
"missing_values": sorted(coding.MISSING),
|
||||
},
|
||||
"presets": {},
|
||||
}
|
||||
for pid, p in M["presets"].items():
|
||||
sub = apply_filters(runs, p["filters"])
|
||||
out["presets"][pid] = {
|
||||
"label": p["label"], "analyse": analyse(runs, p["filters"]),
|
||||
"routes": {t: rank_routes(sub, t, th) for t in TARGETS},
|
||||
"map": route_map(sub), "valley": valley(sub), "overview": overview(sub),
|
||||
}
|
||||
return clean(out)
|
||||
|
||||
|
||||
def coded_runs(path):
|
||||
df, _ = coding.load(path)
|
||||
df = df.drop(columns=["run_id"])
|
||||
return df.astype(object).where(df.notna(), None).to_dict("records")
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
ap = argparse.ArgumentParser(description=__doc__)
|
||||
ap.add_argument("--data", default=str(ROOT / "data/public/form_responses.json"))
|
||||
ap.add_argument("--out", default=str(ROOT / "data/public/stats.json"))
|
||||
a = ap.parse_args(argv)
|
||||
raw = json.load(open(a.data, encoding="utf-8"))
|
||||
runs = coded_runs(a.data)
|
||||
out = build(runs, len(raw["rows"]), raw.get("exported"))
|
||||
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")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
File diff suppressed because one or more lines are too long
+3
-2
@@ -34,6 +34,7 @@ share.
|
||||
2. Route model in Python, built from `core/spec/game.yaml`. **Done** (the bot's text, `core/spec/crosswalk.yaml`, moves with the bot importer and the JS advisor in step 4).
|
||||
3. **Done.** Fix the coding bugs found in the core review (letting the Red pass, "left your squadmates" before the
|
||||
redesigned form, missing bot text), each with a rule test.
|
||||
4. The site shows precomputed statistics with fixed filter presets; the upload button and `engine.js` go; a small
|
||||
JS advisor that reads the Python-built model replaces `solver.js`.
|
||||
4. The site shows precomputed statistics with fixed filter presets (**done**: `analysis/stats/site_stats.py`,
|
||||
`measures.yaml`, `data/public/stats.json`; the upload button and the click-to-select route map are gone); next,
|
||||
a small JS advisor that reads the Python-built model replaces `solver.js`, and `engine.js` goes.
|
||||
5. `data/dictionary.yaml` for every published column, and Croissant metadata for the datasets.
|
||||
|
||||
+3
-2
@@ -8,13 +8,14 @@
|
||||
"dev": "node site/build.js && python3 -m http.server 8000 -d dist",
|
||||
"test:js": "node tests/parity/run_engine.js data/public/form_responses.json tests/out",
|
||||
"test:py": "PYTHONPATH=core python3 -m atlas.coding && cd analysis/stats && PYTHONPATH=../../core python3 analyze.py && cd ../.. && PYTHONPATH=core python3 -m unittest discover -s tests/core -p 'test_*.py'",
|
||||
"test:parity": "python3 tests/parity/compare_runs.py && python3 tests/parity/compare_results.py && python3 tests/parity/compare_routes.py && python3 tests/parity/compare_solver.py",
|
||||
"test:parity": "python3 tests/parity/compare_runs.py && python3 tests/parity/compare_results.py && python3 tests/parity/compare_routes.py && python3 tests/parity/compare_solver.py && python3 tests/parity/compare_stats.py",
|
||||
"test:unit": "node --test tests/core/graph.test.js tests/core/solver.test.js",
|
||||
"test": "npm run test:js && npm run test:py && npm run test:parity && npm run test:unit",
|
||||
"graph": "node analysis/network/build-graph.js",
|
||||
"import-bot": "node collection/bot/import-bot.js",
|
||||
"check-sources": "python3 collection/sources/update_sources.py",
|
||||
"policy": "python3 planner/build_policy.py && python3 planner/policy_report.py"
|
||||
"policy": "python3 planner/build_policy.py && python3 planner/policy_report.py",
|
||||
"stats": "python3 analysis/stats/site_stats.py"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
|
||||
+77
-154
@@ -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})`);
|
||||
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);
|
||||
}
|
||||
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 = {};
|
||||
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
@@ -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
@@ -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 & 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 & 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 "> 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
@@ -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,
|
||||
};
|
||||
|
||||
+4
-211
@@ -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:")));
|
||||
// the routes runs take through these places are counted in Python (analysis/stats/site_stats.py, place_path)
|
||||
|
||||
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
|
||||
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 };
|
||||
})();
|
||||
|
||||
+5
-3
@@ -20,14 +20,16 @@ for (const f of fs.readdirSync(path.join(root, "site/atlas"))) copy(`site/atlas/
|
||||
if (!/^\s*<!doctype/i.test(html))
|
||||
fs.writeFileSync(p, `<!doctype html>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n${html}`);
|
||||
}
|
||||
copy("core/engine.js", "engine.js");
|
||||
// The route advisor and the bot's text mapping (Ken's bot downloads these two from the published site)
|
||||
copy("core/graph.js", "graph.js");
|
||||
copy("core/solver.js", "solver.js");
|
||||
for (const f of ["form_responses.json", "register.json", "graph.json", "policy.json"]) copy(`data/public/${f}`, `data/${f}`);
|
||||
// The numbers the page shows (all computed in Python) and the published data
|
||||
for (const f of ["stats.json", "register.json", "graph.json", "policy.json"]) copy(`data/public/${f}`, `data/${f}`);
|
||||
copy("data/derived/runs_clean.csv", "data/runs_clean.csv");
|
||||
// Source files shown in the page's "view the code" panel
|
||||
copy("core/atlas/coding.py", "python/coding.py");
|
||||
copy("core/spec/form.yaml", "python/form.yaml");
|
||||
for (const f of ["analyze.py", "stats_core.py"]) copy(`analysis/stats/${f}`, `python/${f}`);
|
||||
for (const f of ["measures.yaml", "site_stats.py", "stats_core.py"]) copy(`analysis/stats/${f}`, `python/${f}`);
|
||||
copy("README.md", "README.md");
|
||||
fs.writeFileSync(path.join(out, ".nojekyll"), "");
|
||||
console.log(`Site built in ${path.relative(root, out) || "."}`);
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
"""The precomputed statistics (analysis/stats/site_stats.py -> stats.json) must match what core/engine.js computed
|
||||
in the browser before, for every preset: factor tables, models, encounters, chance events, route rankings at every
|
||||
threshold, and the route map.
|
||||
|
||||
python tests/parity/compare_stats.py [stats.json]
|
||||
"""
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
stats = json.load(open(sys.argv[1] if len(sys.argv) > 1 else ROOT / "data/public/stats.json"))
|
||||
presets = {k: v["analyse"]["filters"] for k, v in stats["presets"].items()}
|
||||
targets = list(stats["meta"]["targets"])
|
||||
th = stats["meta"]["route_thresholds"]
|
||||
js = json.loads(subprocess.run(["node", "-e", f"""
|
||||
const E=require('./core/engine.js'),fs=require('fs');const raw=JSON.parse(fs.readFileSync('data/public/form_responses.json'));
|
||||
const {{runs}}=E.codeRows(raw.rows,raw.headers);const out={{}};
|
||||
for (const [k,f] of Object.entries({json.dumps(presets)})) {{
|
||||
const sub=E.applyFilters(runs,f); const o={{analyse:E.analyse(runs,f), routes:{{}}, map:{{}}}};
|
||||
for (const t of {json.dumps(targets)}) {{ o.routes[t]={{}}; for (const m of {json.dumps(th)}) o.routes[t][m]=E.rankRoutes(sub,t,m); o.map[t]=E.buildGraph(sub,t,{{}}); }}
|
||||
out[k]=o; }}
|
||||
process.stdout.write(JSON.stringify(out));"""], cwd=ROOT, capture_output=True, text=True, check=True).stdout)
|
||||
|
||||
bad = []
|
||||
|
||||
|
||||
def close(a, b, tol):
|
||||
if a is None or b is None:
|
||||
return a is None and b is None
|
||||
if isinstance(a, bool) or isinstance(b, bool) or isinstance(a, str) or isinstance(b, str):
|
||||
return a == b
|
||||
return abs(a - b) <= tol * max(1, abs(a), abs(b))
|
||||
|
||||
|
||||
def same(path, a, b, fields, tol=1e-9):
|
||||
for f in fields:
|
||||
if not close(a.get(f), b.get(f), tol): # a field left out counts as empty
|
||||
bad.append(f"{path}.{f}: python {a.get(f)!r} vs js {b.get(f)!r}")
|
||||
|
||||
|
||||
W = ("k", "n", "p", "lo", "hi")
|
||||
for pid, P in stats["presets"].items():
|
||||
py, J = P["analyse"], js[pid]["analyse"]
|
||||
if py["n"] != J["n"]:
|
||||
bad.append(f"{pid}: n {py['n']} vs {J['n']}")
|
||||
same(f"{pid}.meta", py["meta"], J["meta"], ("date_min", "date_max", "n_flagged"))
|
||||
for k in ("sources", "flag_counts", "outcomes"):
|
||||
if py["meta"][k] != J["meta"][k]:
|
||||
bad.append(f"{pid}.meta.{k} differ")
|
||||
for key, c in py["chance"].items():
|
||||
same(f"{pid}.chance.{key}", c["overall"], J["chance"][key]["overall"], W)
|
||||
for grp in ("by_stratum", "by_goal", "by_attempt"):
|
||||
if set(c[grp]) != set(J["chance"][key][grp]):
|
||||
bad.append(f"{pid}.chance.{key}.{grp} keys differ")
|
||||
for s in c[grp]:
|
||||
same(f"{pid}.chance.{key}.{grp}.{s}", c[grp][s], J["chance"][key][grp].get(s, {}), W)
|
||||
if py["first_sighting"] != J["first_sighting"]:
|
||||
bad.append(f"{pid}.first_sighting differ")
|
||||
for a, b in zip(py["encounters"], J["encounters"]):
|
||||
same(f"{pid}.enc.{a['context']}.overall", a["overall"], b["overall"], W)
|
||||
same(f"{pid}.enc.{a['context']}.intent", a["intent_matched"], b["intent_matched"], W)
|
||||
for k in ("green_encounters", "bonded_green", "rescued_orange", "rescued_brown", "incinerated"):
|
||||
if py["green_rescue"][k] != J["green_rescue"][k]:
|
||||
bad.append(f"{pid}.green_rescue.{k}")
|
||||
for key, ft in py["factors"].items():
|
||||
jr = {(r["factor"], r["level"]): r for r in J["factors"][key]["rows"]}
|
||||
if len(jr) != len(ft["rows"]):
|
||||
bad.append(f"{pid}.factors.{key}: {len(ft['rows'])} rows vs {len(jr)}")
|
||||
for r in ft["rows"]:
|
||||
j = jr.get((r["factor"], r["level"]))
|
||||
if j is None:
|
||||
bad.append(f"{pid}.factors.{key}: {r['factor']}={r['level']} missing in JS")
|
||||
continue
|
||||
same(f"{pid}.factors.{key}.{r['factor']}={r['level']}", r, j, W + ("or", "or_lo", "or_hi"))
|
||||
same(f"{pid}.factors.{key}.{r['factor']}={r['level']}", r, j, ("fisher_p", "q"), 1e-5)
|
||||
for key, m in py["models"].items():
|
||||
jm = J["models"][key]
|
||||
if (m is None) != (jm is None):
|
||||
bad.append(f"{pid}.models.{key} missing on one side")
|
||||
continue
|
||||
if m is None:
|
||||
continue
|
||||
same(f"{pid}.models.{key}", m, jm, ("n", "events"))
|
||||
jt = {t["term"]: t for t in jm["terms"]}
|
||||
for t in m["terms"]:
|
||||
same(f"{pid}.models.{key}.{t['term']}", t, jt.get(t["term"], {}), ("or", "lo", "hi"), 1e-4)
|
||||
same(f"{pid}.models.{key}.{t['term']}", t, jt.get(t["term"], {}), ("p",), 1e-6)
|
||||
for a, b in zip(py["daily"], J["daily"]):
|
||||
same(f"{pid}.daily.{a['date']}", a, b, ("runs", "meadow_n", "blue_k", "tree_n", "shadow_k"))
|
||||
for t, R in P["routes"].items():
|
||||
for m in th:
|
||||
jr = js[pid]["routes"][t][str(m)]
|
||||
bt = R["by_threshold"][str(m)]
|
||||
if bt["n_routes_tested"] != jr["n_routes_tested"]:
|
||||
bad.append(f"{pid}.routes.{t}.{m}: {bt['n_routes_tested']} routes vs {jr['n_routes_tested']}")
|
||||
jrows = {r["route"]: r for r in jr["rows"]}
|
||||
for i, r in enumerate(R["rows"]):
|
||||
if r["n"] < m:
|
||||
continue
|
||||
j = jrows.get(r["route"])
|
||||
if j is None:
|
||||
bad.append(f"{pid}.routes.{t}.{m}: {r['route']} missing in JS")
|
||||
continue
|
||||
same(f"{pid}.routes.{t}.{m}.{r['route']}", r, j, W + ("or", "or_lo", "or_hi", "mh_or", "mh_lo", "mh_hi"))
|
||||
same(f"{pid}.routes.{t}.{m}.{r['route']}", r, j, ("fisher_p", "mh_p"), 1e-5)
|
||||
same(f"{pid}.routes.{t}.{m}.{r['route']}", {"q": bt["q"].get(str(i)), "mh_q": bt["mh_q"].get(str(i))}, j, ("q", "mh_q"), 1e-5)
|
||||
for t in targets:
|
||||
jn = {n["id"]: n for n in js[pid]["map"][t]["nodes"]}
|
||||
jl = {l["id"]: l for l in js[pid]["map"][t]["links"]}
|
||||
for n, w in zip(P["map"]["nodes"], P["map"]["by_target"][t]["nodes"]):
|
||||
same(f"{pid}.map.{t}.{n['id']}", {**n, **w}, jn.get(n["id"], {}), W)
|
||||
for l, w in zip(P["map"]["links"], P["map"]["by_target"][t]["links"]):
|
||||
same(f"{pid}.map.{t}.{l['id']}", {**l, **w}, jl.get(l["id"], {}), W + ("chance",))
|
||||
if len(jn) != len(P["map"]["nodes"]) or len(jl) != len(P["map"]["links"]):
|
||||
bad.append(f"{pid}.map.{t}: size differs")
|
||||
|
||||
print(f"precomputed statistics, {len(stats['presets'])} presets: " + ("ALL MATCH" if not bad else f"{len(bad)} DIFFER"))
|
||||
for b in bad[:25]:
|
||||
print(" ", b)
|
||||
sys.exit(1 if bad else 0)
|
||||
Reference in New Issue
Block a user