Collection as an ETL pipeline; runs_clean.csv from every source; Report a run

- collection/pipeline.yaml declares every source (extract kind, transform,
  privacy rules, load target, run source); `python -m collection update|build`
- extract keeps data/raw/<source>/current + previous only (git-ignored);
  data/manifest.json records the current raw checksum and change date
- transforms are pure; validate checks runs against data/dictionary.yaml
  before load; load writes byte-stable files only when they change
- data/public/runs_clean.csv: every run from every source with a new
  `source` column (reddit spreadsheet, reddit thread, reported, bot,
  reddit pdf); the sheet's own row label moves to `entry`; run_id is text
- bot importer ported to Python (same output as bot.js on the fixture);
  labels and crosswalk in collection/specs/bot.yaml, written into graph.js
- Reddit through the official API (result links to add by hand); the 12
  result pages move to collection/manual/reddit_results.yaml
- "Report a run": a GitHub issue form generated from
  collection/specs/report_form.yaml, collected as source "reported", plus a
  site tab pointing to it, the community spreadsheet and the megathread
- analysis and the route model read runs_clean.csv (sources in
  measures.yaml); stats.json and policy.json unchanged apart from the
  factor's new name
- daily workflow runs the pipeline; the raw store is kept between runs in
  the Actions cache, encrypted with RAW_ARCHIVE_KEY

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-04 02:46:48 +00:00
co-authored by Claude Opus 5.5
parent 61bc50583c
commit 3b24a11f5a
64 changed files with 8626 additions and 6909 deletions
+6 -1
View File
@@ -6,6 +6,11 @@
# (not blank), {any: [condition, ...]} (at least one). Several fields in one condition must all hold.
version: 1
# Which runs of data/public/runs_clean.csv the statistics use (its `source` column). Runs from the other sources
# (reported, bot, Reddit result pages) are in the published file but not in these statistics yet: they are coded
# from different questions, and the bot follows a strategy, so pooling them needs its own review.
sources: [reddit spreadsheet]
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).
@@ -34,7 +39,7 @@ bonded_outcome:
# 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]
attempt_group, entry, goal, sighting_action, combat_second, malek_intent]
# Route targets: the outcome (event) and which runs could have reached it at all (pool)
targets:
+20 -17
View File
@@ -19,6 +19,7 @@ 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 atlas import runs as runs_io # 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
@@ -95,7 +96,7 @@ def is_rare(goal):
def stratum(r):
if r["source"] != "Form":
if r["entry"] != "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")
@@ -107,9 +108,9 @@ def goal2(r):
def apply_filters(runs, f):
def ok(r):
if f.get("source") == "form" and r["source"] != "Form":
if f.get("source") == "form" and r["entry"] != "Form":
return False
if f.get("source") == "bulk" and r["source"] == "Form":
if f.get("source") == "bulk" and r["entry"] == "Form":
return False
if f.get("goal") == "exclude_rare" and is_rare(r["goal"]):
return False
@@ -196,7 +197,7 @@ def analyse(all_runs, filters):
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()},
"sources": {k: len(v) for k, v in group_by(runs, "entry").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()},
@@ -208,7 +209,7 @@ def analyse(all_runs, filters):
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"]
form = [r for r in D if r["entry"] == "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)}
@@ -239,7 +240,7 @@ def analyse(all_runs, filters):
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
src2 = lambda r: "Form submission" if r["entry"] == "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")}),
@@ -256,7 +257,7 @@ def analyse(all_runs, filters):
"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")}
for s, g in group_by(runs, "entry").items()} for key in ("blue_meadow", "shadow")}
return res
@@ -508,23 +509,25 @@ def build(runs, rows, exported=None):
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("--data", default=str(runs_io.PATH))
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"))
runs = runs_io.read(a.data, sources=M["sources"])
out = build(runs, len(runs), 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")
def exported():
"""When the community spreadsheet last changed (data/manifest.json), else the date in its public file."""
m = ROOT / "data/manifest.json"
entry = json.loads(m.read_text(encoding="utf-8")).get("reddit_spreadsheet") if m.exists() else None
if entry:
return entry["changed"]
return json.loads((ROOT / "data/public/form_responses.json").read_text(encoding="utf-8")).get("exported")
if __name__ == "__main__":
main()