Coding rules for the redesigned community form; import the new data

The Threshing Routes form was redesigned (5,651 responses). Both implementations
(engine.js and clean.py) now read either version:
- one direction question + one colour question, with the older per-direction
  columns used only to fill gaps and cross-check
- cadet encounter as an action path (scream, first and second combat move)
  plus a separate outcome
- new fields: sighting_action, combat_second, rare_reported, malek_intent,
  left_squadmates, tail; "Why are you doing this run?" mapped onto the goal
  ("Blue or Black" for rare chasers)
- the rare-dragon question feeds saw_blue_meadow / saw_shadow and the branch
The old export still codes identically. JS/Python parity: all match.

Data: form 2,573 -> 5,651 rows, Dragon Register 216 -> 273, new route PDF
fingerprint. Supersedes the automated pull request #2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
ekcSchiano
2026-11-01 22:10:51 +00:00
co-authored by Claude Opus 5.5
parent 9c0e35423a
commit 46ee08a56b
8 changed files with 5911 additions and 5707 deletions
+130 -27
View File
@@ -48,15 +48,32 @@
bond_note: ["those who bonded"],
goal: ["colour dragon are you trying"],
combat: ["combat choice"],
// Questions added in the redesigned form (late October 2026). "!x" means the header must NOT contain x.
first_dir: ["what was your first direction"],
first_colour: ["colour was your initial dragon sighting", "!["],
leg_West: ["colour was your initial dragon sighting", "[west"],
leg_Center: ["colour was your initial dragon sighting", "[forest center"],
sighting_action: ["action did you take during the first dragon sighting"],
cadet_actions: ["during your cadet encounter"],
goal_v2: ["why are you doing this run"],
malek: ["seek malek"],
rare: ["encounter a rare dragon"],
tail: ["what tail does your dragon have"],
};
// A key is only reported missing when neither it nor its replacement in the other form version was found.
const ALTERNATIVE = {
dir_East: "first_dir", dir_West: "first_dir", dir_Center: "first_dir", first_dir: "dir_Center", first_colour: "dir_Center",
goal: "goal_v2", goal_v2: "goal", combat: "cadet_actions", cadet_actions: "combat",
};
const OPTIONAL = new Set(["leg_West", "leg_Center", "sighting_action", "malek", "rare", "tail"]);
function findColumns(headers) {
const C = {};
for (const [key, words] of Object.entries(COLUMN_KEYS)) {
const hit = headers.find((h) => words.every((w) => String(h).toLowerCase().includes(w)));
const hit = headers.find((h) => words.every((w) => w[0] === "!" ? !String(h).toLowerCase().includes(w.slice(1)) : String(h).toLowerCase().includes(w)));
if (hit !== undefined) C[key] = hit;
}
const missing = Object.keys(COLUMN_KEYS).filter((k) => !(k in C));
const missing = Object.keys(COLUMN_KEYS).filter((k) => !(k in C) && !OPTIONAL.has(k) && !(ALTERNATIVE[k] in C));
return { C, missing };
}
@@ -79,6 +96,45 @@
"Bullies > Put yourself in the middle (Rushed the bigger cadet attacking your squadmate)":
"Put yourself in the middle (bigger cadet)",
};
// Redesigned form: the cadet encounter is asked as a path of actions plus a separate outcome.
// value: [scream, first combat move, second combat move, resolution (when the action decides it)]
const CADET_ACTIONS = {
"Bullies > Assess > Unknown": ["Investigate & help", "Assess the situation", null, null],
"Bullies > Assess > Smaller Cadet": ["Investigate & help", "Assess the situation", "Engage the smaller cadet", null],
"Bullies > Assess > Daggers or not": ["Investigate & help", "Assess the situation", "Daggers or not (protect squadmate)", null],
"Bullies > Unknown": ["Investigate & help", null, null, null],
"Bullies > Smaller Cadet (Did not assess)": ["Investigate & help", "Even the numbers (smaller cadet)", null, null],
"Bullies > Bigger Cadet (Did not assess)": ["Investigate & help", "Put yourself in the middle (bigger cadet)", null, null],
"Injured Cadet > Tourniquet": ["Ignore the scream", null, null, "Tourniquet"],
"Injured Cadet > Left them there": ["Ignore the scream", null, null, "Left injured cadet"],
"Injured Cadet > Took their weapons": ["Ignore the scream", null, null, "Took their weapons"],
"Avoided combat (Investigated scream > Left them to it)": ["Investigate & leave", null, null, "Left them to it"],
"N/A - You died with initial dragon sighting": ["DIED at first sighting", null, null, "DIED at first sighting"],
"Unsure": ["Unknown", null, null, "Unknown"],
};
const CADET_OUTCOME = {
"Squadmate's revenge": "Squadmate's revenge",
"You ended the bullies yourself": "Killed the bullies yourself",
"Left to the Dragons": "Left bullies to the dragons",
"You died in combat": "DIED in combat",
};
const DIRECTION_MAP = { "Forest Center": "Center", "West / Scent": "West", "East / Roar": "East" };
const GOAL_V2 = {
"Hoping for a Rare Dragon (Blue or Black)": "Blue or Black",
"Trying to bond the Red dragon under the tree": "Red (tree)",
"Daily Run Assignment data": "Daily run data",
"Just here for fun, and maybe a dragon": "Any (for fun)",
};
const SIGHTING_ACTION = {
"Hold Ground / Stay Still": "Hold still", "Respect / Face it": "Respect / face it",
"Retreat / Run / Back Away": "Retreat / run", "Hide / Duck": "Hide", "Draw / Drop Weapon": "Weapon",
"Meet Gaze": "Meet its gaze", "Protect / Help Sqaudmate": "Protect squadmate", "Approach": "Approach",
"Stand on your own": "Stand alone", "Unsure": "Unknown", "Unsure - You don't remember": "Unknown",
};
const RARE_MAP = { "Yes - A blue dragon in the valley": "Blue (valley)", "Yes - Shadow!!!": "Shadow", "No": "No" };
const RARE_GOALS = ["Blue", "Black", "Blue or Black"];
const isRareGoal = (goal) => RARE_GOALS.includes(goal);
const HOUR_MAP = {
"Continued to Valley Centre": "Valley",
"Climbed the tallest tree": "Tree",
@@ -143,25 +199,61 @@
const section = wings.length === 1 ? g("wing_" + wings[0]) : null;
if (wings.length > 1) flags.push("multiple wings");
const dirs = ["East", "West", "Center"].filter((d) => g("dir_" + d));
let direction, first;
if (dirs.length === 1) {
direction = dirs[0];
first = g("dir_" + dirs[0]);
if ("first_dir" in C) {
// Redesigned form: one direction question and one colour question. The older per-direction colour
// columns are still in the sheet for some rows and are used only to fill gaps and to cross-check.
direction = DIRECTION_MAP[g("first_dir")] || null;
first = g("first_colour");
const legacy = ["West", "Center"].filter((d) => g("leg_" + d));
if (!direction && legacy.length === 1) {
direction = legacy[0];
flags.push("direction taken from the older sighting column");
}
const leg = direction ? g("leg_" + direction) : null;
if (!first && leg) first = leg;
else if (first && leg && first !== leg && first !== "Unsure" && leg !== "Unsure")
flags.push("first sighting differs between the old and new columns");
if (!direction) {
direction = "Unknown";
flags.push("direction missing");
}
} else {
direction = dirs.length ? "Multiple" : "Unknown";
first = null;
flags.push("direction " + (dirs.length ? "multiple" : "missing"));
const dirs = ["East", "West", "Center"].filter((d) => g("dir_" + d));
if (dirs.length === 1) {
direction = dirs[0];
first = g("dir_" + dirs[0]);
} else {
direction = dirs.length ? "Multiple" : "Unknown";
first = null;
flags.push("direction " + (dirs.length ? "multiple" : "missing"));
}
}
const company = g("company") || "Unknown";
const pool = SIGHTING_POOL[company + "|" + direction];
if (first && first !== "Unsure" && pool && !pool.includes(first))
const companyRaw = g("company") || "Unknown";
const leftSquad = / > Left them$/.test(companyRaw);
const company = leftSquad ? companyRaw.replace(/ > Left them$/, "") : companyRaw;
// Leaving your squadmates sends you into the solo pools, so either pool is plausible.
const pool = (SIGHTING_POOL[company + "|" + direction] || []).concat(leftSquad ? SIGHTING_POOL["Alone|" + direction] || [] : []);
if (first && first !== "Unsure" && pool.length && !pool.includes(first))
flags.push(`first sighting ${first} not in documented pool for ${company}/${direction}`);
const cadetRaw = g("cadet");
const [scream, resolution] = CADET_MAP[cadetRaw] || ["Unknown", "Unknown"];
if (cadetRaw && !CADET_MAP[cadetRaw]) flags.push("unrecognised cadet answer");
const combat = g("combat") ? COMBAT_MAP[g("combat")] || null : null;
let scream, resolution, combat = null, combat2 = null;
if ("cadet_actions" in C) {
const act = g("cadet_actions");
const a = CADET_ACTIONS[act] || ["Unknown", null, null, "Unknown"];
if (act && !CADET_ACTIONS[act]) flags.push("unrecognised cadet answer");
[scream, combat, combat2] = a;
const out = CADET_OUTCOME[cadetRaw] || null;
if (a[3] !== null) {
resolution = a[3];
if (out === "DIED in combat" && !resolution.startsWith("DIED")) flags.push("died in combat on a path without combat");
} else resolution = out || "Unknown";
} else {
[scream, resolution] = CADET_MAP[cadetRaw] || ["Unknown", "Unknown"];
if (cadetRaw && !CADET_MAP[cadetRaw]) flags.push("unrecognised cadet answer");
combat = g("combat") ? COMBAT_MAP[g("combat")] || null : null;
}
const postRaw = g("post");
let post = null;
@@ -176,12 +268,13 @@
const enc = {};
for (const c of COLORS) enc[c] = g("enc_" + c);
const rare = RARE_MAP[g("rare")] || null;
const bonded = COLORS.filter((c) => enc[c] === "Bonded!");
const burned = COLORS.filter((c) => enc[c] === "Incinerated");
let branch = null;
if (hour === "Tree") {
if (enc.Blue || enc.Black) branch = "Shadow (rare)";
if (enc.Blue || enc.Black || rare === "Shadow") branch = "Shadow (rare)";
else if (enc.Green) branch = "Descend slowly: two Greens";
else if (enc.Red) branch = "Descend quickly: Red";
else if (enc.Orange || enc.Brown) {
@@ -190,7 +283,7 @@
}
} else if (hour === "Valley") {
if (enc.Green) flags.push("Green recorded on a Valley run (no Greens in the valley)");
const meadow = ["Orange", "Brown", "Blue"].some((c) => enc[c]);
const meadow = ["Orange", "Brown", "Blue"].some((c) => enc[c]) || rare === "Blue (valley)";
if (meadow || enc.Red === "Changed my mind") branch = "Passed the Red: meadow";
else if (enc.Red) branch = "Valley Red";
}
@@ -212,17 +305,26 @@
const rescued = enc.Green === "Saved by another" && outcome === "Bonded" && ["Orange", "Brown"].includes(outcomeColor);
const attempt = parseAttempt(g("attempt"));
if ((rare === "Blue (valley)" && hour === "Tree") || (rare === "Shadow" && hour === "Valley"))
flags.push("rare-dragon answer does not match the path");
const goalRaw = g("goal_v2");
const goal = g("goal") || (goalRaw && goalRaw !== "Unknown" ? GOAL_V2[goalRaw] || goalRaw : null) || "(not asked/blank)";
return {
source, date, wing, section, squad: g("squad") || "Unknown", attempt,
attempt_group: attempt === 1 ? "First attempt" : attempt > 1 ? "Later attempt" : "Unknown/lost count",
goal: g("goal") || "(not asked/blank)", company, direction, first_sighting: first || "Unknown",
scream, resolution, combat_first: combat || "(not recorded)", post_path: post, hour, branch,
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)",
post_path: post, hour, branch,
enc_Red: enc.Red, enc_Green: enc.Green, enc_Orange: enc.Orange, enc_Brown: enc.Brown,
enc_Blue: enc.Blue, enc_Black: enc.Black,
outcome, outcome_color: outcomeColor, rescued,
saw_blue_meadow: !!(hour === "Valley" && enc.Blue),
saw_shadow: !!(hour === "Tree" && (enc.Blue || enc.Black)),
saw_blue_meadow: !!(hour === "Valley" && (enc.Blue || rare === "Blue (valley)")),
saw_shadow: !!(hour === "Tree" && (enc.Blue || enc.Black || rare === "Shadow")),
rare_reported: "rare" in C ? rare || "Unknown" : "(not asked)",
malek_intent: "malek" in C ? g("malek") || "Unknown" : "(not asked)",
tail: g("tail"),
data_flags: flags.join("; "),
death_note: redact(g("death_note")), bond_note: redact(g("bond_note")),
};
@@ -396,8 +498,9 @@
const sortedKeys = (o) => Object.keys(o).sort();
const stratum = (r) => r.source !== "Form" ? "Bulk logs (imports)" :
r.goal === "Blue" ? "Form: chasing Blue" : r.goal === "Black" ? "Form: chasing Black" : "Form: other/blank goal";
const goal2 = (r) => ["Blue", "Black"].includes(r.goal) ? r.goal : r.goal === "(not asked/blank)" ? "Blank/not asked" : "Other colour/any";
r.goal === "Blue" ? "Form: chasing Blue" : r.goal === "Black" ? "Form: chasing Black" :
r.goal === "Blue or Black" ? "Form: chasing Blue or Black" : "Form: other/blank goal";
const goal2 = (r) => isRareGoal(r.goal) ? r.goal : r.goal === "(not asked/blank)" ? "Blank/not asked" : "Other colour/any";
// Denominators for each outcome ("who could have had this outcome?")
const OUTCOMES = {
@@ -423,7 +526,7 @@
}
const FACTORS = ["company", "direction", "first_sighting", "scream", "resolution", "combat_first",
"post_path", "hour", "wing", "squad", "attempt_group", "source", "goal"];
"post_path", "hour", "wing", "squad", "attempt_group", "source", "goal", "sighting_action", "combat_second", "malek_intent"];
// Encounter contexts: which recorded dragon attempt belongs to which in-game encounter.
const CONTEXTS = [
@@ -441,8 +544,8 @@
return runs.filter((r) => {
if (f.source === "form" && r.source !== "Form") return false;
if (f.source === "bulk" && r.source === "Form") return false;
if (f.goal === "exclude_rare" && ["Blue", "Black"].includes(r.goal)) return false;
if (f.goal === "only_rare" && !["Blue", "Black"].includes(r.goal)) return false;
if (f.goal === "exclude_rare" && isRareGoal(r.goal)) return false;
if (f.goal === "only_rare" && !isRareGoal(r.goal)) return false;
if (f.excludeFlagged && r.data_flags) return false;
return true;
});
@@ -540,7 +643,7 @@
res.encounters = CONTEXTS.map(([name, where, col, color]) => {
const A = runs.filter((r) => where(r) && ["Bonded!", "Incinerated"].includes(r[col]));
const win = (r) => r[col] === "Bonded!";
const intent = A.filter((r) => r.goal === color || r.goal.startsWith("Any"));
const intent = A.filter((r) => r.goal === color || r.goal.startsWith("Any") || (r.goal === "Blue or Black" && (color === "Blue" || color === "Black")));
const byS = groupBy(A, stratum);
return {
context: name, color, overall: rate(A, win), intent_matched: rate(intent, win),