Treat unsure and blank answers as missing information, not choices
- engine.js / analyze.py: one MISSING set ("Unknown", "Unsure",
"Unsure/unknown", "Multiple", "(not recorded)", "(not asked)", ...).
Factor tables compare only runs that answered each question and report how
many were left out; models are complete-case for every choice variable;
route rankings group only fully known routes; the route flow skips
missing steps.
- "I've lost count" now counts as a later attempt.
- The chase goal keeps its "not asked" stratum as an adjustment only; it is
no longer displayed as a finding.
- Page: no unknown levels in charts, tables or filters; factor explorer notes
how many runs were left out; Methods explains the rule.
JS/Python parity still exact.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
de80e99c74
commit
1b0ef9a2c1
+10
-9
@@ -220,10 +220,10 @@
|
||||
$$(".tchip[data-t]").forEach((b) => b.addEventListener("click", () => { state.target = b.dataset.t; $("#best-routes").innerHTML = ""; renderTargets(); renderMap(); }));
|
||||
}
|
||||
const ORDER = {
|
||||
company: ["Alone", "1 Squadmate", "2 Squadmates", "Unknown"],
|
||||
direction: ["East", "Center", "West", "Multiple", "Unknown"],
|
||||
first_sighting: ["Red", "Orange", "Brown", "Green", "Unsure", "Unknown"],
|
||||
post_path: ["Forest", "West", "East", "(no fork)", "Unknown"],
|
||||
company: ["Alone", "1 Squadmate", "2 Squadmates"],
|
||||
direction: ["East", "Center", "West"],
|
||||
first_sighting: ["Red", "Orange", "Brown", "Green"],
|
||||
post_path: ["Forest", "West", "East", "(no fork)"],
|
||||
hour: ["Climb the tree", "Valley centre"],
|
||||
encounter: ["Tree: Red below", "Tree: two Greens", "Tree: shadow → Blue/Black", "Valley: bond the Red", "Meadow: Orange", "Meadow: Brown", "Meadow: Orange/Brown", "Meadow: Blue", "Meadow (no attempt recorded)"],
|
||||
end: ["Bonded Red", "Bonded Green", "Bonded Orange", "Bonded Brown", "Bonded Blue", "Bonded Black", "Incinerated", "Died before the hour"],
|
||||
@@ -487,10 +487,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]) => k !== "Unknown/lost count").map(([k, w]) => ({ label: k, ...w, color: cssVar("--accent") })));
|
||||
Object.entries(c.by_attempt).filter(([k]) => !E.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)).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) && !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 mb = r.models.blue_meadow, ms = r.models.shadow;
|
||||
forest($("#ch-model-blue"), termsOf(mb));
|
||||
forest($("#ch-model-shadow"), termsOf(ms));
|
||||
@@ -563,9 +563,10 @@
|
||||
$("#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>
|
||||
<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>`;
|
||||
const cols = ["Red", "Orange", "Brown", "Green", "Unsure", "Unknown"];
|
||||
// "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"] };
|
||||
$("#tbl-first").innerHTML = `<table><thead><tr><th>Company · direction</th>${cols.map((c) => `<th class="num">${c}</th>`).join("")}<th class="num">Runs</th></tr></thead><tbody>${r.first_sighting.filter((x) => x.n >= 3).map((x) => `<tr><td>${esc(x.key.replace("|", " · "))}</td>${cols.map((c) => { const n = x.colors[c] || 0; const off = n && POOL[x.key] && !["Unsure", "Unknown"].includes(c) && !POOL[x.key].includes(c); return `<td class="num" style="${off ? "color:var(--warn);font-weight:600" : n ? "" : "color:var(--faint)"}" title="${off ? "Outside the documented pool" : ""}">${n ? `${n}<span class="muted"> · ${pct(n / x.n, 0)}</span>` : "·"}</td>`; }).join("")}<td class="num">${x.n}</td></tr>`).join("")}</tbody></table>`;
|
||||
$("#tbl-first").innerHTML = `<table><thead><tr><th>Company · direction</th>${cols.map((c) => `<th class="num">${c}</th>`).join("")}<th class="num">Runs</th></tr></thead><tbody>${r.first_sighting.map((x) => ({ ...x, n: cols.reduce((t, c) => t + (x.colors[c] || 0), 0), gap: (x.colors.Unsure || 0) + (x.colors.Unknown || 0) })).filter((x) => x.n >= 3).map((x) => `<tr><td>${esc(x.key.replace("|", " · "))}</td>${cols.map((c) => { const n = x.colors[c] || 0; const off = n && POOL[x.key] && !POOL[x.key].includes(c); return `<td class="num" style="${off ? "color:var(--warn);font-weight:600" : n ? "" : "color:var(--faint)"}" title="${off ? "Outside the documented pool" : ""}">${n ? `${n}<span class="muted"> · ${pct(n / x.n, 0)}</span>` : "·"}</td>`; }).join("")}<td class="num">${x.n}${x.gap ? `<span class="muted" title="Riders who were not sure which dragon they saw, left out"> +${x.gap} unsure</span>` : ""}</td></tr>`).join("")}</tbody></table>`;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ route table
|
||||
@@ -601,7 +602,7 @@
|
||||
$("#tbl-factors").innerHTML = `<table><thead><tr><th>${esc(labelFactor(state.fxFactor))}</th><th class="num">Hits/runs</th><th class="num">Rate</th><th class="num">95% CI</th><th class="num">OR vs rest</th><th class="num">p</th><th class="num">q</th></tr></thead><tbody>
|
||||
<tr><td><i>All</i></td><td class="num">${kn(ft.overall)}</td><td class="num">${pct(ft.overall.p)}</td><td class="num">${ci(ft.overall)}</td><td></td><td></td><td></td></tr>
|
||||
${rows.map((r) => `<tr class="${r.q < 0.05 ? "sig" : ""}${r.or === undefined ? " thin" : ""}"><td>${esc(r.level)}</td><td class="num">${kn(r)}</td><td class="num">${pct(r.p)}</td><td class="num">${ci(r)}</td><td class="num">${r.or !== undefined ? `${fmtOR(r.or)} <span class="muted">(${fmtOR(r.or_lo)}–${fmtOR(r.or_hi)})</span>` : "too few"}</td><td class="num">${fmtP(r.fisher_p)}</td><td class="num">${r.q !== undefined ? `<span class="qbadge${r.q < 0.05 ? " s" : ""}">${fmtP(r.q)}</span>` : ""}</td></tr>`).join("")}
|
||||
</tbody></table>`;
|
||||
</tbody></table>${ft.missing && ft.missing[state.fxFactor] ? `<p class="small muted">${ft.missing[state.fxFactor].toLocaleString()} runs with no usable answer to this question ("unsure", blank, or not asked on that version of the form) are left out of these comparisons rather than treated as a choice.</p>` : ""}`;
|
||||
forest($("#ch-factor"), rows.filter((r) => r.or !== undefined).map((r) => ({ label: r.level, or: r.or, lo: r.or_lo, hi: r.or_hi, q: r.q, p: undefined, n: r.n })), { labelW: 220 });
|
||||
}
|
||||
|
||||
|
||||
@@ -644,7 +644,9 @@ adjusted OR = exp(βⱼ), 95% CI = exp(βⱼ ± 1.96·SEⱼ)</div>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<h3>Missing answers</h3>
|
||||
<p class="small">"Unsure", blank answers, conflicting answers and questions an older version of the form did not ask are treated as missing information, never as a choice. Each comparison uses the runs that answered that question; models use runs that answered every question in them (complete cases). "I've lost count" counts as a later attempt. The only exception is the chase goal used to adjust for reporting bias: runs from before that question existed stay in the models as their own adjustment group, but that group is not shown as a finding. The solver and the valley map ignore missing steps in the same way.</p>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
+2581
-2581
File diff suppressed because it is too large
Load Diff
+28
-16
@@ -22,6 +22,13 @@
|
||||
|
||||
const COLORS = ["Red", "Green", "Orange", "Brown", "Blue", "Black"];
|
||||
|
||||
// Answers that carry no information about the choice ("Unsure", blank, a question the form did not ask yet,
|
||||
// conflicting answers). They are kept in the coded data for transparency, but every analysis treats them as
|
||||
// missing: they are never shown or compared as if they were a choice.
|
||||
const MISSING = new Set(["Unknown", "Unsure", "Unsure/unknown", "Multiple", "(not recorded)", "(not asked)",
|
||||
"(not asked/blank)", "Unknown/lost count", "Blank/not asked"]);
|
||||
const isMissing = (v) => v === null || v === undefined || v === "" || MISSING.has(v);
|
||||
|
||||
// ---------------------------------------------------------------- column detection
|
||||
const COLUMN_KEYS = {
|
||||
timestamp: ["timestamp"],
|
||||
@@ -312,7 +319,8 @@
|
||||
|
||||
return {
|
||||
source, date, wing, section, squad: g("squad") || "Unknown", attempt,
|
||||
attempt_group: attempt === 1 ? "First attempt" : attempt > 1 ? "Later attempt" : "Unknown/lost count",
|
||||
// "I've lost count" means many attempts, so it is a later attempt, not missing
|
||||
attempt_group: attempt === 1 ? "First attempt" : attempt > 1 || /lost count/i.test(g("attempt") || "") ? "Later attempt" : "Unknown",
|
||||
goal, company, left_squadmates: leftSquad, direction, first_sighting: first || "Unknown",
|
||||
sighting_action: "sighting_action" in C ? SIGHTING_ACTION[g("sighting_action")] || g("sighting_action") || "Unknown" : "(not asked)",
|
||||
scream, resolution, combat_first: combat || "(not recorded)", combat_second: combat2 || "(not recorded)",
|
||||
@@ -555,9 +563,10 @@
|
||||
const O = OUTCOMES[outKey];
|
||||
const D = runs.filter(O.denom);
|
||||
const total = D.length, events = D.filter(O.event).length;
|
||||
const rows = [];
|
||||
const rows = [], missing = {};
|
||||
for (const f of FACTORS) {
|
||||
const groups = groupBy(D.filter((r) => r[f] !== null && r[f] !== undefined), f);
|
||||
const groups = groupBy(D.filter((r) => !isMissing(r[f])), f);
|
||||
missing[f] = D.filter((r) => isMissing(r[f])).length;
|
||||
const nf = Object.values(groups).reduce((s, g) => s + g.length, 0);
|
||||
const ef = Object.values(groups).reduce((s, g) => s + g.filter(O.event).length, 0);
|
||||
for (const lv of sortedKeys(groups)) {
|
||||
@@ -570,7 +579,7 @@
|
||||
}
|
||||
const tested = rows.filter((r) => r.fisher_p !== undefined);
|
||||
bh(tested.map((r) => r.fisher_p)).forEach((q, i) => (tested[i].q = q));
|
||||
return { outcome: outKey, label: O.label, overall: wilson(events, total), rows };
|
||||
return { outcome: outKey, label: O.label, overall: wilson(events, total), rows, missing };
|
||||
}
|
||||
|
||||
// Multivariable model: one row per run in the outcome's denominator; categorical factors dummy-coded
|
||||
@@ -664,18 +673,19 @@
|
||||
for (const key of Object.keys(OUTCOMES)) res.factors[key] = factorTable(runs, key);
|
||||
|
||||
// adjusted models
|
||||
const first2 = (r) => ["Red", "Brown", "Orange", "Green"].includes(r.first_sighting) ? r.first_sighting : "Unsure/unknown";
|
||||
const first2 = (r) => (["Red", "Brown", "Orange", "Green"].includes(r.first_sighting) ? r.first_sighting : null);
|
||||
const known = (f) => (r) => (isMissing(r[f]) ? null : r[f]);
|
||||
const src2 = (r) => (r.source === "Form" ? "Form submission" : "Bulk log (import)");
|
||||
res.models = {
|
||||
blue_meadow: model(runs, "blue_meadow", {
|
||||
source: src2, goal: goal2, direction: (r) => r.direction, first_sighting: first2,
|
||||
resolution: (r) => r.resolution, company: (r) => (r.company === "Unknown" ? null : r.company),
|
||||
source: src2, goal: goal2, direction: known("direction"), first_sighting: first2,
|
||||
resolution: known("resolution"), company: known("company"),
|
||||
}),
|
||||
shadow: model(runs, "shadow", {
|
||||
source: src2, goal: goal2, attempt: (r) => r.attempt_group, direction: (r) => r.direction,
|
||||
source: src2, goal: goal2, attempt: known("attempt_group"), direction: known("direction"),
|
||||
}),
|
||||
bond_blue_meadow: model(runs, "bond_blue_meadow", {
|
||||
source: src2, goal: goal2, direction: (r) => r.direction, resolution: (r) => r.resolution,
|
||||
source: src2, goal: goal2, direction: known("direction"), resolution: known("resolution"),
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -714,13 +724,13 @@
|
||||
|
||||
function stageValue(r, key) {
|
||||
switch (key) {
|
||||
case "company": return r.company;
|
||||
case "direction": return r.direction;
|
||||
case "first_sighting": return r.scream === "DIED at first sighting" ? null : r.first_sighting;
|
||||
case "company": return isMissing(r.company) ? null : r.company;
|
||||
case "direction": return isMissing(r.direction) ? null : r.direction;
|
||||
case "first_sighting": return r.scream === "DIED at first sighting" || isMissing(r.first_sighting) ? null : r.first_sighting;
|
||||
case "cadet":
|
||||
if (r.scream.startsWith("DIED")) return null;
|
||||
if (r.scream.startsWith("DIED") || isMissing(r.scream) || isMissing(r.resolution)) return null;
|
||||
return r.scream === "Investigate & help" ? "Help → " + r.resolution : r.scream + " → " + r.resolution;
|
||||
case "post_path": return r.post_path;
|
||||
case "post_path": return isMissing(r.post_path) ? null : r.post_path;
|
||||
case "hour": return r.hour === "Tree" ? "Climb the tree" : r.hour === "Valley" ? "Valley centre" : null;
|
||||
case "encounter": {
|
||||
if (!r.branch) return null;
|
||||
@@ -803,7 +813,9 @@
|
||||
const keyStages = STAGES.slice(0, 6).map((s) => s.key);
|
||||
const pool = runs.filter(TARGETS[targetKey].pool);
|
||||
const totK = pool.filter(T).length, totN = pool.length;
|
||||
const groups = groupBy(pool, (r) => keyStages.map((k) => stageValue(r, k) || "—").join(" › "));
|
||||
// a route is only ranked from runs whose every step is known; runs with a gap still count in the comparison group
|
||||
const groups = groupBy(pool.filter((r) => keyStages.every((k) => stageValue(r, k) || (k === "post_path" && r.post_path === null))),
|
||||
(r) => keyStages.map((k) => stageValue(r, k) || "—").join(" › "));
|
||||
const rows = Object.entries(groups).filter(([, g]) => g.length >= minN).map(([key, g]) => {
|
||||
const k = g.filter(T).length, n = g.length;
|
||||
const o = Object.assign({ route: key, values: keyStages.map((s) => stageValue(g[0], s)) }, wilson(k, n));
|
||||
@@ -826,7 +838,7 @@
|
||||
}
|
||||
|
||||
return {
|
||||
COLORS, COLUMN_KEYS, STAGES, TARGETS, OUTCOMES, FACTORS, ROUTE_FIELDS, rankRoutes,
|
||||
COLORS, MISSING, isMissing, COLUMN_KEYS, STAGES, TARGETS, OUTCOMES, FACTORS, ROUTE_FIELDS, rankRoutes,
|
||||
findColumns, codeRow, codeRows, parseTimestamp,
|
||||
wilson, fisher, oddsRatio, bh, logisticRidge, mantelHaenszel,
|
||||
applyFilters, analyse, factorTable, model, buildGraph, stageValue, stratum,
|
||||
|
||||
@@ -133,7 +133,8 @@
|
||||
/* ---------- Decision-variable graph (all sources) ---------- */
|
||||
|
||||
const VAR_STAGES = ["company", "direction", "first_sighting", "scream", "resolution", "post_path", "hour", "branch"];
|
||||
const MISSING = new Set([null, undefined, "", "Unknown", "Unsure", "Multiple", "(no fork)", "(not recorded)"]);
|
||||
// "(no fork)" is a real state (that path has no fork), but it is not a choice node, so it is skipped too
|
||||
const MISSING = new Set([null, undefined, "", "Unknown", "Unsure", "Unsure/unknown", "Multiple", "(no fork)", "(not recorded)", "(not asked)", "(not asked/blank)", "Unknown/lost count"]);
|
||||
|
||||
function endLabel(v) {
|
||||
if (v.outcome === "Bonded") return v.outcome_color ? `Bonded ${v.outcome_color}` : "Bonded (colour unknown)";
|
||||
|
||||
@@ -15,6 +15,13 @@ import pandas as pd
|
||||
from stats_core import Z95, bh, logistic_ridge, odds_ratio, p_from_z, wilson
|
||||
|
||||
COLORS = ["Red", "Green", "Orange", "Brown", "Blue", "Black"]
|
||||
# answers with no information about the choice: treated as missing everywhere (mirrors MISSING in engine.js)
|
||||
MISSING = {"Unknown", "Unsure", "Unsure/unknown", "Multiple", "(not recorded)", "(not asked)",
|
||||
"(not asked/blank)", "Unknown/lost count", "Blank/not asked"}
|
||||
|
||||
|
||||
def is_missing(v):
|
||||
return v is None or (isinstance(v, float) and v != v) or v == "" or v in MISSING
|
||||
FACTORS = ["company", "direction", "first_sighting", "scream", "resolution", "combat_first",
|
||||
"post_path", "hour", "wing", "squad", "attempt_group", "source", "goal", "sighting_action", "combat_second", "malek_intent"]
|
||||
|
||||
@@ -47,7 +54,7 @@ def factor_table(d, key, min_n=5):
|
||||
D["_e"] = ev(D).astype(bool)
|
||||
rows = []
|
||||
for f in FACTORS:
|
||||
sub = D[D[f].notna()]
|
||||
sub = D[D[f].notna() & ~D[f].isin(MISSING)]
|
||||
nf, ef = len(sub), int(sub._e.sum())
|
||||
for lv in sorted(sub[f].astype(str).unique()):
|
||||
g = sub[sub[f].astype(str) == lv]
|
||||
@@ -99,7 +106,11 @@ def src2(r):
|
||||
|
||||
|
||||
def first2(r):
|
||||
return r.first_sighting if r.first_sighting in ("Red", "Brown", "Orange", "Green") else "Unsure/unknown"
|
||||
return r.first_sighting if r.first_sighting in ("Red", "Brown", "Orange", "Green") else None
|
||||
|
||||
|
||||
def known(f):
|
||||
return lambda r: None if is_missing(r[f]) else r[f]
|
||||
|
||||
|
||||
def period(r):
|
||||
@@ -112,13 +123,13 @@ def analyse(d):
|
||||
res = {"n": len(d), "factors": {k: factor_table(d, k) for k in OUT}}
|
||||
res["models"] = {
|
||||
"blue_meadow": model(d, "blue_meadow", {
|
||||
"source": src2, "goal": goal2, "direction": lambda r: r.direction, "first_sighting": first2,
|
||||
"resolution": lambda r: r.resolution, "company": lambda r: None if r.company == "Unknown" else r.company}),
|
||||
"source": src2, "goal": goal2, "direction": known("direction"), "first_sighting": first2,
|
||||
"resolution": known("resolution"), "company": known("company")}),
|
||||
"shadow": model(d, "shadow", {
|
||||
"source": src2, "goal": goal2, "attempt": lambda r: r.attempt_group,
|
||||
"direction": lambda r: r.direction}),
|
||||
"source": src2, "goal": goal2, "attempt": known("attempt_group"),
|
||||
"direction": known("direction")}),
|
||||
"bond_blue_meadow": model(d, "bond_blue_meadow", {
|
||||
"source": src2, "goal": goal2, "direction": lambda r: r.direction, "resolution": lambda r: r.resolution}),
|
||||
"source": src2, "goal": goal2, "direction": known("direction"), "resolution": known("resolution")}),
|
||||
}
|
||||
return res
|
||||
|
||||
|
||||
@@ -352,7 +352,8 @@ def code_row(r, C):
|
||||
return {
|
||||
"source": source, "date": date, "wing": wing, "section": section,
|
||||
"squad": g("squad") or "Unknown", "attempt": attempt,
|
||||
"attempt_group": "First attempt" if attempt == 1 else ("Later attempt" if attempt and attempt > 1 else "Unknown/lost count"),
|
||||
# "I've lost count" means many attempts, so it is a later attempt, not missing
|
||||
"attempt_group": "First attempt" if attempt == 1 else ("Later attempt" if (attempt and attempt > 1) or "lost count" in (g("attempt") or "").lower() else "Unknown"),
|
||||
"goal": goal, "company": company, "left_squadmates": left_squad,
|
||||
"direction": direction, "first_sighting": first or "Unknown",
|
||||
"sighting_action": (SIGHTING_ACTION.get(g("sighting_action")) or g("sighting_action") or "Unknown") if "sighting_action" in C else "(not asked)",
|
||||
|
||||
+11
-4
@@ -8,12 +8,19 @@ js = json.loads(subprocess.check_output(["node", "-e", """
|
||||
const E=require('./packages/core/src/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 o={};for(const t of ['see_Blue','bond_Blue','see_shadow','bond_Green']){o[t]=E.rankRoutes(runs,t,10)}
|
||||
console.log(JSON.stringify(o));"""]))
|
||||
MISSING = {"Unknown", "Unsure", "Unsure/unknown", "Multiple", "(not recorded)", "(not asked)", "(not asked/blank)", "Unknown/lost count", "Blank/not asked"}
|
||||
miss = lambda v: not isinstance(v, str) or v == "" or v in MISSING # noqa: E731
|
||||
def stage(r):
|
||||
if r.scream.startswith("DIED"): cad = None # noqa
|
||||
# a route is only ranked from runs whose every step is known (mirrors rankRoutes in engine.js)
|
||||
if r.scream.startswith("DIED") or miss(r.scream) or miss(r.resolution): cad = None # noqa
|
||||
else: cad = ("Help → " + r.resolution) if r.scream == "Investigate & help" else (r.scream + " → " + r.resolution)
|
||||
hour = {"Tree": "Climb the tree", "Valley": "Valley centre"}.get(r.hour)
|
||||
fs = None if r.scream == "DIED at first sighting" else r.first_sighting
|
||||
return " › ".join(v if isinstance(v, str) and v else "—" for v in [r.company, r.direction, fs, cad, r.post_path, hour])
|
||||
fs = None if r.scream == "DIED at first sighting" or miss(r.first_sighting) else r.first_sighting
|
||||
post_null = not isinstance(r.post_path, str)
|
||||
post = None if post_null or miss(r.post_path) else r.post_path
|
||||
vals = [None if miss(r.company) else r.company, None if miss(r.direction) else r.direction, fs, cad, post, hour]
|
||||
if any(v is None for i, v in enumerate(vals) if not (i == 4 and post_null)): return None
|
||||
return " › ".join(v if v else "—" for v in vals)
|
||||
def stratum(r):
|
||||
if r.source != "Form": return "bulk"
|
||||
return {"Blue": "blue", "Black": "black", "Blue or Black": "blue-or-black"}.get(r.goal, "other")
|
||||
@@ -28,7 +35,7 @@ for t, (pool, ev) in T.items():
|
||||
P = d[pool(d)].copy(); P["e"] = ev(P).astype(bool)
|
||||
K, N = int(P.e.sum()), len(P)
|
||||
rows = {}
|
||||
for route, g in P.groupby("route"):
|
||||
for route, g in P[P.route.notna()].groupby("route"):
|
||||
if len(g) < 10: continue
|
||||
k, n = int(g.e.sum()), len(g)
|
||||
orr = odds_ratio(k, n - k, K - k, N - n - (K - k))
|
||||
|
||||
Reference in New Issue
Block a user