48 changed files with 9765 additions and 14262 deletions
+2 -4
View File
@@ -10,11 +10,9 @@
# DK_ACCOUNT_SALT the salt account names are hashed with (the same one every time) # DK_ACCOUNT_SALT the salt account names are hashed with (the same one every time)
# ATLAS_BOT_TOKEN as in update-sources.yml # ATLAS_BOT_TOKEN as in update-sources.yml
name: Bot cycle name: Bot cycle
# Not scheduled: no runner has the `bot-host` label yet (issue #27), and the bot's data already arrives through the
# daily source check. Put the schedule back once Ken adds a runner on the bot's machine:
# schedule:
# - cron: "41 */4 * * *"
on: on:
schedule:
- cron: "41 */4 * * *"
workflow_dispatch: workflow_dispatch:
jobs: jobs:
cycle: cycle:
-37
View File
@@ -1,37 +0,0 @@
# The published Atlas page. Every push to main builds the static site (npm run build -> dist/) and force-pushes it
# as the single commit of the `pages` branch. Ken's server serves that branch as plain files (a web server whose
# folder is kept in step with the branch: a git-sync sidecar, or `git pull` on a timer). The repository is public,
# so his server needs no token. Only the build output is on `pages`, never the raw data.
#
# Secrets: ATLAS_BOT_TOKEN (as in update-sources.yml), to push the branch.
name: Publish the site (pages branch)
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: pages
cancel-in-progress: true
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm run build
- name: Push dist/ as the pages branch
env:
ATLAS_BOT_TOKEN: ${{ secrets.ATLAS_BOT_TOKEN }}
run: |
cd dist
git init -q -b pages
git config user.name "Atlas data bot"
git config user.email "atlas-bot@noreply.localhost"
git add -A
git commit -q -m "site built from ${GITHUB_SHA::8}"
GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.https://git.kenschiano.net/.extraheader" \
GIT_CONFIG_VALUE_0="AUTHORIZATION: token $ATLAS_BOT_TOKEN" \
git push -q -f "https://git.kenschiano.net/${GITHUB_REPOSITORY}.git" pages
echo "pages branch updated from ${GITHUB_SHA::8}"
+3 -4
View File
@@ -1,6 +1,6 @@
# When the route model changes on main, send it to the bot: open (or update) a pull request on the bot's repo, # When the route model changes on main, send it to the bot: open (or update) a pull request on the bot's repo,
# DragonKind/DragonKind, that replaces vendor/threshing-atlas/{policy.json,solver.js,graph.js,known_answers.json} with # DragonKind/DragonKind, that replaces vendor/threshing-atlas/{policy.json,solver.js,graph.js} with this repo's
# this repo's data/public/policy.json, core/solver.js, core/graph.js and data/public/known_answers.json. They always travel together, so the policy and the # data/public/policy.json, core/solver.js and core/graph.js. The three always travel together, so the policy and the
# solver that reads it never get out of step. Ken reviews and merges it; the running bot reloads the files after a pull. # solver that reads it never get out of step. Ken reviews and merges it; the running bot reloads the files after a pull.
# #
# Secrets: ATLAS_BOT_TOKEN (repository: read and write, with write access to DragonKind/DragonKind). # Secrets: ATLAS_BOT_TOKEN (repository: read and write, with write access to DragonKind/DragonKind).
@@ -12,7 +12,6 @@ on:
- data/public/policy.json - data/public/policy.json
- core/solver.js - core/solver.js
- core/graph.js - core/graph.js
- data/public/known_answers.json
workflow_dispatch: workflow_dispatch:
jobs: jobs:
send: send:
@@ -35,7 +34,7 @@ jobs:
GIT_CONFIG_VALUE_0="AUTHORIZATION: token $ATLAS_BOT_TOKEN" GIT_CONFIG_VALUE_0="AUTHORIZATION: token $ATLAS_BOT_TOKEN"
git clone --quiet --depth 1 https://git.kenschiano.net/DragonKind/DragonKind.git "$dst" git clone --quiet --depth 1 https://git.kenschiano.net/DragonKind/DragonKind.git "$dst"
mkdir -p "$dst/vendor/threshing-atlas" mkdir -p "$dst/vendor/threshing-atlas"
cp data/public/policy.json core/solver.js core/graph.js data/public/known_answers.json "$dst/vendor/threshing-atlas/" cp data/public/policy.json core/solver.js core/graph.js "$dst/vendor/threshing-atlas/"
id=$(python3 -c "import json; print(json.load(open('data/public/policy.json')).get('id', ''))") id=$(python3 -c "import json; print(json.load(open('data/public/policy.json')).get('id', ''))")
sha=$(git rev-parse --short HEAD) sha=$(git rev-parse --short HEAD)
cd "$dst" cd "$dst"
-31
View File
@@ -1,31 +0,0 @@
# A review summary on every Reddit scraper pull request (issue #23): the runs added, changed and gone, the ones that
# break a game rule, other flags, possible copies of form rows, and result pages already counted. Posted as one
# comment on the pull request, refreshed on every push. The reviewer corrects runs in
# collection/manual/reddit_comments.yaml (collection/README.md, "Reviewing Reddit runs"), then merges.
#
# Secrets: ATLAS_BOT_TOKEN (as in update-sources.yml), to post the comment.
name: Review Reddit runs
on:
pull_request:
paths:
- data/public/reddit_comments.json
- collection/manual/reddit_comments.yaml
jobs:
summary:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -r requirements.txt
- name: The file as it is on main
run: |
git fetch --depth 1 origin "${{ github.base_ref }}"
git show FETCH_HEAD:data/public/reddit_comments.json > "$RUNNER_TEMP/base.json" || echo '{"runs": []}' > "$RUNNER_TEMP/base.json"
- name: Build the runs and post the summary
env:
ATLAS_BOT_TOKEN: ${{ secrets.ATLAS_BOT_TOKEN }}
run: |
python -m collection build
python -m collection review-reddit --base "$RUNNER_TEMP/base.json" --out "$RUNNER_TEMP/review.md" --pr "${{ github.event.pull_request.number }}"
-4
View File
@@ -16,10 +16,6 @@ on:
schedule: schedule:
- cron: "23 10 * * *" # daily - cron: "23 10 * * *" # daily
workflow_dispatch: workflow_dispatch:
# one check at a time: a second dispatch waits instead of building and pushing alongside the first
concurrency:
group: update-sources
cancel-in-progress: false
jobs: jobs:
check: check:
runs-on: ubuntu-latest # a runner label on the server (act_runner) runs-on: ubuntu-latest # a runner label on the server (act_runner)
+2 -1
View File
@@ -166,7 +166,8 @@ venv.bak/
# Rope project settings # Rope project settings
.ropeproject .ropeproject
# (mkdocs' /site is not ignored: site/ here is the Atlas page) # mkdocs/Zensical documentation
/site
# mypy # mypy
.mypy_cache/ .mypy_cache/
+9 -40
View File
@@ -35,17 +35,9 @@ def group(r):
return "bot" return "bot"
if r["source"] == "reddit spreadsheet": if r["source"] == "reddit spreadsheet":
return "form" if r["entry"] == "Form" else "bulk logs" return "form" if r["entry"] == "Form" else "bulk logs"
if r["source"] == "reddit comment":
return "Reddit comments"
if r["source"] == "reported":
return "reported"
return "other" return "other"
GROUP_NAMES = {"form": "Form submissions", "bulk logs": "Bulk logs", "bot": "Bot", "Reddit comments": "Reddit comments",
"reported": "Reported on the Atlas"}
def tally(rows, key): def tally(rows, key):
d = collections.OrderedDict() d = collections.OrderedDict()
for r in rows: for r in rows:
@@ -118,20 +110,17 @@ def build():
"another) are still fair if the over-reporting is the same on both sides.", ""] "another) are still fair if the over-reporting is the same on both sides.", ""]
# 1. by attempt # 1. by attempt
# the self-reported sources (Reddit comments, "Report a run") get a column once they have a gated tree run L += ["## 1. The shadow by attempt number", "", "| Attempt | Form submissions | Bulk logs | Bot |", "|---|---|---|---|"]
groups = ["form", "bulk logs", "bot"] + [g for g in ("Reddit comments", "reported") if any(group(r) == g for r in G)]
L += ["## 1. The shadow by attempt number", "", "| Attempt | " + " | ".join(GROUP_NAMES[g] for g in groups) + " |",
"|---" * (len(groups) + 1) + "|"]
bands = [("1", 1, 1), ("2", 2, 2), ("3", 3, 3), ("4-10", 4, 10), ("11-30", 11, 30), ("31 or more", 31, 10 ** 9)] bands = [("1", 1, 1), ("2", 2, 2), ("3", 3, 3), ("4-10", 4, 10), ("11-30", 11, 30), ("31 or more", 31, 10 ** 9)]
for name, lo, hi in bands: for name, lo, hi in bands:
cells = [] cells = []
for g in groups: for g in ("form", "bulk logs", "bot"):
rs = [r for r in G if group(r) == g and r["attempt"] and lo <= r["attempt"] <= hi] rs = [r for r in G if group(r) == g and r["attempt"] and lo <= r["attempt"] <= hi]
cells.append(frac(sum(bool(r["saw_shadow"]) for r in rs), len(rs))) cells.append(frac(sum(bool(r["saw_shadow"]) for r in rs), len(rs)))
facts["by_attempt"].setdefault(g, {})[name] = [sum(bool(r["saw_shadow"]) for r in rs), len(rs)] facts["by_attempt"].setdefault(g, {})[name] = [sum(bool(r["saw_shadow"]) for r in rs), len(rs)]
L.append(f"| {name} | " + " | ".join(cells) + " |") L.append(f"| {name} | " + " | ".join(cells) + " |")
cells = [] cells = []
for g in groups: for g in ("form", "bulk logs", "bot"):
rs = [r for r in G if group(r) == g and not r["attempt"]] rs = [r for r in G if group(r) == g and not r["attempt"]]
cells.append(frac(sum(bool(r["saw_shadow"]) for r in rs), len(rs))) cells.append(frac(sum(bool(r["saw_shadow"]) for r in rs), len(rs)))
L.append("| not given | " + " | ".join(cells) + " |") L.append("| not given | " + " | ".join(cells) + " |")
@@ -141,14 +130,6 @@ def build():
f"{len(complete_later)} later ones, with {sum(bool(r['saw_shadow']) for r in complete_first + complete_later)} shadows. " f"{len(complete_later)} later ones, with {sum(bool(r['saw_shadow']) for r in complete_first + complete_later)} shadows. "
f"Zero in {len(complete_later)} later attempts rules out a rate above {100 * upper(len(complete_later)):.1f}% for them; " f"Zero in {len(complete_later)} later attempts rules out a rate above {100 * upper(len(complete_later)):.1f}% for them; "
f"zero in {len(complete_first)} first attempts only rules out more than {100 * upper(len(complete_first)):.0f}%.", ""] f"zero in {len(complete_first)} first attempts only rules out more than {100 * upper(len(complete_first)):.0f}%.", ""]
rc = [r for r in runs if r["source"] == "reddit comment" and r["saw_shadow"]]
if rc:
rg = [r for r in G if group(r) == "Reddit comments" and r["saw_shadow"]]
facts["reddit_shadows"] = {"all": len(rc), "gated": len(rg), "first_attempt": sum(r["attempt"] == 1 for r in rc)}
L += [f"Reddit comments describe {len(rc)} shadows in all, but a comment rarely says how the run began: only "
f"{len(rg)} say the rider helped their squadmate and climbed the tree (the table above), and "
f"{sum(r['attempt'] == 1 for r in rc)} say it was a first attempt. Like form submissions, they are posted by "
"choice, so they say what shadow runs look like, not how often the shadow comes.", ""]
# 2. the same route, first against later # 2. the same route, first against later
F = [r for r in G if group(r) == "form" and r["attempt"]] F = [r for r in G if group(r) == "form" and r["attempt"]]
@@ -160,8 +141,7 @@ def build():
c[i + 1] += 1 c[i + 1] += 1
orr, obs, exp, z = mantel_haenszel(by.values()) orr, obs, exp, z = mantel_haenszel(by.values())
facts["same_route"] = {"routes": len(by), "first_shadows": round(obs), "expected": round(exp, 1), facts["same_route"] = {"routes": len(by), "first_shadows": round(obs), "expected": round(exp, 1),
"odds_ratio": round(orr, 1) if math.isfinite(orr) else None, # JSON has no Infinity "odds_ratio": round(orr, 1), "z": round(z, 1)}
"z": round(z, 1)}
facts["form_first"] = [sum(c[0] for c in by.values()), sum(c[1] for c in by.values())] facts["form_first"] = [sum(c[0] for c in by.values()), sum(c[1] for c in by.values())]
facts["form_later"] = [sum(c[2] for c in by.values()), sum(c[3] for c in by.values())] facts["form_later"] = [sum(c[2] for c in by.values()), sum(c[3] for c in by.values())]
L += ["## 2. The same route on a first attempt and on a later one", "", L += ["## 2. The same route on a first attempt and on a later one", "",
@@ -173,7 +153,7 @@ def build():
L.append(f"| {' / '.join(key)} | {frac(y1, n1)} | {frac(y0, n0)} |") L.append(f"| {' / '.join(key)} | {frac(y1, n1)} | {frac(y0, n0)} |")
L += ["", f"Across all {len(by)} recorded routes, comparing first and later attempts on the same route: " L += ["", f"Across all {len(by)} recorded routes, comparing first and later attempts on the same route: "
f"{obs:.0f} first-attempt shadows where {exp:.1f} would be expected if the attempt did not matter " f"{obs:.0f} first-attempt shadows where {exp:.1f} would be expected if the attempt did not matter "
f"(odds ratio {f'{orr:.1f}' if math.isfinite(orr) else 'unbounded: no later-attempt shadow at all'}, z = {z:.1f}). First and later attempts choose almost the same routes, so the " f"(odds ratio {orr:.1f}, z = {z:.1f}). First and later attempts choose almost the same routes, so the "
"difference is not in the recorded choices: it is something about the account, or a choice the form does " "difference is not in the recorded choices: it is something about the account, or a choice the form does "
"not record.", ""] "not record.", ""]
@@ -206,20 +186,9 @@ def build():
("combat_second", "The dagger"), ("resolution", "The bullies' fate"), ("post_path", "The fork")): ("combat_second", "The dagger"), ("resolution", "The bullies' fate"), ("post_path", "The fork")):
t = collections.Counter(r[col] for r in S1) t = collections.Counter(r[col] for r in S1)
L.append(f"- **{label}:** " + ", ".join(f"{k} {v}" for k, v in t.most_common())) L.append(f"- **{label}:** " + ", ".join(f"{k} {v}" for k, v in t.most_common()))
# a gate counts as missed only when the run answers it otherwise; a run that does not say (a short Reddit outside = [r for r in runs if r["saw_shadow"] and not (r["scream"] == "Investigate & help" and r["hour"] == "Tree")]
# comment, a blank form answer) is not a contradiction facts["shadow_routes"] = {"runs": len(S1), "routes": len({tuple(r[k] for k in ROUTE) for r in S1}), "off_gate": len(outside)}
def stated(v): L += ["", f"Shadows reported without both gates: {len(outside)} (likely mis-entered).", ""]
return bool(v) and v != "Unknown" and not str(v).startswith("(")
def contradicts(r):
return (stated(r["scream"]) and r["scream"] != "Investigate & help") or (stated(r["hour"]) and r["hour"] != "Tree")
outside = [r for r in runs if r["saw_shadow"] and contradicts(r)]
unstated = [r for r in runs if r["saw_shadow"] and not contradicts(r)
and not (r["scream"] == "Investigate & help" and r["hour"] == "Tree")]
facts["shadow_routes"] = {"runs": len(S1), "routes": len({tuple(r[k] for k in ROUTE) for r in S1}),
"off_gate": len(outside), "gates_unstated": len(unstated)}
L += ["", f"Shadows reported with an answer that contradicts a gate: {len(outside)} (likely mis-entered or misread). "
f"Another {len(unstated)} do not say whether they passed both gates.", ""]
# 5. after the shadow # 5. after the shadow
SH = [r for r in runs if r["saw_shadow"]] SH = [r for r in runs if r["saw_shadow"]]
@@ -286,7 +255,7 @@ def main(argv=None):
ap.add_argument("--check", action="store_true") ap.add_argument("--check", action="store_true")
a = ap.parse_args(argv) a = ap.parse_args(argv)
text, facts = build() text, facts = build()
data = json.dumps(facts, ensure_ascii=False, indent=1, allow_nan=False) + "\n" data = json.dumps(facts, ensure_ascii=False, indent=1) + "\n"
if a.check: if a.check:
for path, want in ((OUT, text), (OUT_JSON, data)): for path, want in ((OUT, text), (OUT_JSON, data)):
if not path.exists() or path.read_text(encoding="utf-8") != want: if not path.exists() or path.read_text(encoding="utf-8") != want:
-131
View File
@@ -1,131 +0,0 @@
"""Known answers: what the Atlas knows about every answer the bot can be offered, for screens its other sources don't
cover (issue #35). The bot looks the screen's choices up here first (solver.js `knownAnswer`), and passes what it finds
to Clef as evidence when nothing is certain.
python analysis/known/build_known.py [--check] -> data/public/known_answers.json
Two sources, keyed by the answer text normalised exactly as the bot does (collection/etl/transform/bot.py normalize):
guide every answer in the community route PDF's encounter trees (data/public/pdf_encounters.json): the
encounter, how it ends there (or "continues"), the guide's rate, whether the guide marks it unconfirmed,
and `on_path`: the colours whose recommended path in the guide goes through it
bot every answer in the bot's screen tree (data/public/tree.json): times played, times it died straight
after, and the bonds the runs that took it ended in
"""
import argparse
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT))
from collection.etl.transform.bot import normalize # noqa: E402
GUIDE = ROOT / "data/public/pdf_encounters.json"
TREE = ROOT / "data/public/tree.json"
OUT = ROOT / "data/public/known_answers.json"
# the colours each of the guide's encounters can end in a bond with (the two Greens can also end with an Orange or a
# Brown swooping in), and the encounter a colour's route continues to from there (the shadow leads on to the Black)
ENC_COLOURS = {"valley-Red": ["Red"], "tree-Red": ["Red"], "tree-Greens": ["Green", "Brown", "Orange"],
"meadow-Orange": ["Orange"], "meadow-Brown": ["Brown"], "meadow-Blue": ["Blue"],
"shadow": ["Black", "Blue"], "black": ["Black"]}
ONWARD = {("shadow", "Black"): "Black"}
def is_goal(end, colour, onward):
end = end or ""
if onward:
return end.startswith(f"On to the {onward}")
if not (end.startswith("Bonded") or "Bonded (" in end):
return False
return "(" not in end or colour in end
def leads_to(o, colour, onward):
if "end" in o:
return is_goal(o["end"], colour, onward)
return any(not c.get("roll") and leads_to(c, colour, onward) for c in o.get("then", []))
def guide_path(options, colour, onward):
"""The guide's recommended answers toward `colour` (the same walk as the page's encounter panel)."""
out, opts = [], options
while opts:
live = [o for o in opts if not o.get("roll")]
pick = next((o for o in live if o.get("best") and leads_to(o, colour, onward)), None) \
or next((o for o in live if leads_to(o, colour, onward)), None)
if not pick:
break
out.append(id(pick))
if "end" in pick:
break
opts = pick.get("then", [])
return out
def walk(options, enc, on_path, out):
"""Every answer of an encounter, with its colours (where it happens) and on_path (whose recommended path)."""
for o in options:
if o.get("roll"):
continue
entry = {"encounter": enc, "colours": ENC_COLOURS.get(enc, []), "end": o.get("end", "continues")}
if o.get("pct"):
entry["pct"] = o["pct"]
if o.get("best"):
entry["best"] = True
if o.get("unconfirmed"):
entry["unconfirmed"] = True
cols = sorted(c for c, ids in on_path.items() if id(o) in ids)
if cols:
entry["on_path"] = cols
for text in [s.strip() for s in o["say"].split(", or ")]: # "Jump on its back, or jump to land…"
out.setdefault(normalize(text), {"text": text, "guide": []})["guide"].append(entry)
walk(o.get("then", []), enc, on_path, out)
def build():
g = json.loads(GUIDE.read_text(encoding="utf-8"))
out = {}
for enc, E in g["encounters"].items():
on_path = {c: set(guide_path(E["options"], c, ONWARD.get((enc, c)))) for c in ENC_COLOURS.get(enc, [])}
walk(E["options"], enc, on_path, out)
t = json.loads(TREE.read_text(encoding="utf-8")) if TREE.exists() else {"screens": {}}
for sc in t["screens"].values():
for o in sc["options"].values():
if not o.get("n"):
continue
k = normalize(o["text"])
e = out.setdefault(k, {"text": o["text"], "guide": []})
b = e.setdefault("bot", {"n": 0, "died": 0, "bonded": {}})
b["n"] += o["n"]
for dest, d in o.get("to", {}).items():
if dest == "DIED":
b["died"] += d["n"]
elif dest.startswith("BONDED:"):
c = dest.split(":", 1)[1]
b["bonded"][c] = b["bonded"].get(c, 0) + d["n"]
for e in out.values():
if not e["guide"]:
del e["guide"]
src = g["source"]
return {"schema": 1, "guide": {"title": src["title"], "version": src["version"], "link": src["link"]},
"bot": {"runs": (t.get("builtFrom") or {}).get("runs")}, "answers": dict(sorted(out.items()))}
def main(argv=None):
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--check", action="store_true")
a = ap.parse_args(argv)
text = json.dumps(build(), ensure_ascii=False, indent=1) + "\n"
if a.check:
if not OUT.exists() or OUT.read_text(encoding="utf-8") != text:
print(f"{OUT.relative_to(ROOT)} is out of date (run python analysis/known/build_known.py)", file=sys.stderr)
return 1
return 0
OUT.write_text(text, encoding="utf-8")
print(f"wrote {OUT.relative_to(ROOT)}")
return 0
if __name__ == "__main__":
sys.exit(main())
-112
View File
@@ -1,112 +0,0 @@
"""Is the same attempt reported twice, in the community form and in a Reddit comment? (issue #24)
python analysis/overlap/overlap.py [--check]
There are no player ids, so a copy can only be proven by a shared dragonkind.com result-page id. Neither the form
nor the register records one, and the comment-to-result-page link is already applied when the runs are built
(collection/etl/runs.py). Everything else is measured, never removed:
- a Reddit comment run is *comparable* when it is dated and gives at least MIN_ANSWERS route answers besides how it
ended (fewer answers match dozens of form rows by chance on a busy day);
- it *matches* a form row submitted within WINDOW days when every answer it gives is the form row's answer;
- the same test with the comment's date shifted by a few weeks (SHIFTS, only where the form has rows that week) is
what chance alone produces, so matched - expected is the estimate of runs reported twice.
Writes data/public/overlap.json (the page's Data & methods tab, and the scraper pull-request summary). Nothing is
dropped: identical routes are expected, and the Reddit runs already have their own reporting-bias group in the
route model (planner/policy.yaml).
"""
import argparse
import collections
import datetime as dt
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / "core"))
from atlas import runs as runs_io # noqa: E402
OUT = ROOT / "data/public/overlap.json"
FIELDS = ["company", "left_squadmates", "direction", "first_sighting", "sighting_action", "scream", "resolution",
"combat_first", "combat_second", "post_path", "hour", "branch", "outcome", "outcome_color", "tail", "attempt"]
ENDING = ("outcome", "outcome_color")
MIN_ANSWERS = 4
WINDOW = 1
SHIFTS = (-28, -21, -14, 14, 21, 28)
def given(v):
return v not in (None, "") and v != "Unknown" and not (isinstance(v, str) and v.startswith("("))
def answers(r):
return [k for k in FIELDS if given(r.get(k))]
def comparable(r):
return bool(r.get("date")) and len([k for k in answers(r) if k not in ENDING]) >= MIN_ANSWERS
def days(date, shift=0, window=WINDOW):
d = dt.date.fromisoformat(date[:10]) + dt.timedelta(days=shift)
return [(d + dt.timedelta(days=i)).isoformat() for i in range(-window, window + 1)]
def form_index(runs):
by_day = collections.defaultdict(list)
for r in runs:
if r["source"] == "reddit spreadsheet" and r.get("date"):
by_day[r["date"][:10]].append(r)
return by_day
def matches(c, by_day, shift=0):
"""Form rows within the window that give every answer the comment gives."""
keys = answers(c)
return [f for d in days(c["date"], shift) for f in by_day.get(d, []) if all(f.get(k) == c[k] for k in keys)]
def measure(runs):
by_day = form_index(runs)
comments = [r for r in runs if r["source"] == "reddit comment"]
comp = [c for c in comments if comparable(c)]
found = {c["run_id"]: [f["run_id"] for f in matches(c, by_day)] for c in comp}
matched = sum(1 for v in found.values() if v)
# chance: each comment's match rate on shifted dates, over the shifts whose window has form rows at all
expected = 0.0
for c in comp:
valid = [s for s in SHIFTS if any(by_day.get(d) for d in days(c["date"], s))]
if valid:
expected += sum(1 for s in valid if matches(c, by_day, s)) / len(valid)
return {
"schema": 1,
"rule": {"min_answers": MIN_ANSWERS, "window_days": WINDOW, "baseline_shifts_days": list(SHIFTS)},
"comment_runs": len(comments),
"comparable": len(comp),
"matched": matched,
"expected_by_chance": round(expected, 1),
"likely_double": round(max(0.0, matched - expected), 1),
"matches": [{"comment": k, "form": v} for k, v in sorted(found.items()) if v],
}
def main(argv=None):
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--check", action="store_true", help="fail if data/public/overlap.json is out of date")
a = ap.parse_args(argv)
text = json.dumps(measure(runs_io.read(drop=())), indent=1, ensure_ascii=False) + "\n"
if a.check:
if not OUT.exists() or OUT.read_text(encoding="utf-8") != text:
print(f"out of date (run `python {Path(__file__).relative_to(ROOT)}`): {OUT.relative_to(ROOT)}")
return 1
return 0
OUT.write_text(text, encoding="utf-8")
m = json.loads(text)
print(f"{OUT.relative_to(ROOT)}: {m['matched']} of {m['comparable']} comparable Reddit runs match a form row "
f"(~{m['expected_by_chance']} by chance; ~{m['likely_double']} likely reported twice)")
return 0
if __name__ == "__main__":
sys.exit(main())
+17 -19
View File
@@ -4,36 +4,34 @@ Written by `analysis/black/evidence.py` from `data/public/runs_clean.csv`. Count
## 1. The shadow by attempt number ## 1. The shadow by attempt number
| Attempt | Form submissions | Bulk logs | Bot | Reddit comments | | Attempt | Form submissions | Bulk logs | Bot |
|---|---|---|---|---| |---|---|---|---|
| 1 | 97 / 960 (10.1%) | 0 / 29 (0.0%) | 0 / 0 | 1 / 1 (100.0%) | | 1 | 97 / 960 (10.1%) | 0 / 29 (0.0%) | 0 / 0 |
| 2 | 0 / 299 (0.0%) | 0 / 21 (0.0%) | 0 / 4 (0.0%) | 0 / 0 | | 2 | 0 / 296 (0.0%) | 0 / 21 (0.0%) | 0 / 4 (0.0%) |
| 3 | 0 / 196 (0.0%) | 0 / 14 (0.0%) | 0 / 5 (0.0%) | 0 / 0 | | 3 | 0 / 193 (0.0%) | 0 / 14 (0.0%) | 0 / 5 (0.0%) |
| 4-10 | 0 / 555 (0.0%) | 0 / 102 (0.0%) | 0 / 36 (0.0%) | 0 / 0 | | 4-10 | 0 / 538 (0.0%) | 0 / 102 (0.0%) | 0 / 36 (0.0%) |
| 11-30 | 0 / 657 (0.0%) | 0 / 57 (0.0%) | 0 / 137 (0.0%) | 0 / 0 | | 11-30 | 0 / 627 (0.0%) | 0 / 57 (0.0%) | 0 / 137 (0.0%) |
| 31 or more | 0 / 715 (0.0%) | 0 / 0 | 0 / 333 (0.0%) | 0 / 0 | | 31 or more | 0 / 694 (0.0%) | 0 / 0 | 0 / 333 (0.0%) |
| not given | 0 / 1582 (0.0%) | 0 / 149 (0.0%) | 0 / 0 | 2 / 3 (66.7%) | | not given | 0 / 1581 (0.0%) | 0 / 149 (0.0%) | 0 / 0 |
Complete logs (bot and bulk) have 29 first attempts at the tree and 709 later ones, with 0 shadows. Zero in 709 later attempts rules out a rate above 0.4% for them; zero in 29 first attempts only rules out more than 10%. Complete logs (bot and bulk) have 29 first attempts at the tree and 709 later ones, with 0 shadows. Zero in 709 later attempts rules out a rate above 0.4% for them; zero in 29 first attempts only rules out more than 10%.
Reddit comments describe 17 shadows in all, but a comment rarely says how the run began: only 3 say the rider helped their squadmate and climbed the tree (the table above), and 3 say it was a first attempt. Like form submissions, they are posted by choice, so they say what shadow runs look like, not how often the shadow comes.
## 2. The same route on a first attempt and on a later one ## 2. The same route on a first attempt and on a later one
If the shadow depended only on the choices the form records (company, first direction, first move in the fight, the dagger, the bullies' fate, the fork), a route would do as well on a later attempt as on a first. It does not. If the shadow depended only on the choices the form records (company, first direction, first move in the fight, the dagger, the bullies' fate, the fork), a route would do as well on a later attempt as on a first. It does not.
| Route | First attempt | Later attempts | | Route | First attempt | Later attempts |
|---|---|---| |---|---|---|
| Alone / West / Assess the situation / Engage the smaller cadet / Squadmate's revenge / West | 23 / 114 (20.2%) | 0 / 106 (0.0%) | | Alone / West / Assess the situation / Engage the smaller cadet / Squadmate's revenge / West | 23 / 114 (20.2%) | 0 / 94 (0.0%) |
| Alone / West / Assess the situation / Engage the smaller cadet / Squadmate's revenge / Forest | 5 / 29 (17.2%) | 0 / 96 (0.0%) | | Alone / West / Assess the situation / Engage the smaller cadet / Squadmate's revenge / Forest | 5 / 29 (17.2%) | 0 / 95 (0.0%) |
| Alone / Center / Assess the situation / Engage the smaller cadet / Squadmate's revenge / Forest | 4 / 29 (13.8%) | 0 / 78 (0.0%) | | Alone / Center / Assess the situation / Engage the smaller cadet / Squadmate's revenge / Forest | 4 / 29 (13.8%) | 0 / 78 (0.0%) |
| 1 Squadmate / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 2 / 32 (6.2%) | 0 / 73 (0.0%) | | 1 Squadmate / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 2 / 32 (6.2%) | 0 / 67 (0.0%) |
| 2 Squadmates / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 2 / 45 (4.4%) | 0 / 50 (0.0%) |
| Alone / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 1 / 34 (2.9%) | 0 / 60 (0.0%) | | Alone / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 1 / 34 (2.9%) | 0 / 60 (0.0%) |
| 2 Squadmates / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 2 / 45 (4.4%) | 0 / 48 (0.0%) |
| Alone / Center / Assess the situation / Daggers or not (protect squadmate) / Left bullies to the dragons / Forest | 1 / 28 (3.6%) | 0 / 64 (0.0%) | | Alone / Center / Assess the situation / Daggers or not (protect squadmate) / Left bullies to the dragons / Forest | 1 / 28 (3.6%) | 0 / 64 (0.0%) |
| Alone / Center / Assess the situation / Engage the smaller cadet / Squadmate's revenge / West | 2 / 9 (22.2%) | 0 / 81 (0.0%) | | Alone / Center / Assess the situation / Engage the smaller cadet / Squadmate's revenge / West | 2 / 9 (22.2%) | 0 / 81 (0.0%) |
Across all 326 recorded routes, comparing first and later attempts on the same route: 93 first-attempt shadows where 38.8 would be expected if the attempt did not matter (odds ratio unbounded: no later-attempt shadow at all, z = 12.5). First and later attempts choose almost the same routes, so the difference is not in the recorded choices: it is something about the account, or a choice the form does not record. Across all 325 recorded routes, comparing first and later attempts on the same route: 93 first-attempt shadows where 39.9 would be expected if the attempt did not matter (odds ratio inf, z = 12.3). First and later attempts choose almost the same routes, so the difference is not in the recorded choices: it is something about the account, or a choice the form does not record.
## 3. On one route, is the shadow decided by the cadet's wing, section and squad? ## 3. On one route, is the shadow decided by the cadet's wing, section and squad?
@@ -58,14 +56,14 @@ The 97 form runs with a shadow (all attempts) took 47 different recorded routes:
- **The bullies' fate:** Squadmate's revenge 61, Left bullies to the dragons 25, Killed the bullies yourself 9, Unknown 2 - **The bullies' fate:** Squadmate's revenge 61, Left bullies to the dragons 25, Killed the bullies yourself 9, Unknown 2
- **The fork:** West 46, Forest 36, East 14, Unknown 1 - **The fork:** West 46, Forest 36, East 14, Unknown 1
Shadows reported with an answer that contradicts a gate: 3 (likely mis-entered or misread). Another 14 do not say whether they passed both gates. Shadows reported without both gates: 3 (likely mis-entered).
## 5. After the shadow: the Blue, then the Black ## 5. After the shadow: the Blue, then the Black
The riders' notes describe one sequence: follow the shadow, a Blue lands and burns another cadet, the Blue leaves, then the Black appears. The Blue is a trial on the way, not an alternative to the Black. The riders' notes describe one sequence: follow the shadow, a Blue lands and burns another cadet, the Blue leaves, then the Black appears. The Blue is a trial on the way, not an alternative to the Black.
- Runs that reached the Black: 89, bonded 65. - Runs that reached the Black: 79, bonded 57.
- Runs that died at the Blue: 19. What their notes say they did: approached the Blue 11, warned the other cadet / intervened 4. - Runs that died at the Blue: 16. What their notes say they did: approached the Blue 11, warned the other cadet / intervened 4.
- The answer given to the Black, where the note says (bonded / runs): held its gaze 29/41; lowered eyes 0/7; ignored the sound 0/1. - The answer given to the Black, where the note says (bonded / runs): held its gaze 29/41; lowered eyes 0/7; ignored the sound 0/1.
Holding its gaze is the only answer recorded with a bond, and it still fails about a quarter of the time. The developer says a rider who knows the system bonds with certainty, so those failures are not explained yet: the notes of the riders who died are too short to show what else they did differently. Holding its gaze is the only answer recorded with a bond, and it still fails about a quarter of the time. The developer says a rider who knows the system bonds with certainty, so those failures are not explained yet: the notes of the riders who died are too short to show what else they did differently.
+13 -17
View File
@@ -6,12 +6,10 @@
# (not blank), {any: [condition, ...]} (at least one). Several fields in one condition must all hold. # (not blank), {any: [condition, ...]} (at least one). Several fields in one condition must all hold.
version: 1 version: 1
# Which runs of data/public/runs_clean.csv the statistics use (its `source` column): every source that records the # Which runs of data/public/runs_clean.csv the statistics use (its `source` column). Runs from the other sources
# route (the community form, "Report a run", the Reddit megathread comments, the DragonKind bot). The Reddit result # (reported, bot, Reddit result pages) are in the published file but not in these statistics yet: they are coded
# pages and the register record only the end, so they stay out. The bot plays to a strategy and burns on purpose at # from different questions, and the bot follows a strategy, so pooling them needs its own review.
# encounters it is not chasing: like every rider's deliberate death (`_deliberate`, the route model's rule), those sources: [reddit spreadsheet]
# burns are left out of the bond rates, never counted as failed bonds.
sources: [reddit spreadsheet, reported, reddit comment, bot]
colours: [Red, Green, Orange, Brown, Blue, Black] colours: [Red, Green, Orange, Brown, Blue, Black]
@@ -27,7 +25,7 @@ outcomes:
event: { saw_shadow: true } event: { saw_shadow: true }
bond_blue_meadow: bond_blue_meadow:
label: Bond, given you approached the meadow Blue label: Bond, given you approached the meadow Blue
denom: { branch: "Passed the Red: meadow", enc_Blue: { in: ["Bonded!", "Incinerated"] }, _deliberate: { not: true } } denom: { branch: "Passed the Red: meadow", enc_Blue: { in: ["Bonded!", "Incinerated"] } }
event: { enc_Blue: "Bonded!" } event: { enc_Blue: "Bonded!" }
reach_hour: reach_hour:
label: Survive to the hour (tree/valley choice) label: Survive to the hour (tree/valley choice)
@@ -36,7 +34,7 @@ outcomes:
# one more outcome per colour: "Run ends bonded to <colour>", among runs that reached the hour # one more outcome per colour: "Run ends bonded to <colour>", among runs that reached the hour
bonded_outcome: bonded_outcome:
label: Run ends bonded to {colour} label: Run ends bonded to {colour}
denom: { hour: { in: [Tree, Valley] }, _deliberate: { not: true } } denom: { hour: { in: [Tree, Valley] } }
event: { outcome: Bonded, outcome_color: "{colour}" } event: { outcome: Bonded, outcome_color: "{colour}" }
# Factors compared in the factor tables (each answer against the other answers to the same question) # Factors compared in the factor tables (each answer against the other answers to the same question)
@@ -45,15 +43,15 @@ factors: [company, direction, first_sighting, scream, resolution, combat_first,
# Route targets: the outcome (event) and which runs could have reached it at all (pool) # Route targets: the outcome (event) and which runs could have reached it at all (pool)
targets: targets:
bond_Blue: { label: Bond Blue, colour: Blue, event: { outcome: Bonded, outcome_color: Blue }, pool: { hour: Valley, _deliberate: { not: true } } } 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, _deliberate: { not: true } } } 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_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 } } } 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] }, _deliberate: { not: 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, _deliberate: { not: true } } } 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] }, _deliberate: { not: true } } } 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] }, _deliberate: { not: true } } } 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] }, _deliberate: { not: true } } } 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) # Bonding encounters: which recorded attempt (column) belongs to which in-game encounter (where)
encounters: encounters:
@@ -82,8 +80,6 @@ presets:
all: { label: All runs, filters: { source: all, goal: all, excludeFlagged: false } } all: { label: All runs, filters: { source: all, goal: all, excludeFlagged: false } }
form: { label: Form submissions only, filters: { source: form, 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 } } bulk: { label: Bulk logs only (imports), filters: { source: bulk, goal: all, excludeFlagged: false } }
reddit: { label: Reddit comments only, filters: { source: reddit, goal: all, excludeFlagged: false } }
bot: { label: DragonKind bot only, filters: { source: bot, goal: all, excludeFlagged: false } }
not_chasing: { label: Not chasing Blue/Black, filters: { source: all, goal: exclude_rare, 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 } } 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 } } unflagged: { label: Rows without data-quality flags, filters: { source: all, goal: all, excludeFlagged: true } }
+10 -36
View File
@@ -95,18 +95,7 @@ def is_rare(goal):
return goal in M["rare_goals"] return goal in M["rare_goals"]
# sources other than the community spreadsheet: their own group wherever runs are split by where they came from
SOURCE_LABEL = {"reddit comment": "Reddit comments", "bot": "DragonKind bot", "reported": "Reported on the Atlas"}
def entry_group(r):
"""Where a run came from: the spreadsheet's entry type (Form, Data Import, ...) or the source's own label."""
return SOURCE_LABEL.get(r["source"]) or r["entry"]
def stratum(r): def stratum(r):
if r["source"] in SOURCE_LABEL:
return SOURCE_LABEL[r["source"]]
if r["entry"] != "Form": if r["entry"] != "Form":
return "Bulk logs (imports)" return "Bulk logs (imports)"
g = r["goal"] g = r["goal"]
@@ -119,14 +108,9 @@ def goal2(r):
def apply_filters(runs, f): def apply_filters(runs, f):
def ok(r): def ok(r):
sheet = r["source"] == "reddit spreadsheet" if f.get("source") == "form" and r["entry"] != "Form":
if f.get("source") == "form" and not (sheet and r["entry"] == "Form"):
return False return False
if f.get("source") == "bulk" and not (sheet and r["entry"] != "Form"): if f.get("source") == "bulk" and r["entry"] == "Form":
return False
if f.get("source") == "reddit" and r["source"] != "reddit comment":
return False
if f.get("source") == "bot" and r["source"] != "bot":
return False return False
if f.get("goal") == "exclude_rare" and is_rare(r["goal"]): if f.get("goal") == "exclude_rare" and is_rare(r["goal"]):
return False return False
@@ -213,7 +197,7 @@ def analyse(all_runs, filters):
dates = sorted(r["date"] for r in runs if r.get("date")) 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 "")) outs = group_by(runs, lambda r: r["outcome"] + (" " + r["outcome_color"] if r.get("outcome_color") else ""))
res["meta"] = { res["meta"] = {
"sources": {k: len(v) for k, v in group_by(runs, entry_group).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, "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, "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()}, "outcomes": {k: len(v) for k, v in outs.items()},
@@ -236,14 +220,13 @@ def analyse(all_runs, filters):
res["encounters"] = [] res["encounters"] = []
for e in M["encounters"]: for e in M["encounters"]:
col, colour = e["column"], e["colour"] col, colour = e["column"], e["colour"]
# a rider who chose to burn here (chasing another colour) did not fail this encounter A = [r for r in runs if match(r, e["where"]) and r.get(col) in ("Bonded!", "Incinerated")]
A = [r for r in runs if match(r, e["where"]) and r.get(col) in ("Bonded!", "Incinerated") and not r.get("_deliberate")]
win = lambda r, col=col: r.get(col) == "Bonded!" # noqa: E731 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"))] 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), 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())}}) "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_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") and not r.get("_deliberate")] greens = [r for r in runs if match(r, greens_where) and r.get("enc_Green")]
g = {"green_encounters": len(greens), g = {"green_encounters": len(greens),
"bonded_green": sum(1 for r in greens if r["enc_Green"] == "Bonded!"), "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_orange": sum(1 for r in greens if r["rescued"] and r.get("outcome_color") == "Orange"),
@@ -257,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 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 known = lambda f: (lambda r: None if is_missing(r.get(f)) else r[f]) # noqa: E731
src2 = lambda r: SOURCE_LABEL.get(r["source"]) or ("Form submission" if r["entry"] == "Form" else "Bulk log (import)") # noqa: E731 src2 = lambda r: "Form submission" if r["entry"] == "Form" else "Bulk log (import)" # noqa: E731
res["models"] = { res["models"] = {
"blue_meadow": fit_model(runs, "blue_meadow", {"source": src2, "goal": goal2, "direction": known("direction"), "blue_meadow": fit_model(runs, "blue_meadow", {"source": src2, "goal": goal2, "direction": known("direction"),
"first_sighting": first2, "resolution": known("resolution"), "company": known("company")}), "first_sighting": first2, "resolution": known("resolution"), "company": known("company")}),
@@ -274,7 +257,7 @@ def analyse(all_runs, filters):
"blue": W(bk, len(m)), "shadow": W(sk, len(t))}) "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"])) 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, entry_group).items()} for key in ("blue_meadow", "shadow")} for s, g in group_by(runs, "entry").items()} for key in ("blue_meadow", "shadow")}
return res return res
@@ -319,11 +302,9 @@ def route_map(runs):
"""The route map: nodes and links with run counts, and for every target the hits and their Wilson interval.""" """The route map: nodes and links with run counts, and for every target the hits and their Wilson interval."""
nodes, links = {}, {} nodes, links = {}, {}
hits = {t: {} for t in TARGETS} hits = {t: {} for t in TARGETS}
tries = {t: {} for t in TARGETS} # runs that count for the target (no deliberate deaths for a bond)
for r in runs: for r in runs:
prev = None prev = None
hit = {t: match(r, T["event"]) for t, T in TARGETS.items()} hit = {t: match(r, T["event"]) for t, T in TARGETS.items()}
counts = {t: not (r.get("_deliberate") and t.startswith("bond_")) for t in TARGETS}
for si, s in enumerate(STAGES): for si, s in enumerate(STAGES):
v = stage_value(r, s["key"]) v = stage_value(r, s["key"])
if v is None: if v is None:
@@ -333,18 +314,15 @@ def route_map(runs):
nd["n"] += 1 nd["n"] += 1
for t in TARGETS: for t in TARGETS:
hits[t][nid] = hits[t].get(nid, 0) + hit[t] hits[t][nid] = hits[t].get(nid, 0) + hit[t]
tries[t][nid] = tries[t].get(nid, 0) + counts[t]
if prev: if prev:
lid = prev + "→" + nid lid = prev + "→" + nid
ln = links.setdefault(lid, {"id": lid, "source": prev, "target": nid, "n": 0, "chance": bool(s.get("chance"))}) ln = links.setdefault(lid, {"id": lid, "source": prev, "target": nid, "n": 0, "chance": bool(s.get("chance"))})
ln["n"] += 1 ln["n"] += 1
for t in TARGETS: for t in TARGETS:
hits[t][lid] = hits[t].get(lid, 0) + hit[t] hits[t][lid] = hits[t].get(lid, 0) + hit[t]
tries[t][lid] = tries[t].get(lid, 0) + counts[t]
prev = nid prev = nid
nl, ll = list(nodes.values()), list(links.values()) nl, ll = list(nodes.values()), list(links.values())
by_target = {t: {"nodes": [W(hits[t][n["id"]], tries[t][n["id"]]) for n in nl], 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}
"links": [W(hits[t][l["id"]], tries[t][l["id"]]) for l in ll]} for t in TARGETS}
return {"nodes": nl, "links": ll, "by_target": by_target} return {"nodes": nl, "links": ll, "by_target": by_target}
@@ -572,12 +550,8 @@ def main(argv=None):
ap.add_argument("--data", default=str(runs_io.PATH)) ap.add_argument("--data", default=str(runs_io.PATH))
ap.add_argument("--out", default=str(ROOT / "data/public/stats.json")) ap.add_argument("--out", default=str(ROOT / "data/public/stats.json"))
a = ap.parse_args(argv) a = ap.parse_args(argv)
# a run that cannot have happened as recorded (core/spec/form.yaml impossible_flags) is left out, as in the model runs = runs_io.read(a.data, sources=M["sources"])
runs = [r for r in runs_io.read(a.data, sources=M["sources"]) if not runs_io.impossible(r)] out = build(runs, len(runs), exported(), every_run=runs_io.read(a.data))
for r in runs:
r["_deliberate"] = deliberate(r)
every = [r for r in runs_io.read(a.data) if not runs_io.impossible(r)]
out = build(runs, len(runs), exported(), every_run=every)
Path(a.out).write_text(json.dumps(out, separators=(",", ":"), ensure_ascii=False), encoding="utf-8") 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") print(f"{a.out}: {len(runs)} runs, {len(out['presets'])} presets, {Path(a.out).stat().st_size / 1e6:.1f} MB")
-19
View File
@@ -41,25 +41,6 @@ The route PDF is a flowchart of the choices, not a log of runs, so it adds no ro
fingerprint tells us when the routes it documents change. The register lists bonded dragons without the route that fingerprint tells us when the routes it documents change. The register lists bonded dragons without the route that
led there, so it adds no rows either. led there, so it adds no rows either.
## Reviewing Reddit runs
Ken's scraper opens (or updates) a pull request from `data/reddit-comments` that changes
`data/public/reddit_comments.json`. The **Review Reddit runs** workflow (`.gitea/workflows/reddit-review.yml`) posts a
summary on it, refreshed on every push (`python -m collection review-reddit --base <main's file>` locally):
- runs added, changed and gone since main;
- **runs that break a game rule** (`core/spec/form.yaml` `impossible_flags`): left out of the route model and the
statistics until corrected. Open the comment and decide;
- other flags on the new runs (kept);
- runs that may also be in the community form: the same answers within a day, with how many chance alone gives
(`analysis/overlap/overlap.py`, `data/public/overlap.json`). Measured only, never removed;
- runs whose result page is already a `reddit thread` row (counted once automatically).
Corrections go in `manual/reddit_comments.yaml`, applied at build time, so they never wait for the threads:
`reject: [id]` (not a run), `fix: {id: {question: answer}}` (misread; `null` removes an answer) and
`add: [{id, thread, posted, answers}]` (missed). A corrected run loses the "not checked by hand" note. No usernames:
the comment id is enough to find the comment again. Then merge, once CI passes.
## Raw files and privacy ## Raw files and privacy
`data/raw/` is git-ignored and never published. It holds the current raw file of each source and the one before `data/raw/` is git-ignored and never published. It holds the current raw file of each source and the one before
-12
View File
@@ -131,18 +131,6 @@ def open_issue(title, body, env=None, f=None):
return _call("POST", f"{api_base(f)}/issues", {"title": title, "body": body}, tok, f)["number"] return _call("POST", f"{api_base(f)}/issues", {"title": title, "body": body}, tok, f)["number"]
def upsert_comment(number, marker, body, env=None, f=None):
"""Post `body` on issue or pull request `number`, replacing an earlier comment that starts with `marker`
(so a summary refreshed on every push stays one comment)."""
f = f or config()
tok = token(env)
comments = _call("GET", f"{api_base(f)}/issues/{number}/comments?limit=50&per_page=100", tok=tok, f=f) or []
mine = [c for c in comments if (c.get("body") or "").startswith(marker)]
if mine:
return _call("PATCH", f"{api_base(f)}/issues/comments/{mine[-1]['id']}", {"body": body}, tok, f)["id"]
return _call("POST", f"{api_base(f)}/issues/{number}/comments", {"body": body}, tok, f)["id"]
def ensure_label(name, color, env=None, f=None): def ensure_label(name, color, env=None, f=None):
f = f or config() f = f or config()
tok = token(env) tok = token(env)
-2
View File
@@ -87,8 +87,6 @@ def rebuild():
_step("experiment plan", [py, "planner/build_experiments.py"]) _step("experiment plan", [py, "planner/build_experiments.py"])
_step("what the runs show about the Black", [py, "analysis/black/evidence.py"]) _step("what the runs show about the Black", [py, "analysis/black/evidence.py"])
_step("screen tree", [py, "analysis/tree/build_tree.py"]) _step("screen tree", [py, "analysis/tree/build_tree.py"])
_step("known answers for the bot (guide + screen tree)", [py, "analysis/known/build_known.py"])
_step("runs reported twice (form + Reddit)", [py, "analysis/overlap/overlap.py"])
try: try:
import scipy # noqa: F401 import scipy # noqa: F401
_step("statistics", [py, "analysis/stats/site_stats.py"]) _step("statistics", [py, "analysis/stats/site_stats.py"])
+1 -4
View File
@@ -112,13 +112,10 @@ def build(dictionary=None):
"citeAs": ds["citation"].format(repository=forge.repo_url(fg)), "citeAs": ds["citation"].format(repository=forge.repo_url(fg)),
"isLiveDataset": True, "isLiveDataset": True,
"isBasedOn": [ "isBasedOn": [
{"@type": "sc:CreativeWork", "url": s["links"][k], {"@type": "sc:CreativeWork", "name": s["label"], "url": next(iter(s["links"].values()))}
"name": s["label"] + (f" ({k.replace('part', 'part ')})" if len(s.get("cite") or ()) > 1 else "")}
for s in sources.values() for s in sources.values()
# the route PDF is only fingerprinted, never redistributed; the bot's repo is private # the route PDF is only fingerprinted, never redistributed; the bot's repo is private
if (s.get("privacy") or {}).get("redistribute", True) and s.get("links") if (s.get("privacy") or {}).get("redistribute", True) and s.get("links")
# `cite` (collection/pipeline.yaml) names the links the source is based on; default: the first link
for k in (s.get("cite") or [next(iter(s["links"]))])
], ],
"distribution": distribution, "distribution": distribution,
"recordSet": [ "recordSet": [
-133
View File
@@ -1,133 +0,0 @@
"""A review summary for a Reddit scraper pull request (issue #23).
python -m collection review-reddit --base BASE.json [--out summary.md] [--pr N]
Compares the pull request's data/public/reddit_comments.json with `BASE.json` (the same file on main) and reads the
runs as built from it (data/public/runs_clean.csv, so run `python -m collection build` first). The summary lists
what a reviewer needs to decide on, before merging:
- runs added, changed (answers differ) and gone;
- runs that break a game rule: left out of the route model and the statistics until corrected;
- other flags on the new or changed runs (kept, for information);
- runs that may also be in the community form (analysis/overlap/overlap.py: same answers within a day);
- runs whose result page is already a "reddit thread" row (counted once, automatically).
Corrections go in collection/manual/reddit_comments.yaml (reject / fix / add; see collection/README.md). With
`--pr N` the summary is posted on the pull request, replacing the previous one.
"""
import importlib.util
import json
import sys
from .common import ROOT, path, pipeline, read_yaml
MARKER = "<!-- atlas:reddit-review -->"
PROVENANCE = "read from a Reddit comment"
def _overlap():
spec = importlib.util.spec_from_file_location("overlap", ROOT / "analysis/overlap/overlap.py")
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
def link(run_id, thread):
cid = str(run_id).split("-")[0]
return f"[{run_id}](https://www.reddit.com/r/fourthwing/comments/{thread}/_/{cid}/)"
def diff(base, head):
"""(added, changed, gone) comment-run ids between two reddit_comments.json documents."""
b = {str(r["id"]): r for r in base.get("runs", [])}
h = {str(r["id"]): r for r in head.get("runs", [])}
added = sorted(set(h) - set(b))
gone = sorted(set(b) - set(h))
changed = sorted(k for k in set(h) & set(b) if h[k].get("answers") != b[k].get("answers"))
return added, changed, gone
def summary(base, head, runs, known_results=(), overlap=None):
"""The Markdown summary. `runs`: typed records of runs_clean.csv (with run_id)."""
sys.path.insert(0, str(ROOT / "core"))
from atlas import runs as runs_io
added, changed, gone = diff(base, head)
focus = set(added) | set(changed)
thread = {str(r["id"]): r.get("thread") for r in head.get("runs", [])}
result = {str(r["id"]): r.get("result") for r in head.get("runs", [])}
rows = {r["run_id"][len("comment-"):]: r for r in runs if r["source"] == "reddit comment"}
flags = {k: [f for f in (r.get("data_flags") or "").split("; ") if f and not f.startswith(PROVENANCE)]
for k, r in rows.items()}
impossible = sorted(k for k in rows if runs_io.impossible(rows[k]))
L = [MARKER, "## Reddit comment runs: review summary", ""]
L.append(f"**{len(head.get('runs', []))} runs** in this file: **{len(added)} new**, {len(changed)} changed, "
f"{len(gone)} gone since main. {head.get('unread', 0)} comments mention a bond or a burn but could not "
"be read as a run.")
L.append("")
L += ["### Runs that break a game rule", "",
"Left out of the route model and the statistics until corrected. Check the comment: `fix` a misread "
"answer, or `reject` a run that is not one.", ""]
bad = [k for k in impossible if k in focus] + [k for k in impossible if k not in focus]
if bad:
L += ["| Run | New? | Rule |", "|---|---|---|"]
L += [f"| {link(k, thread.get(k) or '')} | {'yes' if k in focus else ''} | "
f"{'; '.join(f for f in flags[k] if runs_io.impossible({'data_flags': f}))} |" for k in bad]
else:
L.append("None.")
L.append("")
other = [k for k in sorted(focus) if k in flags and flags[k] and k not in impossible]
L += ["### Other flags on new or changed runs (kept)", ""]
L += [f"- {link(k, thread.get(k) or '')}: {'; '.join(flags[k])}" for k in other] or ["None."]
L.append("")
if overlap is not None:
twice = {m["comment"][len("comment-"):]: m["form"] for m in overlap.get("matches", [])}
hits = [k for k in sorted(focus) if k in twice]
L += ["### May also be in the community form", "",
f"Same answers as a form row submitted within {overlap['rule']['window_days']} day(s). Over all Reddit "
f"runs: {overlap['matched']} of {overlap['comparable']} comparable runs match, about "
f"{overlap['expected_by_chance']} by chance, so about {overlap['likely_double']} look reported twice. "
"Nothing is removed: identical routes are expected.", ""]
L += [f"- {link(k, thread.get(k) or '')}: {', '.join(twice[k][:5])}" for k in hits] or ["None among the new runs."]
L.append("")
counted = [k for k in sorted(focus) if result.get(k) and str(result[k]).upper() in known_results]
L += ["### Result pages already counted", "",
"Their result page is also a \"reddit thread\" row; the run is counted once, with its route.", ""]
L += [f"- {link(k, thread.get(k) or '')}: {result[k]}" for k in counted] or ["None."]
L.append("")
L += ["### How to correct", "",
"In `collection/manual/reddit_comments.yaml` (applied at build time, on this branch or later):",
"- `reject: [comment id]`: not a run (a joke, a friend's run, two runs told as one);",
"- `fix: {comment id: {question: answer}}`: answers read wrong (`null` removes one);",
"- `add: [{id, thread, posted, answers}]`: a run the reader missed.",
"", "A corrected run loses the \"not checked by hand\" note. Then merge."]
return "\n".join(L) + "\n"
def main(base_file, out=None, pr=None):
sys.path.insert(0, str(ROOT / "core"))
from atlas import runs as runs_io
spec = pipeline()["sources"]["reddit_comments"]
base = json.loads(open(base_file, encoding="utf-8").read()) if base_file else {"runs": []}
head = json.loads(path(spec["load"]).read_text(encoding="utf-8"))
runs = runs_io.read(drop=())
thread_spec = pipeline()["sources"].get("reddit_thread") or {}
manual = (thread_spec.get("transform") or {}).get("manual")
known = {str(r["id"]).upper() for r in (read_yaml(manual)["results"] if manual else [])}
text = summary(base, head, runs, known, _overlap().measure(runs))
if out:
open(out, "w", encoding="utf-8").write(text)
else:
print(text)
if pr:
from . import forge
forge.upsert_comment(int(pr), MARKER, text)
print(f"summary posted on #{pr}")
return 0
+6 -85
View File
@@ -4,9 +4,7 @@ One coder per source (pipeline.yaml `runs:`). Every coder returns rows keyed by
missing answers get the same "not known" values the community form's coding uses, so every source can be filtered missing answers get the same "not known" values the community form's coding uses, so every source can be filtered
the same way. The `source` column says where a run came from; `entry` keeps the spreadsheet's own row label. the same way. The `source` column says where a run came from; `entry` keeps the spreadsheet's own row label.
""" """
import collections
import functools import functools
import hashlib
import json import json
import re import re
from pathlib import Path from pathlib import Path
@@ -53,40 +51,18 @@ def encounter_columns(row, intentional=False):
# ---------------------------------------------------------------- coders, by pipeline.yaml `runs:` # ---------------------------------------------------------------- coders, by pipeline.yaml `runs:`
def fingerprints(records, prefix):
"""Stable ids for rows that have no id of their own (the form, the register): `<prefix>-<hash of the row's
non-empty answers, timestamp included>`, so deleting or re-sorting rows in the sheet changes no other row's id,
and a column added later (empty in old rows) changes none. Rows that are exact copies of each other get -2, -3...
in the order they come; they are identical, so which copy is which does not matter. A row edited in the sheet
gets a new id: it is a different record."""
seen = collections.Counter()
out = []
for rec in records:
answers = {str(k): v for k, v in rec.items() if v is not None and v != "" and v == v} # v == v: not NaN
h = hashlib.sha1(json.dumps(answers, sort_keys=True, ensure_ascii=False, default=str).encode("utf-8")).hexdigest()[:12]
seen[h] += 1
out.append(f"{prefix}-{h}" + (f"-{seen[h]}" if seen[h] > 1 else ""))
return out
def spreadsheet(name, spec): def spreadsheet(name, spec):
"""The community form: core/spec/form.yaml + core/atlas/coding.py, plus the game-rule checks every source that """The community form: core/spec/form.yaml + core/atlas/coding.py, unchanged."""
answers the form's questions gets (rule_flags; a flag the coder already set is not repeated)."""
from atlas import coding from atlas import coding
raw = coding.read_export(path(spec["load"])) df, missing = coding.code_frame(coding.read_export(path(spec["load"])))
df, missing = coding.code_frame(raw)
if missing: if missing:
print(f"WARNING: {name}: questions not found in the sheet: {missing}") print(f"WARNING: {name}: questions not found in the sheet: {missing}")
ids = fingerprints(raw.astype(object).where(raw.notna(), None).to_dict("records"), "sheet")
df["attempt"] = df["attempt"].astype("Int64") df["attempt"] = df["attempt"].astype("Int64")
rows = [] rows = []
for i, rec in enumerate(df.astype(object).where(df.notna(), None).to_dict("records")): for rec in df.astype(object).where(df.notna(), None).to_dict("records"):
rec.pop("run_id") # the coder's row number: shifts when rows are deleted or re-sorted n = rec.pop("run_id")
entry = rec.pop("source") entry = rec.pop("source")
row = {**{c: None for c in COLUMNS}, **rec, "run_id": ids[i], "source": spec["run_source"], "entry": entry} rows.append({**{c: None for c in COLUMNS}, **rec, "run_id": f"sheet-{n}", "source": spec["run_source"], "entry": entry})
have = [f for f in (row["data_flags"] or "").split("; ") if f]
row["data_flags"] = "; ".join(have + [f for f in rule_flags(row) if f not in have])
rows.append(row)
return rows return rows
@@ -119,7 +95,6 @@ def register(name, spec):
"colour": ("colour",), "tail": ("tail",)}.items()} "colour": ("colour",), "tail": ("tail",)}.items()}
values = {c: DICT["columns"][c].get("values") or [] for c in ("wing", "section", "squad", "outcome_color", "tail")} values = {c: DICT["columns"][c].get("values") or [] for c in ("wing", "section", "squad", "outcome_color", "tail")}
rows = [] rows = []
ids = fingerprints(data["rows"], "register")
for n, r in enumerate(data["rows"], 1): for n, r in enumerate(data["rows"], 1):
get = lambda k: (str(r.get(h[k])).strip() if h[k] and r.get(h[k]) is not None else None) # noqa: E731 get = lambda k: (str(r.get(h[k])).strip() if h[k] and r.get(h[k]) is not None else None) # noqa: E731
flags = ["outcome only (register): the same run may also be in the spreadsheet"] flags = ["outcome only (register): the same run may also be in the spreadsheet"]
@@ -128,7 +103,7 @@ def register(name, spec):
flags.append("colour not recognised") flags.append("colour not recognised")
colour = None colour = None
tail = (get("tail") or "").replace(" ", "").capitalize() or None tail = (get("tail") or "").replace(" ", "").capitalize() or None
row = blank_row(run_id=ids[n - 1], source=spec["run_source"], date=(get("when") or "")[:10] or None, row = blank_row(run_id=f"register-{n}", source=spec["run_source"], date=(get("when") or "")[:10] or None,
outcome="Bonded", outcome_color=colour, tail=tail if tail in values["tail"] else None) outcome="Bonded", outcome_color=colour, tail=tail if tail in values["tail"] else None)
for c in ("wing", "section", "squad"): for c in ("wing", "section", "squad"):
if get(c) and (not values[c] or get(c) in values[c]): # section is free text in the dictionary if get(c) and (not values[c] or get(c) in values[c]): # section is free text in the dictionary
@@ -216,65 +191,11 @@ def answers_row(run_id, source, date, answers, flags=None):
row["saw_blue_meadow"] = True row["saw_blue_meadow"] = True
if row["outcome"] == "Bonded" and not row["outcome_color"]: if row["outcome"] == "Bonded" and not row["outcome_color"]:
flags.append("bonded, colour not given") flags.append("bonded, colour not given")
flags += rule_flags(row)
encounter_columns(row) encounter_columns(row)
row["data_flags"] = "; ".join(flags) row["data_flags"] = "; ".join(flags)
return row 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)")
if row["hour"] == "Valley" and colour == "Black":
flags.append("Black recorded on a Valley run (the Black is only reached from the tree)")
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): def _norm(text):
from .transform.bot import normalize from .transform.bot import normalize
return normalize(text) return normalize(text)
-2
View File
@@ -57,7 +57,6 @@ sources:
runs: null # a flowchart of the routes, not a log of runs (see collection/README.md) runs: null # a flowchart of the routes, not a log of runs (see collection/README.md)
reddit_thread: reddit_thread:
cite: [part3, part4] # both megathreads, in the dataset's isBasedOn
label: Runs posted in the r/fourthwing Dragonkind megathreads label: Runs posted in the r/fourthwing Dragonkind megathreads
run_source: reddit thread run_source: reddit thread
links: links:
@@ -71,7 +70,6 @@ sources:
runs: reddit_results runs: reddit_results
reddit_comments: reddit_comments:
cite: [part3, part4] # both megathreads, in the dataset's isBasedOn
label: Runs riders describe in the r/fourthwing Dragonkind megathread comments label: Runs riders describe in the r/fourthwing Dragonkind megathread comments
run_source: reddit comment run_source: reddit comment
links: links:
-7
View File
@@ -132,10 +132,6 @@ def main(argv=None):
k.add_argument("--out", default="exports") k.add_argument("--out", default="exports")
sub.add_parser("rebuild", help="rebuild everything made from the runs: graph, route model, plan, reports, statistics, build") sub.add_parser("rebuild", help="rebuild everything made from the runs: graph, route model, plan, reports, statistics, build")
sub.add_parser("send-pdf", help="open a pull request on the bot's repo when the route PDF changed (private copy only)") sub.add_parser("send-pdf", help="open a pull request on the bot's repo when the route PDF changed (private copy only)")
rv = sub.add_parser("review-reddit", help="a review summary for a Reddit scraper pull request (run `build` first)")
rv.add_argument("--base", help="data/public/reddit_comments.json as it is on main")
rv.add_argument("--out", help="write the summary here (default: print it)")
rv.add_argument("--pr", help="also post it on this pull request, replacing the previous summary")
r = sub.add_parser("refresh", help="update every source, then rebuild everything (the daily workflow, locally)") r = sub.add_parser("refresh", help="update every source, then rebuild everything (the daily workflow, locally)")
r.add_argument("--bot", action="append", default=[], help="a bot folder or a .zip of its data (repeatable)") r.add_argument("--bot", action="append", default=[], help="a bot folder or a .zip of its data (repeatable)")
c = sub.add_parser("cycle", help="the loop with the bot: import its runs, refit, re-plan, deliver (safe on a timer)") c = sub.add_parser("cycle", help="the loop with the bot: import its runs, refit, re-plan, deliver (safe on a timer)")
@@ -159,9 +155,6 @@ def main(argv=None):
if a.cmd == "rebuild": if a.cmd == "rebuild":
from .etl.handoff import rebuild from .etl.handoff import rebuild
return rebuild() return rebuild()
if a.cmd == "review-reddit":
from .etl.review_reddit import main as review
return review(a.base, a.out, a.pr)
if a.cmd == "send-pdf": if a.cmd == "send-pdf":
from .etl.send_pdf import send from .etl.send_pdf import send
return send() return send()
-7
View File
@@ -25,13 +25,6 @@ def _parse(col, v):
return v return v
def impossible(r):
"""A run that cannot have happened as recorded: one of its flags is in core/spec/form.yaml impossible_flags."""
from . import spec
rules = spec.form()["impossible_flags"]
return any(rule in f for f in (r.get("data_flags") or "").split("; ") for rule in rules)
def read(path=PATH, sources=None, drop=("run_id",)): def read(path=PATH, sources=None, drop=("run_id",)):
"""Typed records, optionally only from some sources (the `source` column).""" """Typed records, optionally only from some sources (the `source` column)."""
with open(path, encoding="utf-8", newline="") as f: with open(path, encoding="utf-8", newline="") as f:
+1 -64
View File
@@ -15,9 +15,6 @@
* shadow odds), `fix` (hold some decisions to given options: an experiment arm) and sampling "uniform" (mapping); * shadow odds), `fix` (hold some decisions to given options: an experiment arm) and sampling "uniform" (mapping);
* assign(plan, { accountSeq, attempt }) reads the experiment plan (experiments.json) and says what an attempt is for; * assign(plan, { accountSeq, attempt }) reads the experiment plan (experiments.json) and says what an attempt is for;
* screenPick(tree, sceneId, offered, { mode }) picks from the screen tree (tree.json): least-tried, or Thompson. * screenPick(tree, sceneId, offered, { mode }) picks from the screen tree (tree.json): least-tried, or Thompson.
* knownAnswer(known, offered, { target, sceneColour }) looks a screen's choices up in known_answers.json (the guide's
* encounter answers and the bot's own results) for screens nothing else covers: a pick when the evidence is clear,
* and the evidence for every choice either way, to hand to Clef (issue #35).
* UMD: window.ThreshSolver in the browser, module.exports in Node. No dependencies. * UMD: window.ThreshSolver in the browser, module.exports in Node. No dependencies.
*/ */
(function (root, factory) { (function (root, factory) {
@@ -449,68 +446,8 @@
reason: mode === "thompson" ? `survived ${pick.survived} of ${pick.n} so far` : `played ${pick.n} times, the fewest on this screen` }; reason: mode === "thompson" ? `survived ${pick.survived} of ${pick.n} so far` : `played ${pick.n} times, the fewest on this screen` };
} }
/* ---------- known answers (analysis/known/build_known.py -> data/public/known_answers.json) ---------- */
const STOP = new Set("a an the to and or of your you its it is for at in on with this that be".split(" "));
const words = (t) => norm(t).split(" ").filter((w) => w && !STOP.has(w));
/** The guide labels a game text carries: the guide paraphrases ("Touch its talon"), the game says it in full ("Reach a
* hand slowly to touch its talon"), so a label matches when every word of it that matters is in the text. Labels of
* fewer than two such words ("Is your dragon") only match a text that is exactly the label. */
function guideMatches(known, text) {
const n = norm(text), have = new Set(words(text)), out = [];
for (const [k, e] of Object.entries(known.answers || {})) {
if (!e.guide) continue;
const w = words(e.text);
const exact = k === n;
if (exact || (w.length >= 2 && w.every((x) => have.has(x)))) e.guide.forEach((g) => out.push({ ...g, label: e.text, exact }));
}
return out;
}
/**
* A screen nothing else covers: what the Atlas knows about each choice, and a pick when it is clear.
* known data/public/known_answers.json
* offered the choice texts on screen, in order
* target the colour the account is after ("Blue"); sceneColour: the colour of this scene's dragon, if the
* bot knows it (only the guide's answers for that dragon's encounters are used then)
* Returns { pick, confidence, reason, choices }: pick is the index to take (null if nothing is clear), confidence
* "strong" (exactly one choice is on the guide's recommended path toward the target, and the bot's own runs don't
* contradict it) or "weak" (several fit, or only the bot's own record speaks for it). choices[i].verdict is "good",
* "bad" (the guide ends it in incineration, or the bot died on it at least 3 times in 4) or "unknown", with the
* evidence behind it. Anything weak or unknown goes to Clef with this evidence; a pick never skips the bot's guard.
*/
function knownAnswer(known, offered, { target, sceneColour = null } = {}) {
const T = target ? target[0].toUpperCase() + target.slice(1).toLowerCase() : null;
const choices = offered.map((text, index) => {
const e = (known.answers || {})[norm(text)] || {};
const bot = e.bot || null;
const guide = guideMatches(known, text).filter((g) => !sceneColour || (g.colours || []).includes(sceneColour));
const onPath = guide.filter((g) => T && (g.on_path || []).includes(T));
const botBad = bot && bot.n >= 2 && bot.died / bot.n >= 0.75;
const botGood = bot && bot.n >= 3 && bot.died === 0;
const guideBad = guide.length > 0 && guide.every((g) => /^Incinerated/.test(g.end));
const verdict = onPath.length && !botBad ? "good" : guideBad || botBad ? "bad" : "unknown";
return { index, text, verdict, guide, bot, onPath: onPath.length > 0, botGood: !!botGood };
});
const good = choices.filter((c) => c.verdict === "good");
let pick = null, confidence = null, reason = "nothing the Atlas knows covers these choices";
if (good.length === 1) {
pick = good[0].index; confidence = "strong";
reason = `on the guide's recommended path to the ${T} ("${good[0].onPath && good[0].guide.find((g) => (g.on_path || []).includes(T)).label}")`;
} else if (good.length > 1) {
const best = good.find((c) => c.botGood) || good[0];
pick = best.index; confidence = "weak"; reason = `${good.length} choices are on the guide's paths; the bot's record favours none clearly`;
} else {
const safe = choices.filter((c) => c.botGood && c.verdict !== "bad");
if (safe.length) {
const b = safe.reduce((x, y) => (y.bot.n > x.bot.n ? y : x));
pick = b.index; confidence = "weak"; reason = `the bot got through it ${b.bot.n} of ${b.bot.n} times`;
}
}
return { pick, confidence, reason, choices };
}
return Object.assign(api, { return Object.assign(api, {
advisor, recommendOption, solverHistory, norm, assign, armFor, givenFor, screenPick, knownAnswer, advisor, recommendOption, solverHistory, norm, assign, armFor, givenFor, screenPick,
makeParams: (T, { alphas, game } = {}) => makeParams(T, { alphas, game: game || api.game }), makeParams: (T, { alphas, game } = {}) => makeParams(T, { alphas, game: game || api.game }),
/** remember the game of a policy sample (sets ENCOUNTERS) without solving anything */ /** remember the game of a policy sample (sets ENCOUNTERS) without solving anything */
useGame(sample) { api.game = sample.model.game; api.ENCOUNTERS = api.game.by_colour; return api.game; }, useGame(sample) { api.game = sample.model.game; api.ENCOUNTERS = api.game.by_colour; return api.game; },
-31
View File
@@ -153,37 +153,6 @@ sighting_pool:
1 Squadmate: { East: [Green, Orange, Red], West: [Red, Brown, Green], Center: [Red, Brown] } 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] } 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.
# Flags (data_flags, matched as text inside a flag) that mean a run cannot have happened as recorded: the game's own
# rules, from the form coder (core/atlas/coding.py) and the checks of collection/etl/runs.py rule_flags. A run with one
# is kept in runs_clean.csv, flagged, and left out of the route model and the site statistics (atlas.runs.impossible).
# Everything else, however partial, is used. Not here on purpose: a first sighting outside the documented pool (the
# pool is what riders have seen, not a rule), a missing direction, several wings, a missing Green before a rescue.
impossible_flags:
- "Green recorded on a Valley run"
- "Black recorded on a Valley run"
- "encounter, which has only"
- "more than one dragon marked Bonded"
- "more than one dragon marked Incinerated"
- "tree run with both the Red and the two Greens attempted"
- "died in combat on a path without combat"
- "rare-dragon answer does not match the path"
- "does not follow"
- "fight answers on a run that did not help"
- "a path after the fight on a run without a fight"
- "a second fight move without pausing to assess"
- "died before the hour, yet reached"
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 # 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. # original answer (data_flags), so nothing is lost.
first_sighting_alias: first_sighting_alias:
+21 -41
View File
@@ -66,33 +66,23 @@
"isBasedOn": [ "isBasedOn": [
{ {
"@type": "sc:CreativeWork", "@type": "sc:CreativeWork",
"url": "https://docs.google.com/spreadsheets/d/1gnw1AdRg1XT4JsOfRM6QTA0jSaS3n9ZF-rPWnYewzv0", "name": "Threshing Routes form and spreadsheet (u/ClumsyBadger, linked from the r/fourthwing megathreads)",
"name": "Threshing Routes form and spreadsheet (u/ClumsyBadger, linked from the r/fourthwing megathreads)" "url": "https://docs.google.com/spreadsheets/d/1gnw1AdRg1XT4JsOfRM6QTA0jSaS3n9ZF-rPWnYewzv0"
}, },
{ {
"@type": "sc:CreativeWork", "@type": "sc:CreativeWork",
"url": "https://docs.google.com/spreadsheets/d/1KMiE9sec0l597Pzue1OhGYf07NF4howtQ_lPeqx7jXQ", "name": "Unofficial Dragon Register (which dragon each rider bonded)",
"name": "Unofficial Dragon Register (which dragon each rider bonded)" "url": "https://docs.google.com/spreadsheets/d/1KMiE9sec0l597Pzue1OhGYf07NF4howtQ_lPeqx7jXQ"
}, },
{ {
"@type": "sc:CreativeWork", "@type": "sc:CreativeWork",
"url": "https://www.reddit.com/r/fourthwing/comments/1wvwfp9/", "name": "Runs posted in the r/fourthwing Dragonkind megathreads",
"name": "Runs posted in the r/fourthwing Dragonkind megathreads (part 3)" "url": "https://www.reddit.com/r/fourthwing/comments/1wvwfp9/"
}, },
{ {
"@type": "sc:CreativeWork", "@type": "sc:CreativeWork",
"url": "https://www.reddit.com/r/fourthwing/comments/1wz5cnj/", "name": "Runs riders describe in the r/fourthwing Dragonkind megathread comments",
"name": "Runs posted in the r/fourthwing Dragonkind megathreads (part 4)" "url": "https://www.reddit.com/r/fourthwing/comments/1wvwfp9/"
},
{
"@type": "sc:CreativeWork",
"url": "https://www.reddit.com/r/fourthwing/comments/1wvwfp9/",
"name": "Runs riders describe in the r/fourthwing Dragonkind megathread comments (part 3)"
},
{
"@type": "sc:CreativeWork",
"url": "https://www.reddit.com/r/fourthwing/comments/1wz5cnj/",
"name": "Runs riders describe in the r/fourthwing Dragonkind megathread comments (part 4)"
} }
], ],
"distribution": [ "distribution": [
@@ -103,8 +93,8 @@
"description": "Every run from every source, one per row, coded into the same columns (collection/etl/runs.py; the form's rules are core/spec/form.yaml). The `source` column says where each run came from.", "description": "Every run from every source, one per row, coded into the same columns (collection/etl/runs.py; the form's rules are core/spec/form.yaml). The `source` column says where each run came from.",
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/runs_clean.csv", "contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/runs_clean.csv",
"encodingFormat": "text/csv", "encodingFormat": "text/csv",
"sha256": "24321aa853d696b4a06226e28bac5e7843759dc3393721ef020d7f5c6beadf4e", "sha256": "ce944619f3a8ca03e67e05438a630d632d6dbe10c13e557e9fcc2fa897cdc932",
"contentSize": "3828261 B" "contentSize": "3685124 B"
}, },
{ {
"@type": "cr:FileObject", "@type": "cr:FileObject",
@@ -113,8 +103,8 @@
"description": "The community \"Threshing Routes\" form export as published (headers and rows), with email addresses in free-text answers redacted. The source of runs_clean.", "description": "The community \"Threshing Routes\" form export as published (headers and rows), with email addresses in free-text answers redacted. The source of runs_clean.",
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/form_responses.json", "contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/form_responses.json",
"encodingFormat": "application/json", "encodingFormat": "application/json",
"sha256": "8067ac944db2833e6a1203dc6464ed208d60dea4e617ee9b28fc56f285445d2e", "sha256": "3a3322da84274416880d87a400b06e44e0ed97feaf93df839b5269bdaa1badad",
"contentSize": "12786245 B" "contentSize": "12640700 B"
}, },
{ {
"@type": "cr:FileObject", "@type": "cr:FileObject",
@@ -123,18 +113,8 @@
"description": "Runs described in the r/fourthwing megathread comments, read into the \"Report a run\" answers: comment id, day and answers only, no usernames or comment text.", "description": "Runs described in the r/fourthwing megathread comments, read into the \"Report a run\" answers: comment id, day and answers only, no usernames or comment text.",
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/reddit_comments.json", "contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/reddit_comments.json",
"encodingFormat": "application/json", "encodingFormat": "application/json",
"sha256": "b169d157e731db23c99f2f8317a9718d31801b7d64336b3d414511ac13f32493", "sha256": "c180f8b82ed1119d4ff28697fcf45d0c7f22859597cd10f5e82a2e50ca1dc51a",
"contentSize": "23174 B" "contentSize": "105 B"
},
{
"@type": "cr:FileObject",
"@id": "overlap",
"name": "overlap",
"description": "How many Reddit comment runs may also be in the community form (the same answers within a day), against what chance alone gives (analysis/overlap/overlap.py). Measured only: no run is removed.",
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/overlap.json",
"encodingFormat": "application/json",
"sha256": "e7511cccf9e8379d8e892639cb38772269ac228756b984e9e0d4d8e9a583a9dd",
"contentSize": "2544 B"
}, },
{ {
"@type": "cr:FileObject", "@type": "cr:FileObject",
@@ -163,8 +143,8 @@
"description": "Every number the Atlas page shows, for six filter presets (analysis/stats/site_stats.py; what is measured is analysis/stats/measures.yaml).", "description": "Every number the Atlas page shows, for six filter presets (analysis/stats/site_stats.py; what is measured is analysis/stats/measures.yaml).",
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/stats.json", "contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/stats.json",
"encodingFormat": "application/json", "encodingFormat": "application/json",
"sha256": "7431173d9b667d4914d17bbc299d994d14c3104e3e89a1eb75d690c1b21ade6a", "sha256": "d2a551e785c8593b442d95338a99ea0710ed7df2cd6c6f3ef341bddff1f3689e",
"contentSize": "5110214 B" "contentSize": "5475502 B"
}, },
{ {
"@type": "cr:FileObject", "@type": "cr:FileObject",
@@ -173,8 +153,8 @@
"description": "The route model: the game (core/spec/game.yaml), the count tables behind every roll, and the best decision tree for every dragon colour under two goals, with posterior intervals (planner/build_policy.py).", "description": "The route model: the game (core/spec/game.yaml), the count tables behind every roll, and the best decision tree for every dragon colour under two goals, with posterior intervals (planner/build_policy.py).",
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/policy.json", "contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/policy.json",
"encodingFormat": "application/json", "encodingFormat": "application/json",
"sha256": "eec67140c63f028d31553be4f2310d92c9378293488aecd73a41ba1700b9e646", "sha256": "ef607b9a7fbc7f7d0e647f988fbac94a1685109a78218ce8c6f0ada3e62e2ee4",
"contentSize": "987412 B" "contentSize": "986552 B"
}, },
{ {
"@type": "cr:FileObject", "@type": "cr:FileObject",
@@ -183,8 +163,8 @@
"description": "The route graph over every run in runs_clean.csv, counted per source (analysis/network/build-graph.js).", "description": "The route graph over every run in runs_clean.csv, counted per source (analysis/network/build-graph.js).",
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/graph.json", "contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/graph.json",
"encodingFormat": "application/json", "encodingFormat": "application/json",
"sha256": "f9d1a86f84fcc10ef906af686ce624355ffd729440460288406ba97177ff05da", "sha256": "112895b711ade4e0aad8e4b7a61dea5db00f4734e484bc20198740e924c14974",
"contentSize": "84575 B" "contentSize": "75580 B"
} }
], ],
"recordSet": [ "recordSet": [
@@ -201,7 +181,7 @@
"@type": "cr:Field", "@type": "cr:Field",
"@id": "runs/run_id", "@id": "runs/run_id",
"name": "run_id", "name": "run_id",
"description": "Unique id of the run, stable when rows are deleted or re-sorted: sheet-<hash of the form row's answers and timestamp>, register-<hash of the register row>, thread-<result id>, comment-<Reddit comment id>, reported-<issue number> or bot-<hash>.", "description": "Unique id of the run: sheet-<row of the form export>, thread-<result id>, comment-<Reddit comment id>, reported-<issue number> or bot-<hash>.",
"dataType": "sc:Text", "dataType": "sc:Text",
"source": { "source": {
"fileObject": { "fileObject": {
+1 -7
View File
@@ -41,12 +41,6 @@ files:
description: >- description: >-
Runs described in the r/fourthwing megathread comments, read into the "Report a run" answers: comment id, day Runs described in the r/fourthwing megathread comments, read into the "Report a run" answers: comment id, day
and answers only, no usernames or comment text. and answers only, no usernames or comment text.
overlap:
path: data/public/overlap.json
format: application/json
description: >-
How many Reddit comment runs may also be in the community form (the same answers within a day), against what
chance alone gives (analysis/overlap/overlap.py). Measured only: no run is removed.
reports: reports:
path: data/public/reports.json path: data/public/reports.json
format: application/json format: application/json
@@ -75,7 +69,7 @@ files:
# The columns of runs_clean. type: text, integer, boolean or date. values: every value the column may take # The columns of runs_clean. type: text, integer, boolean or date. values: every value the column may take
# (empty cells are always allowed and mean "does not apply" or "not recorded"). # (empty cells are always allowed and mean "does not apply" or "not recorded").
columns: columns:
run_id: { type: text, required: true, description: "Unique id of the run, stable when rows are deleted or re-sorted: sheet-<hash of the form row's answers and timestamp>, register-<hash of the register row>, thread-<result id>, comment-<Reddit comment id>, reported-<issue number> or bot-<hash>." } run_id: { type: text, required: true, description: "Unique id of the run: sheet-<row of the form export>, thread-<result id>, comment-<Reddit comment id>, reported-<issue number> or bot-<hash>." }
source: source:
type: text type: text
required: true required: true
+5 -5
View File
@@ -10,18 +10,18 @@
"changed": "2026-11-16" "changed": "2026-11-16"
}, },
"reddit_spreadsheet": { "reddit_spreadsheet": {
"sha256": "44eeece5fd75fb27f0c7bdf2729d812ba710f4bfba30dfd5dbee51a7888b8270", "sha256": "ca06bbb6914483214801b54b58ed08039c21dc858c59347456ea473b1417fbb4",
"bytes": 5994979, "bytes": 5941127,
"changed": "2026-11-19" "changed": "2026-11-19"
}, },
"register": { "register": {
"sha256": "6efdf107fce4d7b5a48de3d683762b7236a6049c875145bf4aa1608c90f9ae8f", "sha256": "d6e5085f73adbf047163578c150dd034e2387fe37bd91030b36592df46147261",
"bytes": 51331, "bytes": 51331,
"changed": "2026-11-19" "changed": "2026-11-19"
}, },
"reported": { "reported": {
"sha256": "4c62d2e726e7c967d03a6c85d3bb3e09384656b7ffd9ea629d13400fdc37b211", "sha256": "8c8721b9c698e155c406da97fb69dda1729a9546290773dc0a044b1cd7eae628",
"bytes": 28296, "bytes": 27492,
"changed": "2026-11-19" "changed": "2026-11-19"
} }
} }
+15 -47
View File
@@ -8,23 +8,23 @@
], ],
"2": [ "2": [
0, 0,
299 296
], ],
"3": [ "3": [
0, 0,
196 193
], ],
"4-10": [ "4-10": [
0, 0,
555 538
], ],
"11-30": [ "11-30": [
0, 0,
657 627
], ],
"31 or more": [ "31 or more": [
0, 0,
715 694
] ]
}, },
"bulk logs": { "bulk logs": {
@@ -78,45 +78,14 @@
0, 0,
333 333
] ]
},
"Reddit comments": {
"1": [
1,
1
],
"2": [
0,
0
],
"3": [
0,
0
],
"4-10": [
0,
0
],
"11-30": [
0,
0
],
"31 or more": [
0,
0
]
} }
}, },
"reddit_shadows": {
"all": 17,
"gated": 3,
"first_attempt": 3
},
"same_route": { "same_route": {
"routes": 326, "routes": 325,
"first_shadows": 93, "first_shadows": 93,
"expected": 38.8, "expected": 39.9,
"odds_ratio": null, "odds_ratio": Infinity,
"z": 12.5 "z": 12.3
}, },
"form_first": [ "form_first": [
97, 97,
@@ -124,7 +93,7 @@
], ],
"form_later": [ "form_later": [
0, 0,
2422 2348
], ],
"best_route": { "best_route": {
"route": [ "route": [
@@ -141,19 +110,18 @@
], ],
"later": [ "later": [
0, 0,
106 94
] ]
}, },
"shadow_routes": { "shadow_routes": {
"runs": 97, "runs": 97,
"routes": 47, "routes": 47,
"off_gate": 3, "off_gate": 3
"gates_unstated": 14
}, },
"after_shadow": { "after_shadow": {
"reached_black": 89, "reached_black": 79,
"bonded_black": 65, "bonded_black": 57,
"died_at_blue": 19, "died_at_blue": 16,
"answers": { "answers": {
"held its gaze": [ "held its gaze": [
29, 29,
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
-134
View File
@@ -1,134 +0,0 @@
{
"schema": 1,
"rule": {
"min_answers": 4,
"window_days": 1,
"baseline_shifts_days": [
-28,
-21,
-14,
14,
21,
28
]
},
"comment_runs": 82,
"comparable": 36,
"matched": 9,
"expected_by_chance": 7.3,
"likely_double": 1.7,
"matches": [
{
"comment": "comment-pdjr7gm",
"form": [
"sheet-e42d078df15a",
"sheet-d930d7c3533d"
]
},
{
"comment": "comment-pdq6tsw",
"form": [
"sheet-e588ea82d6f9",
"sheet-410e2db3f2df",
"sheet-af47d3ca8ef8"
]
},
{
"comment": "comment-pe0kwol",
"form": [
"sheet-bea7c3c25e85"
]
},
{
"comment": "comment-pe2l6mz",
"form": [
"sheet-7a526f9f5956",
"sheet-8191a69798de",
"sheet-0d56c45763b7",
"sheet-c51873588c6d",
"sheet-b8d6d0a2ce4c",
"sheet-34e592789d1b",
"sheet-66e8fda4be49",
"sheet-1922bb0d7397",
"sheet-37f31b85732d"
]
},
{
"comment": "comment-pe2n3j1",
"form": [
"sheet-807397c3d7e2",
"sheet-ff44440c3570"
]
},
{
"comment": "comment-pev3uge",
"form": [
"sheet-9c848ba4c9a9",
"sheet-65c505bb553d",
"sheet-93077866d5b5",
"sheet-f4ba657cd34c",
"sheet-2fa18d22a1eb",
"sheet-4602a99ee254",
"sheet-5320d71ea890",
"sheet-55b901b0c666",
"sheet-94b17052d8c3",
"sheet-8924c5206376",
"sheet-81124318fbca",
"sheet-1346c5ddbeb6",
"sheet-c8670abfd8b3",
"sheet-913d430db3ed",
"sheet-2fa9c70f091d",
"sheet-19e5e9069e3b",
"sheet-19ecd172b18a",
"sheet-62484835c1c0",
"sheet-86e585f7994e",
"sheet-ad2265128708",
"sheet-f65261b3b1f7",
"sheet-cead6ddb0272",
"sheet-dd7216ed25e8",
"sheet-60a2410b997e",
"sheet-93303aaac8a1",
"sheet-aac64def431c",
"sheet-a62003707841",
"sheet-76d43e939528",
"sheet-ca945bc0e4f7",
"sheet-83270750d93e",
"sheet-7cb7c22a757e",
"sheet-1598950786a0",
"sheet-0d44ea821771",
"sheet-cc3275c111d3",
"sheet-899c141a899c"
]
},
{
"comment": "comment-pf22tpj",
"form": [
"sheet-3fdbb179c709",
"sheet-08a79a6ae907",
"sheet-73d9e41fee8d",
"sheet-172fec1dedc4",
"sheet-792cc1632e55",
"sheet-e97b3363e32f",
"sheet-d81d1b4b8c65",
"sheet-bcb8e109f973",
"sheet-8d6f20b09b5e",
"sheet-3848c3443c4e",
"sheet-ff87178ef296",
"sheet-5819e3882bec",
"sheet-aba89201ba1e"
]
},
{
"comment": "comment-pfhmw5d",
"form": [
"sheet-b03b79966bdb"
]
},
{
"comment": "comment-pgzz9hc",
"form": [
"sheet-344751923fc3"
]
}
]
}
-737
View File
@@ -1,737 +0,0 @@
{
"_about": "The answers inside each bonding encounter, transcribed by hand from the community route PDF (see source). Data, not the flowchart: each option's answer (say), the guide's printed rate (pct), whether it is on the guide's recommended dark-tile path (best), whether the guide marks it untested or unconfirmed (unconfirmed), and what follows (then) or how it ends (end); roll marks a step the guide calls an unknown chance or decision. route_encounters: which encounters each bonding encounter of the route model shows. Edit this file when the PDF changes (the daily check opens a pull request on the bot's repo when it does).",
"version": 1,
"source": {
"title": "Threshing Options (community route PDF)",
"authors": [
"u/ClumsyBadger",
"u/Old_Regular3018",
"u/Smart_Trifle_2099"
],
"version": "2026-11-16",
"link": "https://drive.google.com/file/d/17o72ehHsSPW4UdsKF-sXTxMLEuinWeEg/view",
"note": "Percentages are the guide's, from documented runs; options off the recommended path often rest on fewer than three records."
},
"encounters": {
"valley-Red": {
"title": "The valley Red",
"scene": "You're moved by an instinctual feeling that this...",
"options": [
{
"say": "Is your dragon",
"best": true,
"then": [
{
"say": "You're sure",
"best": true,
"then": [
{
"say": "Continue approach",
"best": true,
"then": [
{
"say": "Touch its talon",
"best": true,
"pct": "93%",
"end": "Bonded"
},
{
"say": "Run to mount its foreleg",
"end": "Bonded"
}
]
},
{
"say": "Exit gracefully",
"end": "That was close (on to the meadow)"
}
]
},
{
"say": "On second thought…",
"end": "That was close (on to the meadow)"
}
]
},
{
"say": "Is not your dragon, leave",
"end": "That was close (on to the meadow)"
}
]
},
"tree-Red": {
"title": "The Red below the tree",
"scene": "A red dragon prowls ten feet beneath you.",
"warning": "The guide gives a 98% chance of dying if you engage this dragon.",
"options": [
{
"say": "Jump on its back, or jump to land by its tail",
"then": [
{
"roll": "Some unknown chance or decision roll"
},
{
"say": "Hold the Red's gaze",
"then": [
{
"say": "Jump off and hope",
"end": "Incinerated"
},
{
"say": "Drop to your stomach",
"then": [
{
"say": "Hang tight",
"end": "Incinerated"
},
{
"say": "Crawl to the seat",
"pct": "2%",
"end": "Bonded"
}
]
}
]
},
{
"say": "Lower your eyes",
"end": "Incinerated"
}
]
},
{
"say": "Wait and pursue the Green",
"end": "On to the two Greens"
}
]
},
"tree-Greens": {
"title": "The two Greens",
"scene": "You enter a clearing with two Green dragons.",
"options": [
{
"say": "Turn to the right dragon",
"best": true,
"then": [
{
"say": "Glance to the left dragon",
"end": "Incinerated"
},
{
"say": "Don't move a muscle",
"best": true,
"then": [
{
"say": "Stay still",
"best": true,
"then": [
{
"say": "Decapitation isn't scary",
"best": true,
"then": [
{
"say": "You respect their nature",
"best": true,
"end": "Bonded (Right Green)"
},
{
"say": "You don't know",
"end": "Incinerated"
},
{
"say": "Greens have the best magic",
"best": true,
"end": "Bonded (Left Green)"
},
{
"say": "Intellect match",
"best": true,
"end": "A Brown saves you: Bonded (Brown)"
}
]
},
{
"say": "Sidestep out of its mouth",
"end": "Incinerated"
}
]
},
{
"say": "Sidestep out of its mouth",
"end": "Incinerated"
}
]
}
]
},
{
"say": "Turn to the left dragon",
"best": true,
"then": [
{
"say": "Glance to the right dragon",
"end": "Incinerated"
},
{
"say": "Don't move a muscle",
"best": true,
"then": [
{
"say": "Hold your ground",
"best": true,
"then": [
{
"say": "You always overextend",
"best": true,
"end": "Bonded (Right Green)"
},
{
"say": "You lack flaws",
"end": "Incinerated"
},
{
"say": "You struggle with temper",
"best": true,
"end": "Bonded (Left Green)"
},
{
"say": "You're always right",
"best": true,
"end": "An Orange saves you: Bonded (Orange)"
}
]
},
{
"say": "Step back",
"end": "Incinerated"
}
]
}
]
},
{
"say": "Stay neutral",
"end": "Incinerated"
}
]
},
"meadow-Orange": {
"title": "The meadow Orange",
"scene": "You approach the Orange dragon.",
"options": [
{
"say": "Absolutely sure, Orange",
"best": true,
"pct": "90%",
"then": [
{
"say": "Roar right back at it",
"best": true,
"pct": "69%",
"then": [
{
"say": "Flee",
"end": "Incinerated"
},
{
"say": "Attempt to mount",
"best": true,
"end": "Bonded"
},
{
"roll": "Possibly an unknown decision or chance mechanic (20%)"
},
{
"say": "Hit the ground",
"best": true,
"then": [
{
"say": "Run to mount its foreleg",
"best": true,
"end": "Bonded"
},
{
"say": "Look it in the eye",
"then": [
{
"say": "Run to mount",
"end": "Bonded"
},
{
"say": "Maintain eye contact",
"end": "Incinerated"
}
]
}
]
},
{
"say": "Run at the claw",
"then": [
{
"say": "Hold tight for balance",
"end": "Incinerated"
},
{
"say": "Climb with strength",
"end": "Bonded"
}
]
}
]
},
{
"say": "Run, this was a mistake",
"end": "Incinerated"
}
]
},
{
"say": "On second thought…",
"pct": "10%",
"end": "Incinerated"
}
]
},
"meadow-Brown": {
"title": "The meadow Brown",
"scene": "You approach the Brown dragon.",
"options": [
{
"say": "Run after the Brown",
"best": true,
"then": [
{
"say": "On second thought…",
"end": "Incinerated"
},
{
"say": "Your heart is sure",
"best": true,
"then": [
{
"say": "Shout at it to stop",
"pct": "50%",
"then": [
{
"say": "Apologise immediately",
"pct": "50%",
"end": "Incinerated"
},
{
"say": "Await judgment, or pray",
"pct": "90%",
"then": [
{
"say": "Mud fight!",
"then": [
{
"say": "Wipe off the mud",
"pct": "90%",
"then": [
{
"say": "The dragon speaks",
"then": [
{
"say": "Defend the kingdom",
"end": "Death 50/50"
},
{
"say": "Defend the powerless",
"end": "Bonded"
},
{
"say": "Seek revenge",
"end": "Incinerated"
}
]
}
]
},
{
"say": "Throw mud at the dragon",
"pct": "60%",
"end": "Bonded"
},
{
"say": "Find a better dragon",
"end": "Not recorded"
}
]
}
]
}
]
},
{
"say": "Indecisively chase it",
"end": "Incinerated"
},
{
"say": "Mount the Brown's tail",
"best": true,
"then": [
{
"say": "Throw your weight",
"best": true,
"then": [
{
"say": "You'll charm it",
"best": true,
"end": "Bonded"
},
{
"say": "Hope for a clean death",
"end": "Incinerated"
},
{
"say": "It's already talking to you",
"end": "Bonded"
}
]
},
{
"say": "Wait for a better angle",
"end": "Incinerated"
}
]
}
]
}
]
},
{
"say": "Turn to the Orange",
"end": "Incinerated"
}
]
},
"meadow-Blue": {
"title": "The meadow Blue",
"scene": "You approach the Blue dragon.",
"options": [
{
"say": "Change to Orange",
"pct": "?",
"unconfirmed": true,
"end": "Not tested"
},
{
"say": "Change to Brown",
"pct": "?",
"unconfirmed": true,
"end": "Not tested"
},
{
"say": "Absolutely, Blue Dragon",
"best": true,
"pct": "90%",
"then": [
{
"say": "Hold glare and advance",
"best": true,
"pct": "80%",
"then": [
{
"say": "Do nothing",
"best": true,
"pct": "83%",
"then": [
{
"say": "Lower your eyes",
"pct": "?",
"unconfirmed": true,
"end": "Incinerated"
},
{
"say": "Help the cadet",
"pct": "0%",
"end": "Incinerated"
},
{
"say": "Hold glare and watch",
"best": true,
"pct": "80%",
"then": [
{
"say": "Straighten your spine",
"best": true,
"pct": "82%",
"then": [
{
"say": "Hold steady",
"pct": "0%",
"unconfirmed": true,
"end": "Incinerated"
},
{
"say": "Launch yourself right",
"best": true,
"pct": "85%",
"then": [
{
"say": "You already know",
"pct": "?",
"unconfirmed": true,
"end": "Not tested"
},
{
"say": "Bring down an empire",
"best": true,
"pct": "80%",
"then": [
{
"say": "Seize the chance to mount",
"pct": "50%",
"end": "Incinerated"
},
{
"say": "Move slowly forward",
"best": true,
"pct": "80%",
"end": "Bonded"
},
{
"say": "Hold still",
"pct": "50%",
"end": "Incinerated"
}
]
},
{
"say": "I want revenge",
"pct": "?",
"unconfirmed": true,
"end": "Not tested"
},
{
"say": "Defend the helpless",
"pct": "?",
"unconfirmed": true,
"end": "Not tested"
}
]
}
]
},
{
"say": "Speak first",
"pct": "20%",
"end": "Incinerated"
},
{
"say": "Do nothing",
"pct": "?",
"end": "Incinerated"
}
]
}
]
},
{
"say": "Intervene and help",
"pct": "?",
"end": "Incinerated"
}
]
},
{
"say": "Lower gaze, halt advance",
"pct": "0%",
"end": "Incinerated"
},
{
"say": "Lower gaze, advance",
"pct": "0%",
"end": "Incinerated"
}
]
}
]
},
"shadow": {
"title": "The shadow",
"scene": "You've seen a shadow, where will it lead...",
"options": [
{
"say": "A green sounds good",
"unconfirmed": true,
"end": "Not tested"
},
{
"say": "Stay the course",
"best": true,
"then": [
{
"say": "Well this is intriguing",
"best": true,
"then": [
{
"say": "Curiosity sated, retreat",
"then": [
{
"say": "Find that Green",
"end": "On to the two Greens"
},
{
"say": "Go towards the valley",
"unconfirmed": true,
"end": "Not tested"
}
]
},
{
"say": "Freeze and lower your eyes",
"best": true,
"then": [
{
"say": "Warn the cadet",
"end": "Incinerated"
},
{
"say": "Hold still",
"best": true,
"then": [
{
"say": "Aid the cadet",
"unconfirmed": true,
"end": "Not tested"
},
{
"say": "Hold position",
"best": true,
"then": [
{
"say": "Approach the Blue",
"then": [
{
"say": "On second thought…",
"unconfirmed": true,
"end": "Not tested"
},
{
"say": "You're sure",
"unconfirmed": true,
"end": "Incinerated?"
}
]
},
{
"say": "Await judgement",
"best": true,
"then": [
{
"say": "Help the cadet",
"best": true,
"then": [
{
"say": "Use your dagger",
"best": true,
"then": [
{
"say": "Head south and hope",
"best": true,
"end": "On to the Black"
}
]
},
{
"say": "Take them to cold water",
"end": "Head back for the Greens, or explore other dragons"
},
{
"say": "Clean their uniform",
"end": "Head back for the Greens, or explore other dragons"
}
]
},
{
"say": "Leave to find your dragon",
"end": "Head back for the Greens, or explore other dragons"
}
]
},
{
"say": "Run towards the other cadet",
"unconfirmed": true,
"end": "Not tested"
}
]
},
{
"say": "Last chance to escape",
"end": "Head back for the Greens, or explore other dragons"
}
]
},
{
"say": "Leave while it's distracted",
"end": "Head back for the Greens, or explore other dragons"
}
]
}
]
},
{
"say": "Too big, you're out",
"end": "Head back for the Greens, or explore other dragons"
}
]
}
]
},
"black": {
"title": "The Black",
"scene": "A branch snaps behind you...",
"note": "Lowering your eyes has frequently ended in incineration; what follows it is unconfirmed.",
"options": [
{
"say": "Ignore it, keep walking",
"end": "Incinerated"
},
{
"say": "Turn to face the threat",
"best": true,
"then": [
{
"say": "Lower your eyes",
"end": "Incinerated"
},
{
"say": "Hold its gaze",
"best": true,
"end": "Bonded"
}
]
}
]
}
},
"route_encounters": {
"valley-Red": [
"valley-Red"
],
"tree-Red": [
"tree-Red"
],
"tree-Greens": [
"tree-Greens"
],
"meadow-Orange": [
"meadow-Orange"
],
"meadow-Brown": [
"meadow-Brown"
],
"meadow-Blue": [
"meadow-Blue"
],
"shadow-Blue": [
"shadow"
],
"shadow-Black": [
"shadow",
"black"
]
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+9635 -9827
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -13,8 +13,8 @@ branch: main
# public, limited (only people signed in to this server) or private: who can open the links below # public, limited (only people signed in to this server) or private: who can open the links below
visibility: limited visibility: limited
# the published page: Ken's server serves the `pages` branch (.gitea/workflows/pages.yml). Set this to its address # the published page, when it is hosted somewhere (GitHub Pages is paused while the GitHub account is suspended;
# once it is up (then `python -m collection build`): the page's links and the dataset metadata use it. # the page is viewed locally or as a Claude artifact meanwhile)
site: null site: null
# other copies of the repository (informational) # other copies of the repository (informational)
+3 -3
View File
@@ -6,11 +6,11 @@
"scripts": { "scripts": {
"build": "node site/build.js", "build": "node site/build.js",
"dev": "node site/build.js && python3 -m http.server 8000 -d dist", "dev": "node site/build.js && python3 -m http.server 8000 -d dist",
"test:py": "python3 -m collection build --check && python3 planner/build_experiments.py --check && python3 analysis/black/evidence.py --check && python3 analysis/tree/build_tree.py --check && python3 analysis/known/build_known.py --check && python3 analysis/overlap/overlap.py --check && PYTHONPATH=core python3 -m unittest discover -s tests/core -p 'test_*.py' && python3 -m unittest discover -s tests/collection -p 'test_*.py'", "test:py": "python3 -m collection build --check && python3 planner/build_experiments.py --check && python3 analysis/black/evidence.py --check && python3 analysis/tree/build_tree.py --check && PYTHONPATH=core python3 -m unittest discover -s tests/core -p 'test_*.py' && python3 -m unittest discover -s tests/collection -p 'test_*.py'",
"test:unit": "node --test tests/core/graph.test.js tests/core/advisor.test.js tests/core/known.test.js", "test:unit": "node --test tests/core/graph.test.js tests/core/advisor.test.js",
"test": "npm run test:py && npm run test:unit", "test": "npm run test:py && npm run test:unit",
"graph": "node analysis/network/build-graph.js", "graph": "node analysis/network/build-graph.js",
"policy": "python3 planner/build_policy.py && python3 planner/policy_report.py && python3 planner/build_experiments.py && python3 analysis/black/evidence.py && python3 analysis/tree/build_tree.py && python3 analysis/known/build_known.py && python3 analysis/overlap/overlap.py", "policy": "python3 planner/build_policy.py && python3 planner/policy_report.py && python3 planner/build_experiments.py && python3 analysis/black/evidence.py && python3 analysis/tree/build_tree.py",
"cycle": "python3 -m collection cycle", "cycle": "python3 -m collection cycle",
"stats": "python3 analysis/stats/site_stats.py", "stats": "python3 analysis/stats/site_stats.py",
"collect": "python3 -m collection update", "collect": "python3 -m collection update",
+1 -9
View File
@@ -31,19 +31,11 @@ def low_bias(r, lb=CONFIG["low_bias"]):
"""Kept in the low-bias sample: every run of an always-kept source, bulk logs, and riders not chasing a rare dragon.""" """Kept in the low-bias sample: every run of an always-kept source, bulk logs, and riders not chasing a rare dragon."""
if r["source"] in lb["always"]: if r["source"] in lb["always"]:
return True return True
if r["source"] in (lb.get("never") or ()):
return False
if r["source"] == "reddit spreadsheet" and "bulk" in lb["entries_kept"] and r["entry"] not in (None, "Form"): if r["source"] == "reddit spreadsheet" and "bulk" in lb["entries_kept"] and r["entry"] not in (None, "Form"):
return True return True
return r["goal"] not in lb["rare_goals"] return r["goal"] not in lb["rare_goals"]
def drop_flagged(runs, on=CONFIG.get("drop_impossible", True)):
"""Without the runs that cannot have happened as recorded (atlas.runs.impossible; planner/policy.yaml
drop_impossible): every other run is kept, however partial."""
return [r for r in runs if not (on and runs_io.impossible(r))]
def clean(o): def clean(o):
"""JSON-safe: numpy numbers to floats, infinities and NaN to null (as JavaScript's JSON.stringify does).""" """JSON-safe: numpy numbers to floats, infinities and NaN to null (as JavaScript's JSON.stringify does)."""
if isinstance(o, dict): if isinstance(o, dict):
@@ -64,7 +56,7 @@ def main(argv=None):
ap.add_argument("--out", default=str(ROOT / "data/public/policy.json")) ap.add_argument("--out", default=str(ROOT / "data/public/policy.json"))
a = ap.parse_args(argv) a = ap.parse_args(argv)
runs = drop_flagged(runs_io.read(a.data, sources=SOURCES)) runs = runs_io.read(a.data, sources=SOURCES)
rows = len(runs) rows = len(runs)
samples = { samples = {
"all": runs, "all": runs,
+1 -8
View File
@@ -6,19 +6,13 @@
version: 1 version: 1
# the `source` values of data/public/runs_clean.csv the model learns from # the `source` values of data/public/runs_clean.csv the model learns from
sources: [reddit spreadsheet, reported, bot, reddit comment] sources: [reddit spreadsheet, reported, bot]
# Every run of the sources above is used, however partial, except a run that cannot have happened as recorded
# (core/spec/form.yaml impossible_flags: it breaks one of the game's rules). Such runs stay in runs_clean.csv, flagged;
# a hand fix that clears the flag brings a Reddit or reported run back. The site statistics use the same rule.
drop_impossible: true
# Two samples. "all" is every run above. "lowBias" leaves out runs where a rare sighting is more likely to have # 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 # 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. # run, and bulk-pasted logs record every run of the players who kept them, so both stay in.
low_bias: low_bias:
always: [bot] # sources whose every run is kept always: [bot] # sources whose every run is kept
never: [reddit comment] # riders posting a run in a thread pick the notable ones, like rare-chasers
entries_kept: [bulk] # spreadsheet rows whose `entry` is not "Form" (bulk-pasted logs) entries_kept: [bulk] # spreadsheet rows whose `entry` is not "Form" (bulk-pasted logs)
rare_goals: [Blue, Black, Blue or Black] rare_goals: [Blue, Black, Blue or Black]
@@ -44,4 +38,3 @@ reporting_bias:
- { name: "form, chasing Blue/Black", when: { source: reddit spreadsheet, goal: rare } } - { name: "form, chasing Blue/Black", when: { source: reddit spreadsheet, goal: rare } }
- { name: "form, other", when: { source: reddit spreadsheet } } - { name: "form, other", when: { source: reddit spreadsheet } }
- { name: reported, when: { source: reported }, same_as: "form, other" } - { name: reported, when: { source: reported }, same_as: "form, other" }
- { name: reddit comments, when: { source: reddit comment } } # self-selected: its own reporting rate
+1 -3
View File
@@ -84,7 +84,6 @@
// ------------------------------------------------------------ data loading // ------------------------------------------------------------ data loading
async function loadStats() { async function loadStats() {
state.stats = await (await fetch("data/stats.json")).json(); state.stats = await (await fetch("data/stats.json")).json();
try { state.overlap = await (await fetch("data/overlap.json")).json(); } catch { state.overlap = null; }
const sel = $("#f-preset"); const sel = $("#f-preset");
sel.innerHTML = Object.entries(META().presets).map(([k, l]) => `<option value="${k}">${esc(l)}</option>`).join(""); sel.innerHTML = Object.entries(META().presets).map(([k, l]) => `<option value="${k}">${esc(l)}</option>`).join("");
sel.value = state.preset; sel.value = state.preset;
@@ -555,8 +554,7 @@
</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> </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 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>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>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>
${state.overlap && state.overlap.comparable ? `<div class="panel"><h3>The same run reported twice?</h3><p class="small">A rider may log a run in the form and post it in a megathread comment too. With no player IDs, a copy can only be measured, not proven, so nothing is removed. Of ${state.overlap.comparable} Reddit runs detailed enough to compare, ${state.overlap.matched} give the same answers as a form row sent within ${state.overlap.rule.window_days} day; chance alone (the same test a few weeks off) gives about ${state.overlap.expected_by_chance}. So about ${Math.round(state.overlap.likely_double)} of ${state.overlap.comment_runs} Reddit runs look reported twice${state.overlap.likely_double < 0.1 * state.overlap.comment_runs ? ", too few to matter" : ""}.</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>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(Object.entries(m.sources).filter(([k]) => !["Form", "Reddit comments", "DragonKind bot", "Reported on the Atlas"].includes(k)).reduce((s, [, n]) => s + n, 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>`; <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>`;
} }
const sourceRate = (outKey, source) => state.res.source_rates[outKey][source]; const sourceRate = (outKey, source) => state.res.source_rates[outKey][source];
+8 -65
View File
@@ -92,8 +92,7 @@
const model = () => st.policy.samples[st.sample]; const model = () => st.policy.samples[st.sample];
function advisorFor(enc, colour = st.colour) { function advisorFor(enc, colour = st.colour) {
const k = `${st.sample}|${colour}|${st.objective}|${enc}`; const k = `${st.sample}|${colour}|${st.objective}|${enc}`;
// the Black needs the shadow, which (almost) only shows on a first attempt: its routes are solved for that attempt if (!st.cache.has(k)) st.cache.set(k, S.advisor(model(), colour, st.objective, { only: [enc] }));
if (!st.cache.has(k)) st.cache.set(k, S.advisor(model(), colour, st.objective, { only: [enc], attempt: colour === "Black" ? "First attempt" : null }));
return st.cache.get(k); return st.cache.get(k);
} }
let encParams = null; let encParams = null;
@@ -531,7 +530,7 @@
}); });
// destination label // destination label
const end = pts[pts.length - 1]; const end = pts[pts.length - 1];
pill(gLab, end.P.x, end.P.y + 30, `${pct(r.value.x)} ${st.colour === "Black" ? "on a first attempt" : "per attempt"}`, { edge: tc, strong: rel === 1 }); pill(gLab, end.P.x, end.P.y + 30, `${pct(r.value.x)} per attempt`, { edge: tc, strong: rel === 1 });
// choice points on the focused route: one diamond per place, even when several choices are made there // choice points on the focused route: one diamond per place, even when several choices are made there
// (at the bully fight: help or walk away, your first move, the dagger, then the bullies' fate) // (at the bully fight: help or walk away, your first move, the dagger, then the bullies' fate)
if (focus) { if (focus) {
@@ -758,62 +757,7 @@
* colour (data/tree.json, analysis/tree/build_tree.py), with what every other answer did. Only shown when the bot's * colour (data/tree.json, analysis/tree/build_tree.py), with what every other answer did. Only shown when the bot's
* way goes through the same encounter as the route; the community form does not record these answers. */ * way goes through the same encounter as the route; the community form does not record these answers. */
const TREE_SIDE = (enc) => (/^(valley|meadow)-/.test(enc) ? "valley" : "tree"); const TREE_SIDE = (enc) => (/^(valley|meadow)-/.test(enc) ? "valley" : "tree");
/** The community route PDF's answers for an encounter (data/pdf_encounters.json): its recommended (dark-tile) answers
* as numbered steps toward this dragon, then the whole tree. */
// the goal inside one encounter: a bond with this colour, or (an encounter that leads on, like the shadow before
// the Black) the way on to the next one
const isGoal = (end, colour, onward) => onward ? new RegExp(`^On to the ${onward}`).test(end || "")
: /^Bonded|Bonded \(/.test(end || "") && (!/\(/.test(end) || new RegExp(colour).test(end));
function leadsTo(o, colour, onward) {
if (o.end) return isGoal(o.end, colour, onward);
return (o.then || []).some((c) => !c.roll && leadsTo(c, colour, onward));
}
function guidePath(options, colour, onward) {
const steps = [];
let opts = options;
while (opts && opts.length) {
const live = opts.filter((o) => !o.roll);
const pick = live.find((o) => o.best && leadsTo(o, colour, onward)) || live.find((o) => leadsTo(o, colour, onward));
if (!pick) break;
const roll = opts.find((o) => o.roll);
steps.push({ pick, others: live.filter((o) => o !== pick), roll: roll ? roll.roll : null });
if (pick.end) break;
opts = pick.then;
}
return steps;
}
const endOf = (o) => (o.end ? o.end : "continues");
function treeList(options) {
return `<ul>${options.map((o) => o.roll ? `<li class="roll"><em>${esc(o.roll)}</em></li>` :
`<li class="${o.best ? "best" : ""}${o.unconfirmed ? " pale" : ""}">${esc(o.say)}${o.pct ? ` <small>${esc(o.pct)}</small>` : ""}${o.end ? ` → <b>${esc(o.end)}</b>` : ""}${o.then ? treeList(o.then) : ""}</li>`).join("")}</ul>`;
}
function guideAnswers(enc) {
const g = st.guide;
if (!g) return "";
const keys = (g.route_encounters || {})[enc] || [];
if (!keys.length) return "";
const src = g.source || {};
const blocks = keys.map((k, ki) => {
const E = g.encounters[k];
if (!E) return "";
const next = keys[ki + 1] ? (g.encounters[keys[ki + 1]] || {}).title || "" : "";
const steps = guidePath(E.options, st.colour, next ? next.replace(/^The /, "") : null);
const rows = steps.map((s, i) => `<li><span class="n">${i + 1}</span><div><b>${esc(s.pick.say)}</b>${s.roll ? `<small class="ex-roll">The guide notes: ${esc(s.roll)}.</small>` : ""}
<small>${s.pick.pct ? `the guide's rate: ${esc(s.pick.pct)}` : ""}${s.pick.unconfirmed ? " · unconfirmed" : ""}${s.pick.end ? `${s.pick.pct ? " · " : ""}${esc(s.pick.end)}` : ""}</small>
${s.others.length ? `<details><summary>Other answers here</summary><ul>${s.others.map((o) => `<li>${esc(o.say)}${o.pct ? ` <small>${esc(o.pct)}</small>` : ""} → ${esc(endOf(o))}</li>`).join("")}</ul></details>` : ""}</div></li>`).join("");
return `<p class="small"><b>${esc(E.title)}</b>: <em>${esc(E.scene)}</em>${E.warning ? ` <span class="ex-warn">${esc(E.warning)}</span>` : ""}</p>
${rows ? `<ol>${rows}</ol>` : `<p class="small muted">The guide shows no way to bond a ${st.colour} here.</p>`}
${E.note ? `<p class="small muted">${esc(E.note)}</p>` : ""}
<details class="ex-fulltree"><summary>Every answer in the guide's tree</summary>${treeList(E.options)}</details>`;
}).join("");
return `<div class="ex-inside"><span class="eyebrow">Inside the encounter: the community guide's answers</span>${blocks}
<p class="small muted">From the <a href="${esc(src.link || "#")}" target="_blank" rel="noopener">community route PDF</a> by ${esc((src.authors || []).join(", "))} (${esc(src.version || "")} version), transcribed as data. ${esc(src.note || "")}</p></div>`;
}
function encounterAnswers(enc) { function encounterAnswers(enc) {
return guideAnswers(enc) + botAnswers(enc);
}
function botAnswers(enc) {
const t = st.tree; const t = st.tree;
if (!t) return '<p class="small muted ex-inside">Loading the answers inside the encounter…</p>'; if (!t) return '<p class="small muted ex-inside">Loading the answers inside the encounter…</p>';
const best = (t.best || {})[st.colour]; const best = (t.best || {})[st.colour];
@@ -822,7 +766,7 @@
const side = hourAt >= 0 && /valley/i.test(picks[hourAt].text) ? "valley" : "tree"; const side = hourAt >= 0 && /valley/i.test(picks[hourAt].text) ? "valley" : "tree";
const viaShadow = picks && picks.some((p) => /shadow/i.test(p.text) && !/descend/i.test(p.text)); const viaShadow = picks && picks.some((p) => /shadow/i.test(p.text) && !/descend/i.test(p.text));
const fits = picks && hourAt >= 0 && side === TREE_SIDE(enc) && (enc.startsWith("shadow-") ? viaShadow : !viaShadow || side === "valley"); const fits = picks && hourAt >= 0 && side === TREE_SIDE(enc) && (enc.startsWith("shadow-") ? viaShadow : !viaShadow || side === "valley");
if (!fits) return `<p class="small muted ex-inside">The DragonKind bot hasn't bonded a ${st.colour} through ${esc(ENC_NAME[enc] || enc)} yet, so it can't confirm these answers. (The community form records only how the encounter ended, not the answers given.)</p>`; if (!fits) return `<p class="small muted ex-inside">The bot hasn't bonded a ${st.colour} through ${esc(ENC_NAME[enc] || enc)} yet, so the answers inside this encounter aren't mapped. The community form records only how the encounter ended, not the answers given.</p>`;
const died = (o) => (o.to && o.to.DIED ? o.to.DIED.n : 0); const died = (o) => (o.to && o.to.DIED ? o.to.DIED.n : 0);
const rows = picks.slice(hourAt + 1).map((p, i) => { const rows = picks.slice(hourAt + 1).map((p, i) => {
const sc = t.screens[p.screen] || { options: {} }; const sc = t.screens[p.screen] || { options: {} };
@@ -835,14 +779,14 @@
${others ? `<details><summary>Other answers here</summary><ul>${others}</ul></details>` : ""}</div></li>`; ${others ? `<details><summary>Other answers here</summary><ul>${others}</ul></details>` : ""}</div></li>`;
}).join(""); }).join("");
const end = Object.keys((t.screens[picks[picks.length - 1].screen] || { options: {} }).options[picks[picks.length - 1].option]?.to || {}).find((k) => k.startsWith("BONDED")); const end = Object.keys((t.screens[picks[picks.length - 1].screen] || { options: {} }).options[picks[picks.length - 1].option]?.to || {}).find((k) => k.startsWith("BONDED"));
return `<div class="ex-inside"><span class="eyebrow">What the DragonKind bot did: the answers that bonded</span> return `<div class="ex-inside"><span class="eyebrow">Inside the encounter: the answers that bonded</span>
<ol>${rows}</ol> <ol>${rows}</ol>
<p class="small muted">${end ? `Bonded a ${end.split(":")[1]}. ` : ""}From the bot's own runs (it logs every screen it sees), so the counts are small; untested answers may also work.</p></div>`; <p class="small muted">${end ? `Bonded a ${end.split(":")[1]}. ` : ""}From the bot's own runs (it logs every screen it sees), so the counts are small; untested answers may also work.</p></div>`;
} }
function panelRoutes(routes) { function panelRoutes(routes) {
const best = Math.max(1e-12, ...routes.map((r) => r.value.x)); const best = Math.max(1e-12, ...routes.map((r) => r.value.x));
const T = model().targets[st.colour], first = st.colour === "Black" && T.firstAttempt, b = first ? T.firstAttempt.thisAttempt : T[st.objective]; const T = model().targets[st.colour], b = T[st.objective];
const focus = routes.find((r) => r.enc === st.focus) || routes[0]; const focus = routes.find((r) => r.enc === st.focus) || routes[0];
const card = (r) => { const card = (r) => {
const rel = r.value.x / best, o = encOutcome(r.enc), c = encColour(r.enc); const rel = r.value.x / best, o = encOutcome(r.enc), c = encColour(r.enc);
@@ -852,7 +796,7 @@
return `<button type="button" class="ex-route-card${r.enc === focus.enc ? " on" : ""}" data-enc="${r.enc}" aria-pressed="${r.enc === focus.enc}"> return `<button type="button" class="ex-route-card${r.enc === focus.enc ? " on" : ""}" data-enc="${r.enc}" aria-pressed="${r.enc === focus.enc}">
<i class="ex-swatch ${style}" style="--c: var(${DV[st.colour]}); opacity:${(0.3 + 0.7 * rel).toFixed(2)}"></i> <i class="ex-swatch ${style}" style="--c: var(${DV[st.colour]}); opacity:${(0.3 + 0.7 * rel).toFixed(2)}"></i>
<span class="nm">${esc(ENC_NAME[r.enc])}${RESCUE[st.colour] === r.enc && st.colour !== "Green" ? " <em>(rescue)</em>" : ""}</span> <span class="nm">${esc(ENC_NAME[r.enc])}${RESCUE[st.colour] === r.enc && st.colour !== "Green" ? " <em>(rescue)</em>" : ""}</span>
<b>${pct(r.value.x)}</b><small>${st.colour === "Black" ? "on a first attempt" : "per attempt"} · ${bond}${n < 30 ? ` · only ${n} attempts logged` : ""}${r.value.o > 0.005 ? ` · ends on another dragon ${pct(r.value.o)}` : ""}</small></button>`; <b>${pct(r.value.x)}</b><small>per attempt · ${bond}${n < 30 ? ` · only ${n} attempts logged` : ""}${r.value.o > 0.005 ? ` · ends on another dragon ${pct(r.value.o)}` : ""}</small></button>`;
}; };
const steps = focus.steps.filter((s) => s.kind === "decision" || s.kind === "chance").map((s) => { const steps = focus.steps.filter((s) => s.kind === "decision" || s.kind === "chance").map((s) => {
if (s.kind === "chance") return `<li class="chance"><span>${esc(s.label)}</span><b>${esc(String(s.taken))}</b><small>roll ${pct(s.probs[s.taken])}</small></li>`; if (s.kind === "chance") return `<li class="chance"><span>${esc(s.label)}</span><b>${esc(String(s.taken))}</b><small>roll ${pct(s.probs[s.taken])}</small></li>`;
@@ -863,7 +807,7 @@
return `<li class="dec${open ? " open" : ""}"><button type="button" class="ex-step" data-var="${s.var}" aria-expanded="${open}"><span>${esc(s.label)}</span><b>${esc(String(s.taken))}</b><small>${s.userSet ? "your choice" : "best"} · ${s.var === "encounter" ? pct(s.options[s.taken].pX) : pct(s.options[s.taken].pX)}</small></button>${opts}${inside}</li>`; return `<li class="dec${open ? " open" : ""}"><button type="button" class="ex-step" data-var="${s.var}" aria-expanded="${open}"><span>${esc(s.label)}</span><b>${esc(String(s.taken))}</b><small>${s.userSet ? "your choice" : "best"} · ${s.var === "encounter" ? pct(s.options[s.taken].pX) : pct(s.options[s.taken].pX)}</small></button>${opts}${inside}</li>`;
}).join(""); }).join("");
const risks = focus.steps.filter((s) => s.risk && s.risk.p > 0.0005).map((s) => `${s.risk.label.toLowerCase()} ${pct(s.risk.p)}`); const risks = focus.steps.filter((s) => s.risk && s.risk.p > 0.0005).map((s) => `${s.risk.label.toLowerCase()} ${pct(s.risk.p)}`);
const lbT = st.policy.samples.lowBias.targets[st.colour], lb = first && lbT.firstAttempt ? lbT.firstAttempt.thisAttempt : lbT.thisAttempt; const lb = st.policy.samples.lowBias.targets[st.colour].thisAttempt;
return `<div class="ex-head" style="--c: var(${DV[st.colour]})">${mini(st.colour, POSE_OF[st.colour])}<div><span class="eyebrow">Routes to a</span><h2 id="h-valley">${st.colour} dragon</h2></div> return `<div class="ex-head" style="--c: var(${DV[st.colour]})">${mini(st.colour, POSE_OF[st.colour])}<div><span class="eyebrow">Routes to a</span><h2 id="h-valley">${st.colour} dragon</h2></div>
<button type="button" class="ex-close" id="ex-clear" aria-label="Back to the whole valley">×</button></div> <button type="button" class="ex-close" id="ex-clear" aria-label="Back to the whole valley">×</button></div>
${chooser()} ${chooser()}
@@ -875,7 +819,7 @@
<ol class="ex-steps">${steps}</ol> <ol class="ex-steps">${steps}</ol>
<p class="small muted">Diamonds on the map are choices: click one to see where the other options lead. ${st.blocked ? "" : `Your choices apply to every route to this dragon. Changed your mind? <button type="button" class="linklike" id="ex-reset-route">Reset your choices</button>`}</p> <p class="small muted">Diamonds on the map are choices: click one to see where the other options lead. ${st.blocked ? "" : `Your choices apply to every route to this dragon. Changed your mind? <button type="button" class="linklike" id="ex-reset-route">Reset your choices</button>`}</p>
<details class="ex-why"><summary>Why this route?</summary> <details class="ex-why"><summary>Why this route?</summary>
${first ? `<p class="small"><span class="pill warn">Low evidence</span> Best route for the Black, on a <b>first attempt</b>: about <b>1 in ${Math.round(1 / Math.max(b.pX.mean, 1e-9))}</b>, somewhere between 1 in ${Math.round(1 / Math.max(b.pX.hi, 1e-9))} and 1 in ${Math.round(1 / Math.max(b.pX.lo, 1e-9))} (95%). Later attempts almost never see the shadow. The low-bias sample suggests about 1 in ${Math.round(1 / Math.max(lb.pX.mean, 1e-9))}. Every logged shadow comes from riders who chose to post their run, so the shadow's odds rest on an assumption until complete first-attempt logs exist.</p>` : `<p class="small">Best route for any ${st.colour}: <b>${pct(b.pX.mean)}</b> per attempt (95% interval ${pct(b.pX.lo)}–${pct(b.pX.hi)}), about ${isFinite(b.expectedAttempts.mean) ? Math.round(b.expectedAttempts.mean) : "–"} attempts. Riders who logged every run suggest ${pct(lb.pX.mean)}.</p>`} <p class="small">Best route for any ${st.colour}: <b>${pct(b.pX.mean)}</b> per attempt (95% interval ${pct(b.pX.lo)}–${pct(b.pX.hi)}), about ${isFinite(b.expectedAttempts.mean) ? Math.round(b.expectedAttempts.mean) : "–"} attempts. Riders who logged every run suggest ${pct(lb.pX.mean)}.</p>
<p class="small">Each roll's odds may depend on your earlier choices, as far as the data support it. Choices marked "no clear winner" in <a href="#deep">Deep Dive</a> are within the noise.${risks.length ? ` Risks on this route: ${risks.join(", ")}.` : ""}</p> <p class="small">Each roll's odds may depend on your earlier choices, as far as the data support it. Choices marked "no clear winner" in <a href="#deep">Deep Dive</a> are within the noise.${risks.length ? ` Risks on this route: ${risks.join(", ")}.` : ""}</p>
<p class="small">The bond chance at each encounter is the community average: the form does not record the answers riders gave there.</p> <p class="small">The bond chance at each encounter is the community average: the form does not record the answers riders gave there.</p>
<div class="seg" role="group" aria-label="Data"><button type="button" data-s="all" aria-pressed="${st.sample === "all"}">All runs</button><button type="button" data-s="lowBias" aria-pressed="${st.sample === "lowBias"}">Low-bias</button></div> <div class="seg" role="group" aria-label="Data"><button type="button" data-s="all" aria-pressed="${st.sample === "all"}">All runs</button><button type="button" data-s="lowBias" aria-pressed="${st.sample === "lowBias"}">Low-bias</button></div>
@@ -1016,7 +960,6 @@
render(); render();
// the screen tree (the answers inside each encounter), for the "Bonding encounter" step // the screen tree (the answers inside each encounter), for the "Bonding encounter" step
fetch("data/tree.json").then((r) => r.json()).then((t) => { st.tree = t; if (st.expanded === "encounter") render(); }).catch(() => { st.tree = { best: {}, screens: {} }; }); fetch("data/tree.json").then((r) => r.json()).then((t) => { st.tree = t; if (st.expanded === "encounter") render(); }).catch(() => { st.tree = { best: {}, screens: {} }; });
fetch("data/pdf_encounters.json").then((r) => r.json()).then((g) => { st.guide = g; if (st.expanded === "encounter") render(); }).catch(() => {});
fetch("data/policy.json").then((r) => r.json()).then((p) => { fetch("data/policy.json").then((r) => r.json()).then((p) => {
st.policy = p; st.policy = p;
S.useGame(p.samples.all); // the game (and where each colour can be bonded) comes with the route model S.useGame(p.samples.all); // the game (and where each colour can be bonded) comes with the route model
-8
View File
@@ -182,8 +182,6 @@ section h2 { font-family: var(--font-crest); letter-spacing: 0.03em; }
.odd .big { font-family: var(--font-crest); font-weight: 700; font-size: 2.1rem; line-height: 1; color: var(--c, var(--ink)); } .odd .big { font-family: var(--font-crest); font-weight: 700; font-size: 2.1rem; line-height: 1; color: var(--c, var(--ink)); }
.odd .what { font-weight: 600; } .odd .what { font-weight: 600; }
.odd .how { font-size: var(--step--1); color: var(--muted); } .odd .how { font-size: var(--step--1); color: var(--muted); }
.odd-low { border-style: dashed; }
.odd-low .big { opacity: 0.85; }
.odd svg { display: block; width: 100%; max-width: 220px; height: auto; } .odd svg { display: block; width: 100%; max-width: 220px; height: auto; }
.odd::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--c, var(--line)); } .odd::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--c, var(--line)); }
.combo { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; } .combo { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; }
@@ -356,12 +354,6 @@ footer { border-top-color: var(--line); }
.ex-inside small { color: var(--muted); } .ex-inside small { color: var(--muted); }
.ex-inside details summary { cursor: pointer; font-size: var(--step--1); color: var(--muted); } .ex-inside details summary { cursor: pointer; font-size: var(--step--1); color: var(--muted); }
.ex-inside ul { margin: 4px 0 0 16px; padding: 0; font-size: var(--step--1); } .ex-inside ul { margin: 4px 0 0 16px; padding: 0; font-size: var(--step--1); }
.ex-inside + .ex-inside { margin-top: 8px; }
.ex-inside .ex-roll { display: block; font-style: italic; }
.ex-fulltree ul { list-style: disc; }
.ex-fulltree li.best { font-weight: 600; }
.ex-fulltree li.pale { opacity: 0.7; font-style: italic; }
.ex-fulltree li.roll { list-style: none; }
.ex-head { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 10px; align-items: center; } .ex-head { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.ex-head svg { width: 64px; height: 52px; } .ex-head svg { width: 64px; height: 52px; }
.ex-head h2 { color: var(--c); } .ex-head h2 { color: var(--c); }
-10
View File
@@ -159,8 +159,6 @@
if (!b) { if (t2) t2.innerHTML = '<h3>Your first attempt is different</h3><p class="small muted">The shadow evidence could not be loaded.</p>'; return; } if (!b) { if (t2) t2.innerHTML = '<h3>Your first attempt is different</h3><p class="small muted">The shadow evidence could not be loaded.</p>'; return; }
const ff = b.form_first, fl = b.form_later, sr = b.same_route, as = b.after_shadow, gaze = as.answers["held its gaze"]; const ff = b.form_first, fl = b.form_later, sr = b.same_route, as = b.after_shadow, gaze = as.answers["held its gaze"];
if (t2) t2.innerHTML = `<h3>Your first attempt is different</h3><p class="small">Among riders who helped their squadmate and climbed the tree, the shadow came in <b>${frac(ff)}</b> first attempts (${pct(ff[0] / ff[1], 1)}) and <b>${frac(fl)}</b> later ones. On the very same routes, first attempts saw it about ${Math.round(sr.first_shadows / Math.max(sr.expected, 1) * 10) / 10}× as often as chance would give. The shadow is not a dice roll you can repeat.</p>`; if (t2) t2.innerHTML = `<h3>Your first attempt is different</h3><p class="small">Among riders who helped their squadmate and climbed the tree, the shadow came in <b>${frac(ff)}</b> first attempts (${pct(ff[0] / ff[1], 1)}) and <b>${frac(fl)}</b> later ones. On the very same routes, first attempts saw it about ${Math.round(sr.first_shadows / Math.max(sr.expected, 1) * 10) / 10}× as often as chance would give. The shadow is not a dice roll you can repeat.</p>`;
const steps = $("#black-steps");
if (steps) steps.innerHTML = `How it breaks down: the shadow came in ${frac(ff)} reported first attempts (over-reported); after it, ${as.reached_black} riders reached the Black and <b>${as.bonded_black}</b> bonded (${pct(as.bonded_black / Math.max(as.reached_black, 1))}).`;
if (!box) return; if (!box) return;
const br = b.best_route; const br = b.best_route;
box.hidden = false; box.hidden = false;
@@ -172,7 +170,6 @@
${gaze ? `<li>At the Black, riders who held its gaze bonded in <b>${frac(gaze)}</b> logged answers.</li>` : ""} ${gaze ? `<li>At the Black, riders who held its gaze bonded in <b>${frac(gaze)}</b> logged answers.</li>` : ""}
<li>The bot has made ${b.bot.attempts.toLocaleString()} attempts on ${b.bot.accounts} accounts, ${b.bot.gated_tree} on the gated path, and seen the shadow ${b.bot.shadows} times: none of them was a first attempt${b.bot.earliest_attempt ? ` (its earliest was attempt ${b.bot.earliest_attempt})` : ""}, which fits.</li> <li>The bot has made ${b.bot.attempts.toLocaleString()} attempts on ${b.bot.accounts} accounts, ${b.bot.gated_tree} on the gated path, and seen the shadow ${b.bot.shadows} times: none of them was a first attempt${b.bot.earliest_attempt ? ` (its earliest was attempt ${b.bot.earliest_attempt})` : ""}, which fits.</li>
</ul> </ul>
<p class="small"><b>Why the Black's odds are uncertain.</b> The Black comes only after the shadow, and every logged shadow comes from riders who chose to post their run. Riders are much more likely to post a run with a shadow than one without, and no complete log (the bot, bulk logs) has a first attempt with a shadow yet, so the estimate assumes riders over-report the shadow as much as the meadow Blue. Fresh accounts the bot plays to the tree on their first attempt will replace that assumption; until then the odds are a range, not a figure.</p>
<p class="small muted">Method and every table: <code>analysis/reports/BLACK.md</code>; the numbers: <a href="data/black.json">data/black.json</a>.</p>`; <p class="small muted">Method and every table: <code>analysis/reports/BLACK.md</code>; the numbers: <a href="data/black.json">data/black.json</a>.</p>`;
} }
@@ -192,13 +189,6 @@
const art = (c) => window.DragonArt ? `<svg class="odd-art" viewBox="0 0 200 160" aria-hidden="true">${window.DragonArt.svg(POSE[c], { fill: `var(${DV[c]})`, eyeFill: "var(--bg)", dark: c === "Black" })}</svg>` : ""; const art = (c) => window.DragonArt ? `<svg class="odd-art" viewBox="0 0 200 160" aria-hidden="true">${window.DragonArt.svg(POSE[c], { fill: `var(${DV[c]})`, eyeFill: "var(--bg)", dark: c === "Black" })}</svg>` : "";
$("#odds-colours").innerHTML = cols.map(({ c, first, p, pAll, lo, hi }) => { $("#odds-colours").innerHTML = cols.map(({ c, first, p, pAll, lo, hi }) => {
const e = enc(c); const e = enc(c);
// The Black rests on one roll no complete log has measured (the shadow on a first attempt): a range, not a figure
if (first) return `<a class="odd odd-colour odd-low" href="#valley/${c.toLowerCase()}" style="--c: var(${DV[c]})">${art(c)}
<span class="pill warn">Low evidence</span>
<span class="big">about 1 in ${oneIn(p)}</span><span class="what">first attempts end bonded to a Black, on the best route</span>
${dots(Math.round(p * 1000), 1000, cssVar(DV[c]))}
<span class="how">Somewhere between <b>1 in ${oneIn(hi)}</b> and <b>1 in ${oneIn(lo)}</b> (95%). Later attempts: no shadow has ever been logged, so effectively never.${Math.abs(pAll - p) / p > 0.25 ? ` All form posts suggest about 1 in ${oneIn(pAll)}.` : ""} Every logged shadow comes from riders who chose to post their run, so this rests on an assumption until complete first-attempt logs exist. <span id="black-steps"></span></span>
<span class="go">See the route →</span></a>`;
return `<a class="odd odd-colour" href="#valley/${c.toLowerCase()}" style="--c: var(${DV[c]})">${art(c)} return `<a class="odd odd-colour" href="#valley/${c.toLowerCase()}" style="--c: var(${DV[c]})">${art(c)}
<span class="big">${p >= 0.5 ? pct(p) : `1 in ${oneIn(p)}`}</span><span class="what">${p >= 0.5 ? "of runs" : "runs"} end bonded to ${/^[AEIOU]/.test(c) ? "an" : "a"} ${c}, on the best route${first ? ", on your first attempt" : ""}</span> <span class="big">${p >= 0.5 ? pct(p) : `1 in ${oneIn(p)}`}</span><span class="what">${p >= 0.5 ? "of runs" : "runs"} end bonded to ${/^[AEIOU]/.test(c) ? "an" : "a"} ${c}, on the best route${first ? ", on your first attempt" : ""}</span>
${dots(Math.round(p * 1000), 1000, cssVar(DV[c]))} ${dots(Math.round(p * 1000), 1000, cssVar(DV[c]))}
+1 -1
View File
@@ -27,7 +27,7 @@ for (const f of fs.readdirSync(path.join(root, "site/atlas"))) copy(`site/atlas/
copy("core/graph.js", "graph.js"); copy("core/graph.js", "graph.js");
copy("core/solver.js", "solver.js"); copy("core/solver.js", "solver.js");
// The numbers the page shows (all computed in Python) and the published data // 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", "black.json", "tree.json", "experiments.json", "pdf_encounters.json", "overlap.json"]) copy(`data/public/${f}`, `data/${f}`); for (const f of ["stats.json", "register.json", "graph.json", "policy.json", "black.json", "tree.json", "experiments.json"]) copy(`data/public/${f}`, `data/${f}`);
copy("data/public/runs_clean.csv", "data/runs_clean.csv"); copy("data/public/runs_clean.csv", "data/runs_clean.csv");
for (const f of ["croissant.json", "dictionary.yaml"]) copy(`data/${f}`, `data/${f}`); for (const f of ["croissant.json", "dictionary.yaml"]) copy(`data/${f}`, `data/${f}`);
// Source files shown in the page's "view the code" panel // Source files shown in the page's "view the code" panel
+2 -82
View File
@@ -278,7 +278,7 @@ class RedditComments(unittest.TestCase):
"answers": {"company": "Alone", "outcome": "Incinerated at a bonding encounter", "outcome_color": "Red"}}]}), "answers": {"company": "Alone", "outcome": "Incinerated at a bonding encounter", "outcome_color": "Red"}}]}),
encoding="utf-8") encoding="utf-8")
manual = TMP / "reddit_comments_manual.yaml" manual = TMP / "reddit_comments_manual.yaml"
manual.write_text("reject: [c2]\nfix: {c1: {outcome_color: Blue, branch: 'Valley: passed the Red, the meadow', direction: null}}\n" manual.write_text("reject: [c2]\nfix: {c1: {outcome_color: Blue, direction: null}}\n"
"add: [{id: c9, thread: abc, posted: '2026-11-16', " "add: [{id: c9, thread: abc, posted: '2026-11-16', "
"answers: {company: Two squadmates, direction: West (toward the scent), outcome: Died before the hour}}]\n", "answers: {company: Two squadmates, direction: West (toward the scent), outcome: Died before the hour}}]\n",
encoding="utf-8") encoding="utf-8")
@@ -286,92 +286,12 @@ class RedditComments(unittest.TestCase):
self.assertEqual([r["run_id"] for r in rows], ["comment-c1", "comment-c3", "comment-c9"]) self.assertEqual([r["run_id"] for r in rows], ["comment-c1", "comment-c3", "comment-c9"])
c1, c3, c9 = rows c1, c3, c9 = rows
self.assertEqual((c1["source"], c1["outcome_color"], c1["direction"], c1["hour"], c1["enc_Blue"]), self.assertEqual((c1["source"], c1["outcome_color"], c1["direction"], c1["hour"], c1["enc_Blue"]),
("reddit comment", "Blue", "Unknown", "Valley", "Bonded!")) ("reddit comment", "Blue", "Unknown", "Tree", "Bonded!"))
self.assertEqual(c1["data_flags"], "read from a Reddit comment") 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(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((c9["company"], c9["direction"], c9["hour"]), ("2 Squadmates", "West", "DIED before the hour"))
self.assertEqual(validate.problems(rows, runs.DICT), []) 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"),
"Black recorded on a Valley run":
dict(hour="Went to the valley centre", outcome="Bonded", outcome_color="Black"),
"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"])
def test_review_summary_and_overlap(self):
sys.path.insert(0, str(ROOT / "core"))
from collection.etl import review_reddit
ov = review_reddit._overlap()
base = {"runs": [{"id": "a1", "thread": "t", "answers": {"outcome": "Bonded"}}]}
head = {"runs": [{"id": "a1", "thread": "t", "answers": {"outcome": "Incinerated at a bonding encounter"}},
{"id": "b2", "thread": "t", "answers": {}}, {"id": "c3", "thread": "t", "answers": {}, "result": "THRESH-X1"}]}
self.assertEqual(review_reddit.diff(base, head), (["b2", "c3"], ["a1"], []))
route = dict(company="Alone", direction="East", scream="Ignore the scream", hour="Tree", outcome="Bonded",
outcome_color="Red", date="2026-10-05")
runs = [{"run_id": "comment-b2", "source": "reddit comment", "data_flags": "read from a Reddit comment; "
"Black recorded on a Valley run (the Black is only reached from the tree)", **{k: None for k in ov.FIELDS}, "date": None},
{"run_id": "comment-c3", "source": "reddit comment", "data_flags": "", **{k: None for k in ov.FIELDS}, **route},
{"run_id": "sheet-1", "source": "reddit spreadsheet", "data_flags": "", **{k: None for k in ov.FIELDS}, **route}]
m = ov.measure(runs)
self.assertEqual((m["comparable"], m["matched"]), (1, 1))
self.assertEqual(m["matches"], [{"comment": "comment-c3", "form": ["sheet-1"]}])
text = review_reddit.summary(base, head, runs, {"THRESH-X1"}, m)
self.assertIn("**2 new**, 1 changed", text)
self.assertIn("Black recorded on a Valley run", text)
self.assertIn("sheet-1", text)
self.assertIn("THRESH-X1", text)
self.assertTrue(text.startswith(review_reddit.MARKER))
def test_fingerprint_ids_are_stable(self):
a = {"Timestamp": "2026-10-04 11:49:07", "Q1": "Alone", "Q2": None}
b = {"Timestamp": "2026-10-04 11:50:00", "Q1": "West"}
dup = {"Timestamp": "Data Import", "Q1": "Alone"}
ids = runs.fingerprints([a, b, dup, dict(dup)], "sheet")
self.assertEqual(len(set(ids)), 4)
self.assertTrue(all(i.startswith("sheet-") for i in ids))
self.assertTrue(ids[3].endswith("-2") and ids[3].startswith(ids[2])) # an exact copy gets -2
self.assertEqual(runs.fingerprints([b, a], "sheet"), [ids[1], ids[0]]) # re-sorting moves no id
self.assertEqual(runs.fingerprints([b], "sheet"), [ids[1]]) # deleting a row moves no other id
self.assertEqual(runs.fingerprints([{**a, "Q9": ""}], "sheet"), [ids[0]]) # a new, empty column changes none
self.assertNotEqual(runs.fingerprints([{**a, "Q1": "West"}], "sheet"), [ids[0]]) # an edited row is new
def test_delivered_not_extracted(self): def test_delivered_not_extracted(self):
spec = read_yaml("collection/pipeline.yaml")["sources"]["reddit_comments"] spec = read_yaml("collection/pipeline.yaml")["sources"]["reddit_comments"]
with self.assertRaises(extract.Skip): with self.assertRaises(extract.Skip):
-32
View File
@@ -1,32 +0,0 @@
// knownAnswer (core/solver.js) against the published data/public/known_answers.json: the guide's recommended answers
// are found on the game's full texts, wrong colours and deadly answers are not picked, and unknown screens stay open.
const test = require("node:test");
const assert = require("node:assert/strict");
const path = require("node:path");
const S = require("../../core/solver.js");
const known = require(path.join(__dirname, "../../data/public/known_answers.json"));
test("the Black: 'Hold its gaze' is the strong pick, 'Lower your eyes' is bad", () => {
const r = S.knownAnswer(known, ["Lower your eyes", "Hold its gaze"], { target: "black", sceneColour: "Black" });
assert.equal(r.pick, 1);
assert.equal(r.confidence, "strong");
assert.equal(r.choices[0].verdict, "bad");
});
test("a guide paraphrase matches the game's full text", () => {
const r = S.knownAnswer(known, ["Climb onto its foreleg", "Reach a hand slowly to touch its talon"], { target: "Red", sceneColour: "Red" });
assert.equal(r.pick, 1);
assert.match(r.reason, /Touch its talon/);
});
test("the two Greens: the answer for the right Green is not the pick for a Brown target", () => {
const offered = ["You respect their nature", "You don't know", "Intellect match"];
assert.equal(S.knownAnswer(known, offered, { target: "Green" }).pick, 0);
assert.equal(S.knownAnswer(known, offered, { target: "Brown" }).pick, 2);
});
test("a screen nobody has seen: no pick, every choice unknown", () => {
const r = S.knownAnswer(known, ["Whistle a tune", "Count the clouds"], { target: "Blue" });
assert.equal(r.pick, null);
assert.deepEqual(r.choices.map((c) => c.verdict), ["unknown", "unknown"]);
});
-127
View File
@@ -1,127 +0,0 @@
"""The page's statistics (analysis/stats/site_stats.py): the conditions of measures.yaml, how runs are grouped by
where they came from, the presets, deliberate deaths, and the invariants of stats.json on a sample of the real runs."""
import random
import sys
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / "analysis/stats"))
sys.path.insert(0, str(ROOT / "core"))
import site_stats as SS # noqa: E402
from atlas import runs as runs_io # noqa: E402
DEATHS = ("Incinerated", "Died before the hour")
def sample(per_source=300, seed=7):
"""A fixed sample of the published runs, every statistics source represented, impossible runs left out."""
rng = random.Random(seed)
runs = [r for r in runs_io.read(drop=()) if not runs_io.impossible(r)]
out = []
for s in sorted({r["source"] for r in runs}):
rs = [r for r in runs if r["source"] == s]
out += rng.sample(rs, min(per_source, len(rs)))
return out
class Conditions(unittest.TestCase):
def test_match(self):
r = {"hour": "Tree", "branch": "Shadow (rare)", "outcome": "Bonded", "_deliberate": False}
self.assertTrue(SS.match(r, {"hour": "Tree"}))
self.assertTrue(SS.match(r, {"hour": {"in": ["Tree", "Valley"]}, "branch": {"exists": True}}))
self.assertFalse(SS.match(r, {"hour": {"not": "Tree"}}))
self.assertTrue(SS.match(r, {"any": [{"hour": "Valley"}, {"outcome": "Bonded"}]}))
self.assertFalse(SS.match({**r, "branch": None}, {"branch": {"exists": True}}))
# deliberate deaths: `{not: true}` keeps runs that were never marked (a test row, another caller)
self.assertTrue(SS.match(r, {"_deliberate": {"not": True}}))
self.assertTrue(SS.match({"hour": "Tree"}, {"_deliberate": {"not": True}}))
self.assertFalse(SS.match({**r, "_deliberate": True}, {"_deliberate": {"not": True}}))
def test_bond_pools_leave_out_deliberate_deaths(self):
for t, T in SS.TARGETS.items():
if t.startswith("bond_"):
self.assertEqual(T["pool"].get("_deliberate"), {"not": True}, t)
self.assertEqual(SS.OUTCOMES["bonded_Red"]["denom"].get("_deliberate"), {"not": True})
class Sources(unittest.TestCase):
def test_groups_and_presets(self):
form = {"source": "reddit spreadsheet", "entry": "Form", "goal": "Red", "data_flags": ""}
bulk = {"source": "reddit spreadsheet", "entry": "Data Import", "goal": "Red", "data_flags": ""}
bot = {"source": "bot", "entry": None, "goal": "Black", "data_flags": ""}
com = {"source": "reddit comment", "entry": None, "goal": None, "data_flags": "read from a Reddit comment"}
self.assertEqual([SS.entry_group(r) for r in (form, bulk, bot, com)],
["Form", "Data Import", "DragonKind bot", "Reddit comments"])
self.assertEqual([SS.stratum(r) for r in (bulk, bot, com)], ["Bulk logs (imports)", "DragonKind bot", "Reddit comments"])
runs = [form, bulk, bot, com]
f = lambda **kw: SS.apply_filters(runs, {"source": "all", "goal": "all", "excludeFlagged": False, **kw}) # noqa: E731
self.assertEqual(f(source="form"), [form])
self.assertEqual(f(source="bulk"), [bulk]) # the bot and Reddit are not bulk logs
self.assertEqual(f(source="bot"), [bot])
self.assertEqual(f(source="reddit"), [com])
self.assertEqual(f(goal="only_rare"), [bot])
self.assertEqual(f(excludeFlagged=True), [form, bulk, bot])
class Build(unittest.TestCase):
@classmethod
def setUpClass(cls):
every = sample()
runs = [r for r in every if r["source"] in SS.M["sources"]]
for r in runs:
r["_deliberate"] = SS.deliberate(r)
cls.runs, cls.every = runs, every
cls.out = SS.build(runs, len(runs), None, every_run=every)
def test_presets(self):
self.assertEqual(set(self.out["presets"]), set(SS.M["presets"]))
for pid, p in self.out["presets"].items():
self.assertEqual(set(p), {"label", "analyse", "routes", "map", "valley", "overview"}, pid)
self.assertEqual(set(self.out["presets"]["bot"]["analyse"]["meta"]["sources"]), {"DragonKind bot"})
self.assertEqual(set(self.out["presets"]["reddit"]["analyse"]["meta"]["sources"]), {"Reddit comments"})
def test_overview_counts(self):
o = self.out["presets"]["all"]["overview"]
ended = [r for r in self.runs if r["outcome"] in ("Bonded",) + DEATHS]
self.assertEqual(o["cadets"] + o["deliberate"], len(ended))
self.assertEqual(o["deliberate"], sum(1 for r in ended if r["_deliberate"]))
self.assertEqual(o["bonded"] + o["dead"], o["cadets"])
def test_map_bond_denominators_skip_deliberate_deaths(self):
m = self.out["presets"]["all"]["map"]
for i, nd in enumerate(m["nodes"]):
for t, bt in m["by_target"].items():
n = bt["nodes"][i]["n"]
if t.startswith("bond_"):
self.assertLessEqual(n, nd["n"])
else:
self.assertEqual(n, nd["n"], t)
# somewhere in the sample a deliberate death reached the map, so some bond denominator is smaller
self.assertTrue(any(bt["nodes"][i]["n"] < nd["n"] for t, bt in m["by_target"].items() if t.startswith("bond_")
for i, nd in enumerate(m["nodes"])))
def test_encounters_leave_out_deliberate_deaths(self):
for e, spec in zip(self.out["presets"]["all"]["analyse"]["encounters"], SS.M["encounters"]):
col = spec["column"]
n = sum(1 for r in self.runs if SS.match(r, spec["where"]) and r.get(col) in ("Bonded!", "Incinerated")
and not r["_deliberate"])
self.assertEqual(e["overall"]["n"], n, e["context"])
def test_paths(self):
p = self.out["paths"]
self.assertEqual([lay["key"] for lay in p["layers"]], [lay["key"] for lay in SS.M["path_layers"]])
for lay in p["layers"]:
self.assertEqual(sum(lay["counts"].values()), lay["runs"], lay["key"])
self.assertEqual(set(lay["lines"]), {"lived", "chose", "failed"})
bot = next(lay for lay in p["layers"] if lay["key"] == "bot")
self.assertGreater(bot["counts"]["chose"], 0) # the bot burns on purpose: drawn as chosen deaths
self.assertEqual(set(p["unrouted"]), set(SS.M.get("path_unrouted", [])))
def test_json_safe(self):
import json
json.dumps(self.out, allow_nan=False) # the page cannot parse NaN or Infinity
if __name__ == "__main__":
unittest.main()