Game-rule checks for runs answered through "Report a run"
Reported and Reddit-comment runs now get the checks the community form gets in core/atlas/coding.py, as data_flags (the run is kept): - first dragon outside the documented pool for the company/direction - a bond or burn by a dragon the encounter does not have (new encounter_colours table in core/spec/form.yaml; Orange/Brown after the two Greens allowed, as a Green's rescue) - a Green on a valley run - a cadet outcome off its scream path, fight answers or a post-fight path on a run that did not help, a second fight move without assessing - died before the hour, yet reached the tree/valley or an encounter planner/policy.yaml drop_flagged: flagged runs of sources read from free text (reddit comment) stay out of the route model; provenance notes do not count as flags. No effect today: the source is not in `sources` yet. On the first 82 scraped runs: 6 flagged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -191,11 +191,63 @@ def answers_row(run_id, source, date, answers, flags=None):
|
||||
row["saw_blue_meadow"] = True
|
||||
if row["outcome"] == "Bonded" and not row["outcome_color"]:
|
||||
flags.append("bonded, colour not given")
|
||||
flags += rule_flags(row)
|
||||
encounter_columns(row)
|
||||
row["data_flags"] = "; ".join(flags)
|
||||
return row
|
||||
|
||||
|
||||
# the scream answer each cadet outcome follows (a run cannot end the encounter on another path)
|
||||
CADET_PATH = {
|
||||
"Killed the bullies yourself": "Investigate & help", "Squadmate's revenge": "Investigate & help",
|
||||
"Left bullies to the dragons": "Investigate & help", "DIED in combat": "Investigate & help",
|
||||
"Tourniquet": "Ignore the scream", "Left injured cadet": "Ignore the scream", "Took their weapons": "Ignore the scream",
|
||||
"Left them to it": "Investigate & leave",
|
||||
}
|
||||
REACHED = ("Tree", "Valley")
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=1)
|
||||
def _form_rules():
|
||||
from atlas import spec as atlas_spec
|
||||
f = atlas_spec.form()
|
||||
return f["sighting_pool"], {k: set(v) for k, v in f["encounter_colours"].items()}
|
||||
|
||||
|
||||
def rule_flags(row):
|
||||
"""The game's own rules, for runs answered through "Report a run": the checks core/atlas/coding.py makes on
|
||||
the community form (first-dragon pools, Greens in the valley) plus the encounter's dragons and the cadet path.
|
||||
Each broken rule is a flag; the run is kept."""
|
||||
pools, enc_colours = _form_rules()
|
||||
flags = []
|
||||
company, direction, first = row["company"], row["direction"], row["first_sighting"]
|
||||
if company in pools and direction in pools[company] and first in COLOURS:
|
||||
pool = list(pools[company][direction]) + (list(pools["Alone"][direction]) if row["left_squadmates"] is True else [])
|
||||
if first not in pool:
|
||||
flags.append(f"first sighting {first} not in documented pool for {company}/{direction}")
|
||||
colour, branch = row["outcome_color"], row["branch"]
|
||||
if row["outcome"] in ("Bonded", "Incinerated") and colour:
|
||||
if branch in enc_colours and colour not in enc_colours[branch]:
|
||||
flags.append(f"{colour} at the {branch} encounter, which has only {'/'.join(sorted(enc_colours[branch]))}")
|
||||
if row["hour"] == "Valley" and colour == "Green":
|
||||
flags.append("Green recorded on a Valley run (no Greens in the valley)")
|
||||
scream, res = row["scream"], row["resolution"]
|
||||
if scream in ("Investigate & help", "Ignore the scream", "Investigate & leave"):
|
||||
if res in CADET_PATH and CADET_PATH[res] != scream:
|
||||
flags.append(f"cadet outcome {res!r} does not follow {scream!r}")
|
||||
if scream != "Investigate & help" and (row["combat_first"] not in (None, "(not recorded)")
|
||||
or row["combat_second"] not in (None, "(not recorded)")):
|
||||
flags.append("fight answers on a run that did not help")
|
||||
if scream != "Investigate & help" and row["post_path"] in ("Forest", "West", "East"):
|
||||
flags.append("a path after the fight on a run without a fight")
|
||||
if row["combat_second"] not in (None, "(not recorded)") and row["combat_first"] != "Assess the situation":
|
||||
flags.append("a second fight move without pausing to assess")
|
||||
died_early = (scream or "").startswith("DIED") or (res or "").startswith("DIED")
|
||||
if died_early and (row["hour"] in REACHED or row["outcome"] in ("Bonded", "Incinerated")):
|
||||
flags.append("died before the hour, yet reached the tree, the valley or a bonding encounter")
|
||||
return flags
|
||||
|
||||
|
||||
def _norm(text):
|
||||
from .transform.bot import normalize
|
||||
return normalize(text)
|
||||
|
||||
@@ -153,6 +153,17 @@ sighting_pool:
|
||||
1 Squadmate: { East: [Green, Orange, Red], West: [Red, Brown, Green], Center: [Red, Brown] }
|
||||
2 Squadmates: { East: [Red, Orange], West: [Green, Brown, Red], Center: [Red, Brown] }
|
||||
|
||||
# The dragons each bonding encounter can end with (bond or burn), from the community PDF. Only used to FLAG runs
|
||||
# answered through "Report a run" (reported, reddit comment) that end with a dragon the encounter does not have.
|
||||
# Orange and Brown after the two Greens: a Green's rescue, then the Orange or Brown.
|
||||
encounter_colours:
|
||||
"Shadow (rare)": [Blue, Black]
|
||||
"Descend quickly: Red": [Red]
|
||||
"Descend quickly: let the Red pass": [Green]
|
||||
"Descend slowly: two Greens": [Green, Orange, Brown]
|
||||
"Valley Red": [Red]
|
||||
"Passed the Red: meadow": [Orange, Brown, Blue]
|
||||
|
||||
# First-sighting answers that are not a single colour: coded as this colour, and the row is flagged with the
|
||||
# original answer (data_flags), so nothing is lost.
|
||||
first_sighting_alias:
|
||||
|
||||
+10
-1
@@ -36,6 +36,15 @@ def low_bias(r, lb=CONFIG["low_bias"]):
|
||||
return r["goal"] not in lb["rare_goals"]
|
||||
|
||||
|
||||
def drop_flagged(runs, cfg=CONFIG.get("drop_flagged") or {}):
|
||||
"""Without the flagged runs of the sources read automatically from free text (planner/policy.yaml drop_flagged)."""
|
||||
sources, keep = set(cfg.get("sources") or ()), tuple(cfg.get("except") or ())
|
||||
|
||||
def problems(r):
|
||||
return [f for f in (r.get("data_flags") or "").split("; ") if f and not f.startswith(keep)] if keep else [f for f in (r.get("data_flags") or "").split("; ") if f]
|
||||
return [r for r in runs if r["source"] not in sources or not problems(r)]
|
||||
|
||||
|
||||
def clean(o):
|
||||
"""JSON-safe: numpy numbers to floats, infinities and NaN to null (as JavaScript's JSON.stringify does)."""
|
||||
if isinstance(o, dict):
|
||||
@@ -56,7 +65,7 @@ def main(argv=None):
|
||||
ap.add_argument("--out", default=str(ROOT / "data/public/policy.json"))
|
||||
a = ap.parse_args(argv)
|
||||
|
||||
runs = runs_io.read(a.data, sources=SOURCES)
|
||||
runs = drop_flagged(runs_io.read(a.data, sources=SOURCES))
|
||||
rows = len(runs)
|
||||
samples = {
|
||||
"all": runs,
|
||||
|
||||
@@ -8,6 +8,14 @@ version: 1
|
||||
# the `source` values of data/public/runs_clean.csv the model learns from
|
||||
sources: [reddit spreadsheet, reported, bot]
|
||||
|
||||
# Sources read automatically from free text: a run with any data flag (a broken game rule, an unrecognised answer)
|
||||
# is left out of the model, since the flag may mean the text was misread or misremembered. Flags that only say where
|
||||
# the run came from (`except`, matched at the start of a flag) do not count. A hand fix that clears the flags
|
||||
# brings the run back. Applies once the source is also listed in `sources` above.
|
||||
drop_flagged:
|
||||
sources: [reddit comment]
|
||||
except: ["read from a Reddit comment"]
|
||||
|
||||
# Two samples. "all" is every run above. "lowBias" leaves out runs where a rare sighting is more likely to have
|
||||
# been reported than a miss: form submissions and reports from riders chasing Blue or Black. The bot logs every
|
||||
# run, and bulk-pasted logs record every run of the players who kept them, so both stay in.
|
||||
|
||||
@@ -278,7 +278,7 @@ class RedditComments(unittest.TestCase):
|
||||
"answers": {"company": "Alone", "outcome": "Incinerated at a bonding encounter", "outcome_color": "Red"}}]}),
|
||||
encoding="utf-8")
|
||||
manual = TMP / "reddit_comments_manual.yaml"
|
||||
manual.write_text("reject: [c2]\nfix: {c1: {outcome_color: Blue, direction: null}}\n"
|
||||
manual.write_text("reject: [c2]\nfix: {c1: {outcome_color: Blue, branch: 'Valley: passed the Red, the meadow', direction: null}}\n"
|
||||
"add: [{id: c9, thread: abc, posted: '2026-11-16', "
|
||||
"answers: {company: Two squadmates, direction: West (toward the scent), outcome: Died before the hour}}]\n",
|
||||
encoding="utf-8")
|
||||
@@ -286,12 +286,53 @@ class RedditComments(unittest.TestCase):
|
||||
self.assertEqual([r["run_id"] for r in rows], ["comment-c1", "comment-c3", "comment-c9"])
|
||||
c1, c3, c9 = rows
|
||||
self.assertEqual((c1["source"], c1["outcome_color"], c1["direction"], c1["hour"], c1["enc_Blue"]),
|
||||
("reddit comment", "Blue", "Unknown", "Tree", "Bonded!"))
|
||||
("reddit comment", "Blue", "Unknown", "Valley", "Bonded!"))
|
||||
self.assertEqual(c1["data_flags"], "read from a Reddit comment")
|
||||
self.assertEqual(c3["data_flags"], "read from a Reddit comment automatically, not checked by hand")
|
||||
self.assertEqual((c9["company"], c9["direction"], c9["hour"]), ("2 Squadmates", "West", "DIED before the hour"))
|
||||
self.assertEqual(validate.problems(rows, runs.DICT), [])
|
||||
|
||||
def test_game_rules_flag_impossible_runs(self):
|
||||
def flags(**answers):
|
||||
return runs.answers_row("x", "reddit comment", None, answers)["data_flags"]
|
||||
ok = flags(company="Alone", direction="East (toward the roar)", first_sighting="Orange",
|
||||
scream="Kept walking (ignored it)", resolution="Wounded cadet: tourniquet",
|
||||
branch="Tree: climbed down slowly to the two Greens", outcome="Bonded", outcome_color="Brown")
|
||||
self.assertEqual(ok, "") # Brown after the Greens: a Green's rescue
|
||||
cases = {
|
||||
"first sighting Orange not in documented pool for Alone/Center":
|
||||
dict(company="Alone", direction="Toward the forest centre", first_sighting="Orange", outcome="Died before the hour"),
|
||||
"Brown at the Shadow (rare) encounter, which has only Black/Blue":
|
||||
dict(branch="Tree: the shadow (Blue or Black)", outcome="Bonded", outcome_color="Brown"),
|
||||
"Red at the Passed the Red: meadow encounter":
|
||||
dict(branch="Valley: passed the Red, the meadow", outcome="Incinerated at a bonding encounter", outcome_color="Red"),
|
||||
"Green recorded on a Valley run":
|
||||
dict(hour="Went to the valley centre", outcome="Bonded", outcome_color="Green"),
|
||||
"does not follow 'Ignore the scream'":
|
||||
dict(scream="Kept walking (ignored it)", resolution="Bullies: my squadmate's revenge", outcome="Died before the hour"),
|
||||
"fight answers on a run that did not help":
|
||||
dict(scream="Kept walking (ignored it)", combat_first="Pause to assess", outcome="Died before the hour"),
|
||||
"a path after the fight on a run without a fight":
|
||||
dict(scream="Investigated, and walked away", post_path="West", outcome="Died before the hour"),
|
||||
"a second fight move without pausing to assess":
|
||||
dict(scream="Investigated, and helped my squadmate", combat_first="Charge the smaller cadet",
|
||||
combat_second="Engage the smaller cadet", outcome="Died before the hour"),
|
||||
"died before the hour, yet reached":
|
||||
dict(scream="Investigated, and helped my squadmate", resolution="I died in the fight", outcome="Bonded", outcome_color="Red"),
|
||||
}
|
||||
for expected, answers in cases.items():
|
||||
self.assertIn(expected, flags(**answers), expected)
|
||||
|
||||
def test_flagged_comment_runs_stay_out_of_the_route_model(self):
|
||||
sys.path.insert(0, str(ROOT / "planner"))
|
||||
import build_policy
|
||||
rows = [{"source": "reddit comment", "data_flags": "read from a Reddit comment automatically, not checked by hand"},
|
||||
{"source": "reddit comment", "data_flags": "read from a Reddit comment; Green recorded on a Valley run (no Greens in the valley)"},
|
||||
{"source": "reddit spreadsheet", "data_flags": "multiple wings"},
|
||||
{"source": "reported", "data_flags": "Green recorded on a Valley run (no Greens in the valley)"}]
|
||||
kept = build_policy.drop_flagged(rows)
|
||||
self.assertEqual([r["source"] for r in kept], ["reddit comment", "reddit spreadsheet", "reported"])
|
||||
|
||||
def test_delivered_not_extracted(self):
|
||||
spec = read_yaml("collection/pipeline.yaml")["sources"]["reddit_comments"]
|
||||
with self.assertRaises(extract.Skip):
|
||||
|
||||
Reference in New Issue
Block a user