Compare commits
25
Commits
0df6b8d473
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ec176a864 | ||
|
|
d9f3c200b8 | ||
|
|
778e844752 | ||
|
|
b61546a53a | ||
|
|
661730d7fe | ||
|
|
b9d692a91c | ||
|
|
bbea5db2ee | ||
|
|
87217037bb | ||
|
|
6b4b1344be | ||
|
|
6ba87691d6 | ||
|
|
77ce54acec | ||
|
|
44ccd7f760 | ||
|
|
6510bfbd06 | ||
|
|
77f146393d | ||
|
|
a1966bfa2c | ||
|
|
6d52a2548e | ||
|
|
ee222dd775 | ||
|
|
fbf42508a0 | ||
|
|
1dfa8fb4c3 | ||
|
|
ca411e8315 | ||
|
|
b51a6c7039 | ||
|
|
d7befc8e18 | ||
|
|
98be27fc1f | ||
|
|
cd618d37d3 | ||
|
|
0ae29b5423 |
@@ -0,0 +1,7 @@
|
||||
.git
|
||||
.gitea
|
||||
.github
|
||||
dist
|
||||
node_modules
|
||||
**/__pycache__
|
||||
tests
|
||||
@@ -0,0 +1,30 @@
|
||||
# The published Atlas page. Every push to main (every merged pull request, and the data bot's daily commits) builds
|
||||
# the site into a container image and pushes it to Harbor. Argo CD Image Updater watches the `latest` digest and
|
||||
# rolls the deployment in kubefiles (web/threshing-atlas), serving https://threshingatlas.kenschiano.net.
|
||||
#
|
||||
# Secrets: HARBOR_USERNAME and HARBOR_PASSWORD, a Harbor robot account with push access to the `home` project.
|
||||
name: Publish the site (container image)
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
concurrency:
|
||||
group: image
|
||||
cancel-in-progress: true
|
||||
env:
|
||||
IMAGE: harbor.kenschiano.net/home/threshing-atlas
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build and push
|
||||
env:
|
||||
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
|
||||
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
|
||||
run: |
|
||||
echo "$HARBOR_PASSWORD" | docker login harbor.kenschiano.net -u "$HARBOR_USERNAME" --password-stdin
|
||||
docker build -t "$IMAGE:latest" -t "$IMAGE:${GITHUB_SHA::8}" .
|
||||
docker push "$IMAGE:latest"
|
||||
docker push "$IMAGE:${GITHUB_SHA::8}"
|
||||
echo "pushed $IMAGE:latest (${GITHUB_SHA::8})"
|
||||
@@ -1,7 +1,9 @@
|
||||
# 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
|
||||
# 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
|
||||
# solver that reads it never get out of step. Ken reviews and merges it; the running bot reloads the files after a pull.
|
||||
# DragonKind/DragonKind, that replaces vendor/threshing-atlas/{policy.json,solver.js,graph.js,known_answers.json,
|
||||
# experiments.json,tree.json} with this repo's data/public/policy.json, core/solver.js, core/graph.js,
|
||||
# data/public/known_answers.json, data/public/experiments.json and data/public/tree.json. They always travel together, so
|
||||
# the policy, the experiment plan and the solver that reads them never get out of step (docs/BOT_INTEGRATION.md).
|
||||
# tests/core/bot_contract.test.js runs the bot's own call chain against them in CI. 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).
|
||||
name: Send the route model to the bot
|
||||
@@ -13,6 +15,8 @@ on:
|
||||
- core/solver.js
|
||||
- core/graph.js
|
||||
- data/public/known_answers.json
|
||||
- data/public/experiments.json
|
||||
- data/public/tree.json
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
send:
|
||||
@@ -35,7 +39,8 @@ jobs:
|
||||
GIT_CONFIG_VALUE_0="AUTHORIZATION: token $ATLAS_BOT_TOKEN"
|
||||
git clone --quiet --depth 1 https://git.kenschiano.net/DragonKind/DragonKind.git "$dst"
|
||||
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 data/public/known_answers.json \
|
||||
data/public/experiments.json data/public/tree.json "$dst/vendor/threshing-atlas/"
|
||||
id=$(python3 -c "import json; print(json.load(open('data/public/policy.json')).get('id', ''))")
|
||||
sha=$(git rev-parse --short HEAD)
|
||||
cd "$dst"
|
||||
@@ -52,7 +57,7 @@ jobs:
|
||||
printf '%s\n' \
|
||||
"The Threshing Atlas route model changed (policy \`$id\`, atlas commit \`$sha\`)." \
|
||||
"" \
|
||||
"This replaces \`vendor/threshing-atlas/\` (policy.json, solver.js, graph.js) together, as \`npm run atlas:sync\` would." \
|
||||
"This replaces \`vendor/threshing-atlas/\` (policy.json, solver.js, graph.js, known_answers.json, experiments.json, tree.json) together, as \`npm run atlas:sync\` would." \
|
||||
"This pull request is updated in place each time the model changes. After merging, pull on the bot's machine:" \
|
||||
"the running bot reloads the files on its next decision." \
|
||||
"" \
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# 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 }}"
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
# The published Atlas page as a container, on Red Hat's hardened images: build the static site with Node, check
|
||||
# the nginx config with the nginx builder (it has a shell), then serve with the distroless nginx runtime (no shell
|
||||
# or package manager, UID 65532, port 8080). .gitea/workflows/image.yml builds this on every push to main and
|
||||
# pushes it to harbor.kenschiano.net/home/threshing-atlas:latest; Argo CD Image Updater rolls the deployment
|
||||
# (kubefiles, web/threshing-atlas) when that digest changes.
|
||||
ARG NODE_TAG=22
|
||||
ARG NGINX_TAG=latest
|
||||
|
||||
FROM registry.access.redhat.com/hi/nodejs:${NODE_TAG}-builder AS build
|
||||
# Only /site leaves this stage, so build as root
|
||||
USER root
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
RUN node site/build.js /site
|
||||
|
||||
# Fail the build on a bad config, since the runtime image can't run `nginx -t` for us
|
||||
FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG}-builder AS nginx-check
|
||||
COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
RUN nginx -t -e /dev/stderr
|
||||
|
||||
FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG}
|
||||
COPY --from=nginx-check /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=build /site /usr/share/nginx/html
|
||||
EXPOSE 8080
|
||||
@@ -35,9 +35,17 @@ def group(r):
|
||||
return "bot"
|
||||
if r["source"] == "reddit spreadsheet":
|
||||
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"
|
||||
|
||||
|
||||
GROUP_NAMES = {"form": "Form submissions", "bulk logs": "Bulk logs", "bot": "Bot", "Reddit comments": "Reddit comments",
|
||||
"reported": "Reported on the Atlas"}
|
||||
|
||||
|
||||
def tally(rows, key):
|
||||
d = collections.OrderedDict()
|
||||
for r in rows:
|
||||
@@ -110,17 +118,20 @@ def build():
|
||||
"another) are still fair if the over-reporting is the same on both sides.", ""]
|
||||
|
||||
# 1. by attempt
|
||||
L += ["## 1. The shadow by attempt number", "", "| Attempt | Form submissions | Bulk logs | Bot |", "|---|---|---|---|"]
|
||||
# the self-reported sources (Reddit comments, "Report a run") get a column once they have a gated tree run
|
||||
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)]
|
||||
for name, lo, hi in bands:
|
||||
cells = []
|
||||
for g in ("form", "bulk logs", "bot"):
|
||||
for g in groups:
|
||||
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)))
|
||||
facts["by_attempt"].setdefault(g, {})[name] = [sum(bool(r["saw_shadow"]) for r in rs), len(rs)]
|
||||
L.append(f"| {name} | " + " | ".join(cells) + " |")
|
||||
cells = []
|
||||
for g in ("form", "bulk logs", "bot"):
|
||||
for g in groups:
|
||||
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)))
|
||||
L.append("| not given | " + " | ".join(cells) + " |")
|
||||
@@ -130,6 +141,14 @@ def build():
|
||||
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_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
|
||||
F = [r for r in G if group(r) == "form" and r["attempt"]]
|
||||
@@ -141,7 +160,8 @@ def build():
|
||||
c[i + 1] += 1
|
||||
orr, obs, exp, z = mantel_haenszel(by.values())
|
||||
facts["same_route"] = {"routes": len(by), "first_shadows": round(obs), "expected": round(exp, 1),
|
||||
"odds_ratio": round(orr, 1), "z": round(z, 1)}
|
||||
"odds_ratio": round(orr, 1) if math.isfinite(orr) else None, # JSON has no Infinity
|
||||
"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_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", "",
|
||||
@@ -153,7 +173,7 @@ def build():
|
||||
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: "
|
||||
f"{obs:.0f} first-attempt shadows where {exp:.1f} would be expected if the attempt did not matter "
|
||||
f"(odds ratio {orr:.1f}, z = {z:.1f}). First and later attempts choose almost the same routes, so the "
|
||||
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 "
|
||||
"difference is not in the recorded choices: it is something about the account, or a choice the form does "
|
||||
"not record.", ""]
|
||||
|
||||
@@ -266,7 +286,7 @@ def main(argv=None):
|
||||
ap.add_argument("--check", action="store_true")
|
||||
a = ap.parse_args(argv)
|
||||
text, facts = build()
|
||||
data = json.dumps(facts, ensure_ascii=False, indent=1) + "\n"
|
||||
data = json.dumps(facts, ensure_ascii=False, indent=1, allow_nan=False) + "\n"
|
||||
if a.check:
|
||||
for path, want in ((OUT, text), (OUT_JSON, data)):
|
||||
if not path.exists() or path.read_text(encoding="utf-8") != want:
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
"""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())
|
||||
+27
-25
@@ -4,17 +4,19 @@ Written by `analysis/black/evidence.py` from `data/public/runs_clean.csv`. Count
|
||||
|
||||
## 1. The shadow by attempt number
|
||||
|
||||
| Attempt | Form submissions | Bulk logs | Bot |
|
||||
|---|---|---|---|
|
||||
| 1 | 97 / 960 (10.1%) | 0 / 29 (0.0%) | 0 / 0 |
|
||||
| 2 | 0 / 299 (0.0%) | 0 / 21 (0.0%) | 0 / 4 (0.0%) |
|
||||
| 3 | 0 / 196 (0.0%) | 0 / 14 (0.0%) | 0 / 5 (0.0%) |
|
||||
| 4-10 | 0 / 555 (0.0%) | 0 / 102 (0.0%) | 0 / 36 (0.0%) |
|
||||
| 11-30 | 0 / 657 (0.0%) | 0 / 57 (0.0%) | 0 / 137 (0.0%) |
|
||||
| 31 or more | 0 / 715 (0.0%) | 0 / 0 | 0 / 333 (0.0%) |
|
||||
| not given | 0 / 1582 (0.0%) | 0 / 149 (0.0%) | 0 / 0 |
|
||||
| Attempt | Form submissions | Bulk logs | Bot | Reddit comments |
|
||||
|---|---|---|---|---|
|
||||
| 1 | 97 / 973 (10.0%) | 0 / 29 (0.0%) | 0 / 0 | 1 / 1 (100.0%) |
|
||||
| 2 | 0 / 301 (0.0%) | 0 / 21 (0.0%) | 0 / 4 (0.0%) | 0 / 0 |
|
||||
| 3 | 0 / 198 (0.0%) | 0 / 14 (0.0%) | 0 / 5 (0.0%) | 0 / 0 |
|
||||
| 4-10 | 0 / 574 (0.0%) | 0 / 102 (0.0%) | 0 / 36 (0.0%) | 0 / 0 |
|
||||
| 11-30 | 0 / 706 (0.0%) | 0 / 58 (0.0%) | 0 / 137 (0.0%) | 0 / 0 |
|
||||
| 31 or more | 1 / 847 (0.1%) | 0 / 57 (0.0%) | 0 / 333 (0.0%) | 0 / 0 |
|
||||
| not given | 1 / 1594 (0.1%) | 0 / 149 (0.0%) | 0 / 0 | 2 / 3 (66.7%) |
|
||||
|
||||
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 767 later ones, with 0 shadows. Zero in 767 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
|
||||
|
||||
@@ -22,16 +24,16 @@ If the shadow depended only on the choices the form records (company, first dire
|
||||
|
||||
| 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 / Forest | 5 / 29 (17.2%) | 0 / 96 (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%) |
|
||||
| 2 Squadmates / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 2 / 45 (4.4%) | 0 / 50 (0.0%) |
|
||||
| Alone / West / Assess the situation / Engage the smaller cadet / Squadmate's revenge / West | 23 / 114 (20.2%) | 0 / 113 (0.0%) |
|
||||
| Alone / West / Assess the situation / Engage the smaller cadet / Squadmate's revenge / Forest | 5 / 29 (17.2%) | 0 / 99 (0.0%) |
|
||||
| Alone / Center / Assess the situation / Engage the smaller cadet / Squadmate's revenge / Forest | 4 / 29 (13.8%) | 0 / 83 (0.0%) |
|
||||
| 1 Squadmate / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 2 / 32 (6.2%) | 0 / 78 (0.0%) |
|
||||
| 2 Squadmates / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 2 / 45 (4.4%) | 0 / 53 (0.0%) |
|
||||
| Alone / East / Assess the situation / Engage the smaller cadet / Squadmate's revenge / East | 1 / 34 (2.9%) | 0 / 60 (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 / 65 (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 inf, 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 334 recorded routes, comparing first and later attempts on the same route: 93 first-attempt shadows where 38.0 would be expected if the attempt did not matter (odds ratio 111.1, z = 12.7). 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?
|
||||
|
||||
@@ -47,14 +49,14 @@ The developer says the Black is decided by choices and by what the site knows ab
|
||||
|
||||
## 4. There is no single route
|
||||
|
||||
The 97 form runs with a shadow (all attempts) took 47 different recorded routes:
|
||||
The 99 form runs with a shadow (all attempts) took 48 different recorded routes:
|
||||
|
||||
- **Company:** Alone 71, 1 Squadmate 14, 2 Squadmates 12
|
||||
- **First direction:** West 61, Center 20, East 16
|
||||
- **First move in the fight:** Assess the situation 86, (not recorded) 9, Even the numbers (smaller cadet) 2
|
||||
- **The dagger:** Engage the smaller cadet 63, (not recorded) 22, Daggers or not (protect squadmate) 12
|
||||
- **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
|
||||
- **Company:** Alone 71, 1 Squadmate 14, 2 Squadmates 14
|
||||
- **First direction:** West 62, Center 21, East 16
|
||||
- **First move in the fight:** Assess the situation 88, (not recorded) 9, Even the numbers (smaller cadet) 2
|
||||
- **The dagger:** Engage the smaller cadet 63, (not recorded) 22, Daggers or not (protect squadmate) 14
|
||||
- **The bullies' fate:** Squadmate's revenge 63, Left bullies to the dragons 25, Killed the bullies yourself 9, Unknown 2
|
||||
- **The fork:** West 47, Forest 37, 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.
|
||||
|
||||
@@ -62,7 +64,7 @@ Shadows reported with an answer that contradicts a gate: 3 (likely mis-entered o
|
||||
|
||||
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: 91, bonded 67.
|
||||
- Runs that died at the Blue: 19. 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.
|
||||
|
||||
|
||||
@@ -41,6 +41,25 @@ 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
|
||||
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
|
||||
|
||||
`data/raw/` is git-ignored and never published. It holds the current raw file of each source and the one before
|
||||
|
||||
@@ -131,6 +131,18 @@ def open_issue(title, body, env=None, f=None):
|
||||
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):
|
||||
f = f or config()
|
||||
tok = token(env)
|
||||
|
||||
@@ -88,6 +88,7 @@ def rebuild():
|
||||
_step("what the runs show about the Black", [py, "analysis/black/evidence.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:
|
||||
import scipy # noqa: F401
|
||||
_step("statistics", [py, "analysis/stats/site_stats.py"])
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
"""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
|
||||
+26
-5
@@ -4,7 +4,9 @@ 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
|
||||
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 hashlib
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
@@ -51,19 +53,37 @@ def encounter_columns(row, intentional=False):
|
||||
|
||||
# ---------------------------------------------------------------- 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):
|
||||
"""The community form: core/spec/form.yaml + core/atlas/coding.py, plus the game-rule checks every source that
|
||||
answers the form's questions gets (rule_flags; a flag the coder already set is not repeated)."""
|
||||
from atlas import coding
|
||||
df, missing = coding.code_frame(coding.read_export(path(spec["load"])))
|
||||
raw = coding.read_export(path(spec["load"]))
|
||||
df, missing = coding.code_frame(raw)
|
||||
if 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")
|
||||
rows = []
|
||||
for rec in df.astype(object).where(df.notna(), None).to_dict("records"):
|
||||
n = rec.pop("run_id")
|
||||
for i, rec in enumerate(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
|
||||
entry = rec.pop("source")
|
||||
row = {**{c: None for c in COLUMNS}, **rec, "run_id": f"sheet-{n}", "source": spec["run_source"], "entry": entry}
|
||||
row = {**{c: None for c in COLUMNS}, **rec, "run_id": ids[i], "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)
|
||||
@@ -99,6 +119,7 @@ def register(name, spec):
|
||||
"colour": ("colour",), "tail": ("tail",)}.items()}
|
||||
values = {c: DICT["columns"][c].get("values") or [] for c in ("wing", "section", "squad", "outcome_color", "tail")}
|
||||
rows = []
|
||||
ids = fingerprints(data["rows"], "register")
|
||||
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
|
||||
flags = ["outcome only (register): the same run may also be in the spreadsheet"]
|
||||
@@ -107,7 +128,7 @@ def register(name, spec):
|
||||
flags.append("colour not recognised")
|
||||
colour = None
|
||||
tail = (get("tail") or "").replace(" ", "").capitalize() or None
|
||||
row = blank_row(run_id=f"register-{n}", source=spec["run_source"], date=(get("when") or "")[:10] or None,
|
||||
row = blank_row(run_id=ids[n - 1], 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)
|
||||
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
|
||||
|
||||
@@ -132,6 +132,10 @@ def main(argv=None):
|
||||
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("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.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)")
|
||||
@@ -155,6 +159,9 @@ def main(argv=None):
|
||||
if a.cmd == "rebuild":
|
||||
from .etl.handoff import 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":
|
||||
from .etl.send_pdf import send
|
||||
return send()
|
||||
|
||||
+26
-7
@@ -236,14 +236,30 @@
|
||||
if (!worlds) worlds = Array.from({ length: draws }, (_, i) => solveWith(rng(seed * 7919 + i + 1)).sol.choices);
|
||||
return worlds.filter((c) => c.get(key) === choice).length / draws;
|
||||
};
|
||||
// What the game allows, whatever the data say: the same game solved with no runs at all, so every roll can come
|
||||
// out every way except through a closed gate (game.yaml `requires`), and an encounter bonds only its own colour
|
||||
// (and any colour seen there). An option after which X cannot happen at all is never advised while another option
|
||||
// keeps X possible, however small the data make every option's odds. Without this, when the data put X near zero
|
||||
// on every route (the Black on a later attempt), every option ties and a tie-breaking rider or bot may walk away
|
||||
// from the squadmate or go to the valley: the Black needs the gates and the tree (game.yaml, the community PDF and
|
||||
// the developer).
|
||||
const emptyTables = { encounter: {}, ...Object.fromEntries(Object.keys(game.chance).map((k) => [k, {}])) };
|
||||
const reach = solve(makeParams(emptyTables, { game, given: known }), game, support, X, 0, only).optVals;
|
||||
const possibleAt = (key, vals) => Object.keys(vals).filter((o) => vals[o].x > 0 || (((reach.get(key) || {})[o]) || ZERO).x > 0);
|
||||
/** The choice at a history among the options that keep X possible (if any does), and the options ruled out. */
|
||||
const advisedAt = (key) => {
|
||||
let vals = sol.optVals.get(key) || {}, choice = sol.choices.get(key);
|
||||
const can = possibleAt(key, vals), ruledOut = Object.keys(vals).filter((o) => !can.includes(o));
|
||||
if (can.length && ruledOut.length && !can.includes(choice)) choice = can.reduce((b, o) => (vals[o].x > vals[b].x ? o : b), can[0]);
|
||||
return { vals, choice, ruledOut: can.length ? ruledOut : [] };
|
||||
};
|
||||
const VARS = new Set([...Object.keys(game.decisions), ...Object.keys(game.chance), "encounter"]);
|
||||
const fmt = (v) => ({ pX: v.x, pOther: v.o, pReach: v.r });
|
||||
const label = (k) => (game.decisions[k] || game.chance[k]).label;
|
||||
const decisionAt = (name, key, extra) => {
|
||||
const vals = sol.optVals.get(key) || {};
|
||||
const choice = sol.choices.get(key);
|
||||
const { vals, choice, ruledOut } = advisedAt(key);
|
||||
return { kind: "decision", var: name, label: label(name), choice, propensity: propensityAt(key, choice),
|
||||
options: Object.fromEntries(Object.entries(vals).map(([o, v]) => [o, fmt(v)])), ...extra };
|
||||
options: Object.fromEntries(Object.entries(vals).map(([o, v]) => [o, fmt(v)])), ...(ruledOut.length ? { ruledOut } : {}), ...extra };
|
||||
};
|
||||
|
||||
/** The next thing that happens after history h: a decision, a roll, or the end of the run. */
|
||||
@@ -257,7 +273,7 @@
|
||||
if (st.decision) {
|
||||
const name = st.decision, key = name + "@" + canon(state);
|
||||
if (h[name] != null) { value = h[name]; used.add(name); }
|
||||
else if (later()) value = sol.choices.get(key);
|
||||
else if (later()) value = advisedAt(key).choice;
|
||||
else return decisionAt(name, key, risk ? { risk } : {});
|
||||
risk = null;
|
||||
} else {
|
||||
@@ -286,7 +302,7 @@
|
||||
/** the next decision only (null when the next step is a roll or the run is over) */
|
||||
next(h) {
|
||||
const s = step(h);
|
||||
return s.kind === "decision" ? { decision: s.var, label: s.label, choice: s.choice, propensity: s.propensity, options: s.options } : null;
|
||||
return s.kind === "decision" ? { decision: s.var, label: s.label, choice: s.choice, propensity: s.propensity, options: s.options, ...(s.ruledOut ? { ruledOut: s.ruledOut } : {}) } : null;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -322,10 +338,13 @@
|
||||
}
|
||||
const pat = pats[rec.choice];
|
||||
const idx = pat ? texts.findIndex((t) => new RegExp(pat).test(t)) : -1;
|
||||
const values = Object.values(rec.options).map((v) => v.pX).sort((a, b) => b - a);
|
||||
// options after which the target cannot happen at all are not offered to the bot (its tie rule picks among
|
||||
// `options`): see advisor's `ruledOut`
|
||||
const options = rec.ruledOut ? Object.fromEntries(Object.entries(rec.options).filter(([o]) => !rec.ruledOut.includes(o))) : rec.options;
|
||||
const values = Object.values(options).map((v) => v.pX).sort((a, b) => b - a);
|
||||
return { index: idx < 0 ? null : idx, decision: rec.decision, choice: rec.choice, propensity: rec.propensity,
|
||||
margin: values.length > 1 ? values[0] - values[1] : null,
|
||||
options: rec.options,
|
||||
options, ...(rec.ruledOut ? { ruledOut: rec.ruledOut } : {}),
|
||||
reason: idx < 0 && rec.decision !== "encounter" ? "the recommended choice is not on this screen; use the bot's own rules" : `${rec.label}: ${rec.choice}` };
|
||||
}
|
||||
|
||||
|
||||
+23
-13
@@ -46,7 +46,7 @@
|
||||
"conformsTo": "http://mlcommons.org/croissant/1.0",
|
||||
"name": "Threshing Atlas",
|
||||
"description": "Community-logged runs of the Dragonkind \"threshing\" (the dragon-bonding game based on Fourth Wing), coded into one record per run: every choice, what the game rolled, and how the run ended. Also the route model built from them, the statistics shown on the Threshing Atlas page, and the route graph shared with a DragonKind bot.",
|
||||
"url": "https://git.kenschiano.net/DragonKind/threshing-atlas",
|
||||
"url": "https://threshingatlas.kenschiano.net",
|
||||
"sameAs": "https://git.kenschiano.net/DragonKind/threshing-atlas",
|
||||
"license": "https://creativecommons.org/licenses/by/4.0/",
|
||||
"creator": {
|
||||
@@ -103,8 +103,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.",
|
||||
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/runs_clean.csv",
|
||||
"encodingFormat": "text/csv",
|
||||
"sha256": "b5e121cf5deab5f8bc1420b34a5bc434d6f933c7452e200eed4891c35de45122",
|
||||
"contentSize": "3748768 B"
|
||||
"sha256": "6938f1a62d1f855ab6abbceb305b9f9388945ec44ef53a16c21d3f3d0c740fbb",
|
||||
"contentSize": "3986165 B"
|
||||
},
|
||||
{
|
||||
"@type": "cr:FileObject",
|
||||
@@ -113,8 +113,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.",
|
||||
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/form_responses.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "8067ac944db2833e6a1203dc6464ed208d60dea4e617ee9b28fc56f285445d2e",
|
||||
"contentSize": "12786245 B"
|
||||
"sha256": "d5b235f28ad3d1ba91c431328007576251e47294fd8af2ebe7a2cb29e008afef",
|
||||
"contentSize": "13413071 B"
|
||||
},
|
||||
{
|
||||
"@type": "cr:FileObject",
|
||||
@@ -126,6 +126,16 @@
|
||||
"sha256": "b169d157e731db23c99f2f8317a9718d31801b7d64336b3d414511ac13f32493",
|
||||
"contentSize": "23174 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",
|
||||
"@id": "reports",
|
||||
@@ -143,7 +153,7 @@
|
||||
"description": "The Unofficial Dragon Register (which dragon each rider bonded), without rider names.",
|
||||
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/register.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "40b725a39dff447025de5dda0eb6850e0929764ab53549863f2efc5d9414731b",
|
||||
"sha256": "71457db37c12b2e76190480c1aab9fa00347985b5556a40e877093ddb5635750",
|
||||
"contentSize": "118558 B"
|
||||
},
|
||||
{
|
||||
@@ -153,8 +163,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).",
|
||||
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/stats.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "89a6246da2495685733e20f2de9897299bd19d469aaeadbd8883972856787ce5",
|
||||
"contentSize": "5151910 B"
|
||||
"sha256": "aa0a7726cbb1a96b0167329200cf6399ddaec4c4d7c8bf4c2f42045d22fd568e",
|
||||
"contentSize": "5195088 B"
|
||||
},
|
||||
{
|
||||
"@type": "cr:FileObject",
|
||||
@@ -163,8 +173,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).",
|
||||
"contentUrl": "https://git.kenschiano.net/DragonKind/threshing-atlas/raw/branch/main/data/public/policy.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "eec67140c63f028d31553be4f2310d92c9378293488aecd73a41ba1700b9e646",
|
||||
"contentSize": "987412 B"
|
||||
"sha256": "b0bb5f5cb233b976b5184f121844efa765c9c3f0440d59d4fe95c7b6eeb76514",
|
||||
"contentSize": "987608 B"
|
||||
},
|
||||
{
|
||||
"@type": "cr:FileObject",
|
||||
@@ -173,8 +183,8 @@
|
||||
"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",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "f9d1a86f84fcc10ef906af686ce624355ffd729440460288406ba97177ff05da",
|
||||
"contentSize": "84575 B"
|
||||
"sha256": "8817eea999eb8ffd4848638096fd1e8f06c73fe7d6d75e4ec7ea5e0c8859c842",
|
||||
"contentSize": "84523 B"
|
||||
}
|
||||
],
|
||||
"recordSet": [
|
||||
@@ -191,7 +201,7 @@
|
||||
"@type": "cr:Field",
|
||||
"@id": "runs/run_id",
|
||||
"name": "run_id",
|
||||
"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>.",
|
||||
"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>.",
|
||||
"dataType": "sc:Text",
|
||||
"source": {
|
||||
"fileObject": {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"sha256": "99953503376b54ee2ca2061bc277c712681a66add4d62737535e4afca11ba03e",
|
||||
"bytes": 638678,
|
||||
"sha256": "c62f634048b88fa2e4987281cf629c36fc0828aecc8ba22953893214c789df42",
|
||||
"bytes": 636518,
|
||||
"pages": 1,
|
||||
"page_hashes": [
|
||||
"513739c2cb809008"
|
||||
"857ea68696df050e"
|
||||
],
|
||||
"line_hashes": [
|
||||
"0005ef79b6b0",
|
||||
@@ -14,7 +14,6 @@
|
||||
"0309a521e7cd",
|
||||
"033394145a6f",
|
||||
"0340ff1da1bc",
|
||||
"061bdd1646d2",
|
||||
"06845f929ace",
|
||||
"06deac5b8d4a",
|
||||
"070e3c5097ec",
|
||||
@@ -52,9 +51,7 @@
|
||||
"16552853f950",
|
||||
"167a79b5d437",
|
||||
"16872ead1390",
|
||||
"16a87122c069",
|
||||
"17fce8dabd41",
|
||||
"18136e0d6414",
|
||||
"18f42f5e8e05",
|
||||
"1a1d05853cee",
|
||||
"1aefe47e20eb",
|
||||
@@ -85,7 +82,6 @@
|
||||
"2d306ed42cd7",
|
||||
"2de7de149983",
|
||||
"2e8e7a08f162",
|
||||
"2f251aff0a77",
|
||||
"2f501595d6f2",
|
||||
"2f63258bd7ea",
|
||||
"2f943c163229",
|
||||
@@ -105,7 +101,6 @@
|
||||
"351421b8bac7",
|
||||
"3650b7f3b7c5",
|
||||
"3693c0f2d9d6",
|
||||
"36bddc3a241f",
|
||||
"370b1d50ab9e",
|
||||
"3ad433972874",
|
||||
"3af12ce68cd1",
|
||||
@@ -194,7 +189,6 @@
|
||||
"6a3432dd57a9",
|
||||
"6a7ef134f235",
|
||||
"6b32aa9d4ff4",
|
||||
"6b46e167e442",
|
||||
"6bb9c00e0aa5",
|
||||
"6c45cb72a36e",
|
||||
"6c8a73953696",
|
||||
@@ -405,6 +399,7 @@
|
||||
"d8fe183f5b8e",
|
||||
"d90b4f86d5e0",
|
||||
"d942f0a84262",
|
||||
"d96bd5db16e6",
|
||||
"d978e0e48792",
|
||||
"d9a847a1a79a",
|
||||
"d9ae6af36f3c",
|
||||
@@ -486,5 +481,5 @@
|
||||
"ff1f017072cc",
|
||||
"ffe503ead4e4"
|
||||
],
|
||||
"checked": "2026-11-16"
|
||||
"checked": "2026-11-20"
|
||||
}
|
||||
|
||||
@@ -41,6 +41,12 @@ files:
|
||||
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.
|
||||
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:
|
||||
path: data/public/reports.json
|
||||
format: application/json
|
||||
@@ -69,7 +75,7 @@ files:
|
||||
# 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").
|
||||
columns:
|
||||
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>." }
|
||||
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>." }
|
||||
source:
|
||||
type: text
|
||||
required: true
|
||||
|
||||
+11
-11
@@ -5,23 +5,23 @@
|
||||
"changed": "2026-11-19"
|
||||
},
|
||||
"reddit_pdf": {
|
||||
"sha256": "99953503376b54ee2ca2061bc277c712681a66add4d62737535e4afca11ba03e",
|
||||
"bytes": 638678,
|
||||
"changed": "2026-11-16"
|
||||
"sha256": "c62f634048b88fa2e4987281cf629c36fc0828aecc8ba22953893214c789df42",
|
||||
"bytes": 636518,
|
||||
"changed": "2026-11-20"
|
||||
},
|
||||
"reddit_spreadsheet": {
|
||||
"sha256": "44eeece5fd75fb27f0c7bdf2729d812ba710f4bfba30dfd5dbee51a7888b8270",
|
||||
"bytes": 5994979,
|
||||
"changed": "2026-11-19"
|
||||
"sha256": "a48f96a27ca815f15a9bc363924f0286b70a43503bed01f23f87d10587be5ef3",
|
||||
"bytes": 6160082,
|
||||
"changed": "2026-11-21"
|
||||
},
|
||||
"register": {
|
||||
"sha256": "6efdf107fce4d7b5a48de3d683762b7236a6049c875145bf4aa1608c90f9ae8f",
|
||||
"sha256": "ae342bae9bfe323adb74acf24e1d9ce97acccfad0e1ed57392eb49548d44d68a",
|
||||
"bytes": 51331,
|
||||
"changed": "2026-11-19"
|
||||
"changed": "2026-11-21"
|
||||
},
|
||||
"reported": {
|
||||
"sha256": "4c62d2e726e7c967d03a6c85d3bb3e09384656b7ffd9ea629d13400fdc37b211",
|
||||
"bytes": 28296,
|
||||
"changed": "2026-11-19"
|
||||
"sha256": "80e3a627f9071462b27235301d1b2cd827a37dfcd8e6c4c77071b7bece650cc9",
|
||||
"bytes": 40979,
|
||||
"changed": "2026-11-20"
|
||||
}
|
||||
}
|
||||
|
||||
+52
-21
@@ -4,27 +4,27 @@
|
||||
"form": {
|
||||
"1": [
|
||||
97,
|
||||
960
|
||||
973
|
||||
],
|
||||
"2": [
|
||||
0,
|
||||
299
|
||||
301
|
||||
],
|
||||
"3": [
|
||||
0,
|
||||
196
|
||||
198
|
||||
],
|
||||
"4-10": [
|
||||
0,
|
||||
555
|
||||
574
|
||||
],
|
||||
"11-30": [
|
||||
0,
|
||||
657
|
||||
706
|
||||
],
|
||||
"31 or more": [
|
||||
0,
|
||||
715
|
||||
1,
|
||||
847
|
||||
]
|
||||
},
|
||||
"bulk logs": {
|
||||
@@ -46,11 +46,11 @@
|
||||
],
|
||||
"11-30": [
|
||||
0,
|
||||
57
|
||||
58
|
||||
],
|
||||
"31 or more": [
|
||||
0,
|
||||
0
|
||||
57
|
||||
]
|
||||
},
|
||||
"bot": {
|
||||
@@ -78,22 +78,53 @@
|
||||
0,
|
||||
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": {
|
||||
"routes": 326,
|
||||
"routes": 334,
|
||||
"first_shadows": 93,
|
||||
"expected": 38.8,
|
||||
"odds_ratio": Infinity,
|
||||
"z": 12.5
|
||||
"expected": 38.0,
|
||||
"odds_ratio": 111.1,
|
||||
"z": 12.7
|
||||
},
|
||||
"form_first": [
|
||||
97,
|
||||
960
|
||||
973
|
||||
],
|
||||
"form_later": [
|
||||
0,
|
||||
2422
|
||||
1,
|
||||
2626
|
||||
],
|
||||
"best_route": {
|
||||
"route": [
|
||||
@@ -110,18 +141,18 @@
|
||||
],
|
||||
"later": [
|
||||
0,
|
||||
106
|
||||
113
|
||||
]
|
||||
},
|
||||
"shadow_routes": {
|
||||
"runs": 97,
|
||||
"routes": 47,
|
||||
"runs": 99,
|
||||
"routes": 48,
|
||||
"off_gate": 3,
|
||||
"gates_unstated": 14
|
||||
},
|
||||
"after_shadow": {
|
||||
"reached_black": 89,
|
||||
"bonded_black": 65,
|
||||
"reached_black": 91,
|
||||
"bonded_black": 67,
|
||||
"died_at_blue": 19,
|
||||
"answers": {
|
||||
"held its gaze": [
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+10197
-9740
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,44 @@
|
||||
# The Atlas is plain static files. The data changes daily, so browsers revalidate rather than cache blindly.
|
||||
# Replaces the image's conf.d/default.conf (it listens on 8080 and runs as UID 65532).
|
||||
|
||||
# Temp files under /tmp (an emptyDir in the pod), so the root filesystem can be read-only
|
||||
client_body_temp_path /tmp/client_body;
|
||||
proxy_temp_path /tmp/proxy;
|
||||
fastcgi_temp_path /tmp/fastcgi;
|
||||
uwsgi_temp_path /tmp/uwsgi;
|
||||
scgi_temp_path /tmp/scgi;
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
charset utf-8;
|
||||
server_tokens off;
|
||||
|
||||
# The image logs to files under /var/log/nginx; send access logs to the pod log instead
|
||||
access_log /dev/stdout main;
|
||||
|
||||
# Every file type the site build writes, declared here rather than left to the image's mime.types: with nosniff
|
||||
# (below) a browser refuses a script that is not served as JavaScript. The page's data and source files show as
|
||||
# text. Anything else falls back to the image's list.
|
||||
include /etc/nginx/mime.types;
|
||||
types {
|
||||
text/html html;
|
||||
application/javascript js mjs;
|
||||
application/json json;
|
||||
text/csv csv;
|
||||
text/css css;
|
||||
image/svg+xml svg;
|
||||
text/plain yaml py md txt;
|
||||
}
|
||||
|
||||
gzip on;
|
||||
gzip_types text/plain text/css text/csv text/javascript application/javascript application/json;
|
||||
|
||||
add_header Cache-Control "no-cache" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
|
||||
location = /healthz { access_log off; default_type text/plain; return 200 "ok\n"; }
|
||||
location / { try_files $uri $uri/ =404; }
|
||||
}
|
||||
+3
-3
@@ -13,9 +13,9 @@ branch: main
|
||||
# public, limited (only people signed in to this server) or private: who can open the links below
|
||||
visibility: limited
|
||||
|
||||
# the published page, when it is hosted somewhere (GitHub Pages is paused while the GitHub account is suspended;
|
||||
# the page is viewed locally or as a Claude artifact meanwhile)
|
||||
site: null
|
||||
# the published page: a container on Ken's cluster (.gitea/workflows/image.yml, kubefiles web/threshing-atlas). Its address
|
||||
# (after a change, `python -m collection build`): the page's links and the dataset metadata use it.
|
||||
site: https://threshingatlas.kenschiano.net
|
||||
|
||||
# other copies of the repository (informational)
|
||||
mirrors:
|
||||
|
||||
+3
-3
@@ -6,11 +6,11 @@
|
||||
"scripts": {
|
||||
"build": "node site/build.js",
|
||||
"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 && 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: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:unit": "node --test tests/core/graph.test.js tests/core/advisor.test.js tests/core/known.test.js tests/core/bot_contract.test.js",
|
||||
"test": "npm run test:py && npm run test:unit",
|
||||
"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",
|
||||
"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",
|
||||
"cycle": "python3 -m collection cycle",
|
||||
"stats": "python3 analysis/stats/site_stats.py",
|
||||
"collect": "python3 -m collection update",
|
||||
|
||||
+12
-2
@@ -84,6 +84,7 @@
|
||||
// ------------------------------------------------------------ data loading
|
||||
async function loadStats() {
|
||||
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");
|
||||
sel.innerHTML = Object.entries(META().presets).map(([k, l]) => `<option value="${k}">${esc(l)}</option>`).join("");
|
||||
sel.value = state.preset;
|
||||
@@ -271,7 +272,15 @@
|
||||
const chance = s.chance;
|
||||
const t = svgEl("text", { x: colX(i), y: 18, class: "stage-label" + (chance ? " stage-chance" : "") }, svg);
|
||||
t.textContent = s.label;
|
||||
if (chance) { const r = svgEl("text", { x: colX(i), y: 31, class: "stage-label stage-chance" }, svg); r.textContent = "game roll"; }
|
||||
if (chance) {
|
||||
const r = svgEl("text", { x: colX(i), y: 31, class: "stage-label stage-chance" }, svg);
|
||||
r.textContent = "game roll";
|
||||
const here = G.nodes.filter((n) => n.stage === i), tot = here.reduce((a, n) => a + n.n, 0) || 1;
|
||||
const w = r.getComputedTextLength ? r.getComputedTextLength() : 70; // the headings are left-aligned
|
||||
Dice.svg(svg, colX(i) + w + 15, 27, { title: `${s.label}: the game's roll`, n: tot,
|
||||
options: here.map((n) => [n.value, n.n / tot]),
|
||||
note: "Share of riders who reached this step, in the runs shown. The game decides it; earlier choices can shift the odds." });
|
||||
}
|
||||
});
|
||||
|
||||
// links
|
||||
@@ -341,7 +350,7 @@
|
||||
<span>${state.widthMode === "traffic" ? "Band width = number of runs" : "Line width = chance of the outcome"}</span>
|
||||
<span style="display:inline-flex;gap:6px;align-items:center">0% <span class="ramp" style="background:linear-gradient(90deg, ${low}, ${tcol})"></span> ${pct(pmax, 0)}</span>
|
||||
<span>Grey = fewer than ${state.minN} runs</span>
|
||||
<span><span style="color:var(--accent)">Gold headings</span> = steps the game rolls, not you</span>`;
|
||||
<span>${Dice.legend('and <span style="color:var(--accent)">gold headings</span> = steps the game rolls at random, not your choice. Click the dice for the odds of each outcome.')}</span>`;
|
||||
}
|
||||
|
||||
function renderBestRoutes() {
|
||||
@@ -554,6 +563,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>
|
||||
<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>
|
||||
${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(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>`;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Rolls of the dice. Wherever the page shows a step the game decides at random (not the rider's choice), a pair of
|
||||
* dice sits next to it. Clicking the dice shows the odds of every outcome of that roll.
|
||||
*
|
||||
* Dice.html(roll) an inline button for HTML text
|
||||
* Dice.svg(parent, x, y, roll) the same glyph inside an SVG map
|
||||
* Dice.legend(text?) the legend line ("a roll: the game decides ...")
|
||||
*
|
||||
* roll = { title, options: [[label, p], ...], note?, n? } (p between 0 and 1; options may be empty with a note)
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
const NS = "http://www.w3.org/2000/svg";
|
||||
// two dice, the back one showing two, the front one five
|
||||
const GLYPH = `<svg class="dice-glyph" viewBox="0 0 22 16" width="22" height="16" aria-hidden="true">
|
||||
<rect x="1" y="1.5" width="10" height="10" rx="2.2" transform="rotate(-12 6 6.5)" fill="var(--raised)" stroke="currentColor" stroke-width="1.2"/>
|
||||
<circle cx="4" cy="4.8" r="1.05" fill="currentColor" transform="rotate(-12 6 6.5)"/><circle cx="8" cy="8.6" r="1.05" fill="currentColor" transform="rotate(-12 6 6.5)"/>
|
||||
<rect x="9.5" y="4.5" width="10.5" height="10.5" rx="2.2" fill="var(--raised)" stroke="currentColor" stroke-width="1.2"/>
|
||||
<circle cx="12.4" cy="7.4" r="1.05" fill="currentColor"/><circle cx="17.1" cy="7.4" r="1.05" fill="currentColor"/>
|
||||
<circle cx="14.75" cy="9.75" r="1.05" fill="currentColor"/>
|
||||
<circle cx="12.4" cy="12.1" r="1.05" fill="currentColor"/><circle cx="17.1" cy="12.1" r="1.05" fill="currentColor"/></svg>`;
|
||||
const TIP = "A roll: the game decides, not you. Click for the odds of each outcome.";
|
||||
|
||||
const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c]));
|
||||
const pack = (roll) => encodeURIComponent(JSON.stringify(roll || {}));
|
||||
const pct = (p) => (p == null ? "–" : p < 0.001 && p > 0 ? "<0.1%" : `${(100 * p).toFixed(p < 0.1 ? 1 : 0)}%`);
|
||||
|
||||
function html(roll) {
|
||||
return `<button type="button" class="dice" data-roll="${pack(roll)}" title="${TIP}" aria-label="${esc((roll && roll.title) || "A roll")}: show the odds">${GLYPH}</button>`;
|
||||
}
|
||||
|
||||
function svg(parent, x, y, roll) {
|
||||
const g = document.createElementNS(NS, "g");
|
||||
g.setAttribute("class", "dice dice-svg");
|
||||
g.setAttribute("data-roll", pack(roll));
|
||||
g.setAttribute("transform", `translate(${x - 11},${y - 8})`);
|
||||
g.setAttribute("tabindex", "0");
|
||||
g.setAttribute("role", "button");
|
||||
g.setAttribute("aria-label", `${(roll && roll.title) || "A roll"}: show the odds`);
|
||||
const t = document.createElementNS(NS, "title");
|
||||
t.textContent = TIP;
|
||||
g.appendChild(t);
|
||||
const halo = document.createElementNS(NS, "rect");
|
||||
for (const [k, v] of Object.entries({ x: -3, y: -3, width: 28, height: 22, rx: 6, fill: "var(--map-halo, var(--bg))", "fill-opacity": 0.9 })) halo.setAttribute(k, v);
|
||||
g.appendChild(halo);
|
||||
g.insertAdjacentHTML("beforeend", GLYPH.replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, ""));
|
||||
parent.appendChild(g);
|
||||
return g;
|
||||
}
|
||||
|
||||
function legend(text) {
|
||||
return `<span class="dice-legend">${GLYPH.replace('class="dice-glyph"', 'class="dice-glyph legend" style="display:inline-block;vertical-align:-3px"')} ${text || "= a roll: the game decides at random, not your choice. Click any dice for the odds of each outcome."}</span>`;
|
||||
}
|
||||
|
||||
// ---- the popover
|
||||
let pop = null;
|
||||
function hide() { if (pop) pop.hidden = true; }
|
||||
function show(roll, x, y) {
|
||||
if (!pop) {
|
||||
pop = document.createElement("div");
|
||||
pop.id = "dice-pop";
|
||||
pop.setAttribute("role", "dialog");
|
||||
document.body.appendChild(pop);
|
||||
}
|
||||
const opts = (roll.options || []).filter(([, p]) => p != null).sort((a, b) => b[1] - a[1]);
|
||||
pop.innerHTML = `<b>${esc(roll.title || "A roll")}</b>
|
||||
${opts.length ? `<ul>${opts.map(([k, p]) => `<li><span>${esc(k)}</span><span class="bar"><i style="width:${Math.max(1, 100 * p).toFixed(1)}%"></i></span><span class="p">${pct(p)}</span></li>`).join("")}</ul>` : ""}
|
||||
<p>${esc(roll.note || "The game decides this at random. Your earlier choices can change the odds, but not the outcome.")}${roll.n ? ` From ${Number(roll.n).toLocaleString()} runs.` : ""}</p>`;
|
||||
pop.hidden = false;
|
||||
const r = pop.getBoundingClientRect();
|
||||
pop.style.left = `${Math.max(8, Math.min(window.innerWidth - r.width - 8, x - r.width / 2))}px`;
|
||||
pop.style.top = `${y + 14 + r.height > window.innerHeight ? Math.max(8, y - r.height - 14) : y + 14}px`;
|
||||
}
|
||||
|
||||
function open(e, t) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
let roll = {};
|
||||
try { roll = JSON.parse(decodeURIComponent(t.getAttribute("data-roll"))); } catch { /* an empty roll */ }
|
||||
const b = t.getBoundingClientRect();
|
||||
show(roll, b.left + b.width / 2, b.bottom - 6);
|
||||
}
|
||||
// capture phase: a dice inside a map or a card must not also select what is under it
|
||||
document.addEventListener("click", (e) => {
|
||||
const t = e.target.closest && e.target.closest("[data-roll]");
|
||||
if (t) return open(e, t);
|
||||
if (pop && !pop.hidden && !pop.contains(e.target)) hide();
|
||||
}, true);
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape") return hide();
|
||||
const t = (e.key === "Enter" || e.key === " ") && e.target.closest && e.target.closest(".dice-svg[data-roll]");
|
||||
if (t) open(e, t);
|
||||
}, true);
|
||||
window.addEventListener("scroll", hide, { passive: true });
|
||||
|
||||
window.Dice = { html, svg, legend };
|
||||
})();
|
||||
+22
-12
@@ -92,7 +92,8 @@
|
||||
const model = () => st.policy.samples[st.sample];
|
||||
function advisorFor(enc, colour = st.colour) {
|
||||
const k = `${st.sample}|${colour}|${st.objective}|${enc}`;
|
||||
if (!st.cache.has(k)) st.cache.set(k, S.advisor(model(), colour, st.objective, { only: [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], attempt: colour === "Black" ? "First attempt" : null }));
|
||||
return st.cache.get(k);
|
||||
}
|
||||
let encParams = null;
|
||||
@@ -324,6 +325,13 @@
|
||||
pills.push({ g, x, y, w, h, dy: 0 });
|
||||
el("rect", { x: x - w / 2, y: y - h / 2, width: w, height: h, rx: h / 2, fill: bg, "fill-opacity": 0.95, stroke: edge || ink, "stroke-opacity": edge ? 0.95 : 0.4, "stroke-width": edge ? 2 : 1 }, g);
|
||||
el("text", { x, y: y + (strong ? 4.5 : 4), "text-anchor": "middle", "font-size": strong ? 12.5 : 11, "font-weight": strong ? 700 : 500, fill: ink, "font-family": "var(--font-data)" }, g).textContent = text;
|
||||
return { g, w };
|
||||
}
|
||||
|
||||
/** What a roll on the route can come out as: every outcome with its odds, for the dice. */
|
||||
function rollOf(s, title) {
|
||||
return { title: title || s.label || "A roll", options: Object.entries(s.probs || {}).filter(([, p]) => p > 0.0005),
|
||||
note: "The game decides this at random. The odds are the model's, given the choices on this route so far." };
|
||||
}
|
||||
|
||||
function drawDragons(g, routesOn) {
|
||||
@@ -526,11 +534,12 @@
|
||||
if (p > 0.995) return;
|
||||
// the last roll leads straight into the dragon, whose own label sits there: put the roll under the fork point
|
||||
const at = !ro.at ? { x: ro.P.x + 34, y: ro.P.y - 22 } : ro.at === pts.length - 1 ? { x: pts[ro.at - 1].P.x, y: pts[ro.at - 1].P.y + 24 } : mid(pts[ro.at - 1].P, pts[ro.at].P, 0.38);
|
||||
pill(gLab, at.x, at.y, ro.s.var === "shadow" ? (ro.s.taken === "yes" ? `shadow ${pct(p)}` : `no shadow ${pct(p)}`) : `roll ${pct(p)}`);
|
||||
const lab = pill(gLab, at.x, at.y, ro.s.var === "shadow" ? (ro.s.taken === "yes" ? `shadow ${pct(p)}` : `no shadow ${pct(p)}`) : `roll ${pct(p)}`);
|
||||
Dice.svg(lab.g, at.x - lab.w / 2 - 14, at.y, rollOf(ro.s, ro.s.var === "shadow" ? "Does the shadow show at the tree?" : null));
|
||||
});
|
||||
// destination label
|
||||
const end = pts[pts.length - 1];
|
||||
pill(gLab, end.P.x, end.P.y + 30, `${pct(r.value.x)} per attempt`, { edge: tc, strong: rel === 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 });
|
||||
// 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)
|
||||
if (focus) {
|
||||
@@ -714,7 +723,7 @@
|
||||
const sp = st.info, dir = sp.place.split(":")[1];
|
||||
const fs = st.policy ? S.makeParams(model().model.tables, { alphas: model().model.alphas }).chance("fs", { direction: dir }) : null;
|
||||
info = `<div class="ex-card"><span class="eyebrow">First sighting · ${dir === "Center" ? "forest centre" : dir.toLowerCase()}</span>
|
||||
<p class="small">The first dragon is a roll of the dice: nobody bonds here, it decides what you face next.${fs ? ` Going ${dir === "Center" ? "to the forest centre" : dir.toLowerCase()}, riders met: ${Object.entries(fs).sort((a, b) => b[1] - a[1]).filter(([, p]) => p > 0.005).map(([k, p]) => `${k} ${pct(p)}`).join(", ")}.` : ""}</p></div>`;
|
||||
<p class="small">The first dragon is a roll of the dice${fs ? ` ${Dice.html({ title: `First dragon, going ${dir === "Center" ? "to the forest centre" : dir.toLowerCase()}`, options: Object.entries(fs).filter(([, p]) => p > 0.0005), note: "The game decides which dragon you see first. Which way you went changes the odds." })}` : ""}: nobody bonds here, it decides what you face next.${fs ? ` Going ${dir === "Center" ? "to the forest centre" : dir.toLowerCase()}, riders met: ${Object.entries(fs).sort((a, b) => b[1] - a[1]).filter(([, p]) => p > 0.005).map(([k, p]) => `${k} ${pct(p)}`).join(", ")}.` : ""}</p></div>`;
|
||||
}
|
||||
return `<span class="eyebrow">Unofficial atlas · built from ${st.nRuns ? st.nRuns.toLocaleString() : "thousands of"} logged runs</span>
|
||||
<h2 id="h-valley">The valley</h2>
|
||||
@@ -783,7 +792,7 @@
|
||||
}
|
||||
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>` :
|
||||
return `<ul>${options.map((o) => o.roll ? `<li class="roll">${Dice.html({ title: "A roll (from the community guide)", note: `The guide notes: ${o.roll}. It gives no odds for it.` })}<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) {
|
||||
@@ -797,7 +806,7 @@
|
||||
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>` : ""}
|
||||
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">${Dice.html({ title: "A roll (from the community guide)", note: `The guide notes: ${s.roll}. It gives no odds for it.` })}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>
|
||||
@@ -830,7 +839,7 @@
|
||||
const others = Object.entries(sc.options).filter(([k]) => k !== p.option).map(([, o]) =>
|
||||
`<li>${esc(o.text)} <small>${o.n ? `died ${died(o)} of ${o.n}` : "untested"}</small></li>`).join("");
|
||||
return `<li><span class="n">${i + 1}</span><div><b>${esc(p.text)}</b>
|
||||
<small>${me.n ? `got through ${lived} of ${me.n} times` : ""}${me.kind === "fixed" && me.n ? " · always the same so far" : me.kind === "dice" ? " · a roll" : ""}</small>
|
||||
<small>${me.n ? `got through ${lived} of ${me.n} times` : ""}${me.kind === "fixed" && me.n ? " · always the same so far" : me.kind === "dice" ? ` · a roll ${Dice.html({ title: p.text, n: me.n, options: Object.entries(me.to || {}).map(([k, o]) => [k === "DIED" ? "died" : k.startsWith("BONDED") ? k.replace("BONDED_", "bonded ").toLowerCase() : (t.screens[k] ? `then: ${t.screens[k].stage.toLowerCase().replace(/_/g, " ")}${t.screens[k].tint ? ` (${t.screens[k].tint})` : ""}` : k), o.n / me.n]), note: "The same answer led to different screens in the bot's runs: the game rolled." })}` : ""}</small>
|
||||
${others ? `<details><summary>Other answers here</summary><ul>${others}</ul></details>` : ""}</div></li>`;
|
||||
}).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"));
|
||||
@@ -841,7 +850,7 @@
|
||||
|
||||
function panelRoutes(routes) {
|
||||
const best = Math.max(1e-12, ...routes.map((r) => r.value.x));
|
||||
const T = model().targets[st.colour], b = T[st.objective];
|
||||
const T = model().targets[st.colour], first = st.colour === "Black" && T.firstAttempt, b = first ? T.firstAttempt.thisAttempt : T[st.objective];
|
||||
const focus = routes.find((r) => r.enc === st.focus) || routes[0];
|
||||
const card = (r) => {
|
||||
const rel = r.value.x / best, o = encOutcome(r.enc), c = encColour(r.enc);
|
||||
@@ -851,10 +860,10 @@
|
||||
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>
|
||||
<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>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>${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>`;
|
||||
};
|
||||
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)} ${Dice.html(rollOf(s))}</span><b>${esc(String(s.taken))}</b><small>roll ${pct(s.probs[s.taken])}</small></li>`;
|
||||
const open = st.expanded === s.var;
|
||||
const opts = open ? `<div class="ex-opts">${Object.entries(s.options).sort((a, c) => c[1].pX - a[1].pX).map(([v, val]) =>
|
||||
`<button type="button" class="ex-opt${v === s.taken ? " on" : ""}" data-var="${s.var}" data-v="${esc(v)}"><span>${esc(v)}${v === s.choice ? ' <em class="rec">best</em>' : ""}</span><b>${pct(val.pX)}</b></button>`).join("")}</div>` : "";
|
||||
@@ -862,7 +871,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>`;
|
||||
}).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 lb = st.policy.samples.lowBias.targets[st.colour].thisAttempt;
|
||||
const lbT = st.policy.samples.lowBias.targets[st.colour], lb = first && lbT.firstAttempt ? lbT.firstAttempt.thisAttempt : lbT.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>
|
||||
<button type="button" class="ex-close" id="ex-clear" aria-label="Back to the whole valley">×</button></div>
|
||||
${chooser()}
|
||||
@@ -870,11 +879,12 @@
|
||||
${st.blocked ? `<p class="small ex-warn">Your choices so far can't reach a ${st.colour} dragon. <button type="button" class="linklike" id="ex-reset-route">Reset your choices</button></p>` : ""}
|
||||
<div class="ex-routes">${routes.map(card).join("")}</div>
|
||||
<p class="small muted ex-key"><span class="solid"></span> best route <span class="dashed"></span> under half as likely <span class="dotted"></span> under a tenth · line width: chance you are still on the route</p>
|
||||
<p class="small muted">${Dice.legend()}</p>
|
||||
<span class="eyebrow">${esc(ENC_NAME[focus.enc])}: step by step</span>
|
||||
<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>
|
||||
<details class="ex-why"><summary>Why this route?</summary>
|
||||
<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>
|
||||
${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">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>
|
||||
<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>
|
||||
|
||||
@@ -89,6 +89,20 @@ button.primary, a.btnlike.primary { background: var(--accent); color: var(--acce
|
||||
#map text { font-family: var(--font-body); font-size: 11px; fill: var(--ink); }
|
||||
#map .stage-label { font-family: var(--font-data); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; fill: var(--muted); }
|
||||
#map .stage-chance { fill: var(--accent); }
|
||||
/* rolls of the dice (dice.js): a step the game decides, not the rider */
|
||||
.dice { display: inline-flex; align-items: center; vertical-align: middle; padding: 0 2px; margin: 0 2px; border: 0; background: none; color: var(--accent); cursor: pointer; line-height: 1; border-radius: 4px; }
|
||||
.dice:hover, .dice:focus-visible, .dice-svg:hover, .dice-svg:focus-visible { color: var(--ink); outline: 1px solid var(--accent); outline-offset: 1px; }
|
||||
.dice-svg { color: var(--accent); cursor: pointer; }
|
||||
.dice-glyph { display: inline-block; vertical-align: middle; }
|
||||
.dice-glyph.legend { color: var(--accent); margin-right: 2px; }
|
||||
.dice-legend { display: inline; }
|
||||
#dice-pop { position: fixed; z-index: 60; max-width: min(320px, calc(100vw - 16px)); padding: 10px 12px; background: var(--raised); color: var(--ink); border: 1px solid var(--accent); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.45); font-size: var(--step--1, 0.85rem); }
|
||||
#dice-pop ul { list-style: none; margin: 6px 0; padding: 0; display: grid; gap: 4px; }
|
||||
#dice-pop li { display: grid; grid-template-columns: minmax(0, 1fr) 70px 46px; gap: 8px; align-items: center; }
|
||||
#dice-pop .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
|
||||
#dice-pop .bar i { display: block; height: 100%; background: var(--accent); }
|
||||
#dice-pop .p { font-family: var(--font-data); text-align: right; }
|
||||
#dice-pop p { margin: 6px 0 0; color: var(--muted); }
|
||||
#map .node rect { stroke: color-mix(in srgb, var(--ink) 40%, transparent); stroke-width: 0.6; cursor: pointer; }
|
||||
#map .node.sel rect { stroke: var(--accent); stroke-width: 2.4; }
|
||||
#map .node.dim { opacity: 0.35; }
|
||||
@@ -182,6 +196,8 @@ 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 .what { font-weight: 600; }
|
||||
.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::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; }
|
||||
@@ -747,6 +763,7 @@ adjusted OR = exp(βⱼ), 95% CI = exp(βⱼ ± 1.96·SEⱼ)</div>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
|
||||
<script src="solver.js"></script>
|
||||
<script src="register.js"></script>
|
||||
<script src="dice.js"></script>
|
||||
<script src="app.js"></script>
|
||||
<script src="valley.js"></script>
|
||||
<script src="dragons.js"></script>
|
||||
|
||||
@@ -159,6 +159,8 @@
|
||||
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"];
|
||||
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;
|
||||
const br = b.best_route;
|
||||
box.hidden = false;
|
||||
@@ -170,6 +172,7 @@
|
||||
${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>
|
||||
</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>`;
|
||||
}
|
||||
|
||||
@@ -189,6 +192,13 @@
|
||||
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 }) => {
|
||||
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)}
|
||||
<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]))}
|
||||
|
||||
+1
-1
@@ -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/solver.js", "solver.js");
|
||||
// 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"]) copy(`data/public/${f}`, `data/${f}`);
|
||||
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}`);
|
||||
copy("data/public/runs_clean.csv", "data/runs_clean.csv");
|
||||
for (const f of ["croissant.json", "dictionary.yaml"]) copy(`data/${f}`, `data/${f}`);
|
||||
// Source files shown in the page's "view the code" panel
|
||||
|
||||
@@ -335,6 +335,43 @@ class RedditComments(unittest.TestCase):
|
||||
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):
|
||||
spec = read_yaml("collection/pipeline.yaml")["sources"]["reddit_comments"]
|
||||
with self.assertRaises(extract.Skip):
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
// The bot's side of the route advisor. Ken's bot (DragonKind/DragonKind src/atlasPolicy.js) loads policy.json,
|
||||
// solver.js and graph.js from vendor/threshing-atlas/ and calls them in one fixed chain. This test copies that chain
|
||||
// (AtlasPolicy.advise and buildTrajectory, as of DragonKind commit ebe134a2) and plays the bot's own recorded screens
|
||||
// (data/public/tree.json) through it, for every colour, sample and goal, so a change here that would break the bot
|
||||
// fails in this repo's CI first. node --test tests/core/bot_contract.test.js
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert");
|
||||
const path = require("node:path");
|
||||
const fs = require("node:fs");
|
||||
|
||||
const ROOT = path.join(__dirname, "../..");
|
||||
const Solver = require("../../core/solver.js");
|
||||
const Graph = require("../../core/graph.js");
|
||||
const policy = JSON.parse(fs.readFileSync(path.join(ROOT, "data/public/policy.json"), "utf8"));
|
||||
const tree = JSON.parse(fs.readFileSync(path.join(ROOT, "data/public/tree.json"), "utf8"));
|
||||
const known = JSON.parse(fs.readFileSync(path.join(ROOT, "data/public/known_answers.json"), "utf8"));
|
||||
|
||||
// ---- copied from the bot (src/atlasPolicy.js): keep in step with it
|
||||
const ATLAS_COLOURS = { black: "Black", blue: "Blue", green: "Green", red: "Red", brown: "Brown", orange: "Orange" };
|
||||
const FIRST_SIGHTING_COLOURS = new Set(["red", "brown", "green", "orange"]);
|
||||
function sceneColour({ tint = null, observed = {} } = {}) {
|
||||
const t = String(tint || "").toLowerCase();
|
||||
if (ATLAS_COLOURS[t]) return t;
|
||||
const dragons = Array.isArray(observed?.dragons) ? observed.dragons : [];
|
||||
return dragons.length === 1 ? dragons[0] : null;
|
||||
}
|
||||
function buildTrajectory(events = []) {
|
||||
const steps = [];
|
||||
const seen = {};
|
||||
for (const ev of events) {
|
||||
const colour = sceneColour(ev);
|
||||
steps.push({ optionText: ev.optionText || "", tint: colour && FIRST_SIGHTING_COLOURS.has(colour) ? colour : null });
|
||||
if (ev.observed?.shadow === true) seen.shadow = "yes";
|
||||
else if (ev.observed?.shadow === false && seen.shadow !== "yes") seen.shadow = "no";
|
||||
}
|
||||
return { trajectory: { steps, outcome: {} }, seen };
|
||||
}
|
||||
const advisors = new Map();
|
||||
function advise({ targetDragon, sample = "all", objective = "eventually", events = [], offered = [] }) {
|
||||
const colour = ATLAS_COLOURS[targetDragon];
|
||||
const { trajectory, seen } = buildTrajectory(events);
|
||||
const { vars } = Graph.trajectoryVariables(trajectory);
|
||||
const key = `${sample}|${colour}|${objective}`;
|
||||
if (!advisors.has(key)) advisors.set(key, Solver.advisor(policy.samples[sample], colour, objective));
|
||||
const adv = advisors.get(key);
|
||||
const history = Solver.solverHistory(vars, seen, adv.game);
|
||||
const raw = adv.next(history);
|
||||
if (!raw) return null;
|
||||
const withStep = (step) => ({ ...adv, next: (h) => (h === history ? step : adv.next(h)) });
|
||||
return Solver.recommendOption(withStep(raw), history, offered);
|
||||
}
|
||||
// ---- end of the copy
|
||||
|
||||
test("the bot's modules have what it checks for when it loads them", () => {
|
||||
assert.strictEqual(typeof Solver.advisor, "function");
|
||||
assert.strictEqual(typeof Solver.recommendOption, "function");
|
||||
assert.strictEqual(typeof Solver.solverHistory, "function");
|
||||
assert.strictEqual(typeof Solver.knownAnswer, "function");
|
||||
assert.strictEqual(typeof Graph.trajectoryVariables, "function");
|
||||
assert.ok(policy.samples.all.model && policy.samples.lowBias.model && policy.id);
|
||||
});
|
||||
|
||||
/**
|
||||
* Play one run through the recorded screens, asking for advice on each. The run follows the advised option where the
|
||||
* bot has played it (so the screen after it is on record), and otherwise the option the bot played most, going on to
|
||||
* the screen it most often led to. Returns the advised option text on every screen that had one.
|
||||
*/
|
||||
function play(targetDragon, sample, objective) {
|
||||
const events = [], advised = [];
|
||||
let id = tree.start;
|
||||
for (let guard = 0; id && tree.screens[id] && guard < 40; guard++) {
|
||||
const sc = tree.screens[id];
|
||||
const opts = Object.values(sc.options);
|
||||
if (!opts.length) break;
|
||||
const offered = opts.map((o) => o.text);
|
||||
const here = { tint: sc.tint };
|
||||
const rec = advise({ targetDragon, sample, objective, events: [...events, here], offered });
|
||||
if (rec) {
|
||||
assert.ok(rec.decision && rec.choice, `${targetDragon}: advice without a decision on ${sc.label}`);
|
||||
assert.ok(rec.choice in rec.options, `${targetDragon}: ${rec.choice} is not one of its own options`);
|
||||
assert.ok(rec.index === null || (Number.isInteger(rec.index) && rec.index >= 0 && rec.index < offered.length),
|
||||
`${targetDragon}: index ${rec.index} on ${sc.label}`);
|
||||
if (rec.index !== null) advised.push(offered[rec.index]);
|
||||
}
|
||||
const playedTo = (o) => Object.entries(o.to || {}).sort((a, b) => b[1].n - a[1].n)[0];
|
||||
let i = rec && rec.index !== null && playedTo(opts[rec.index]) ? rec.index : -1;
|
||||
if (i < 0) i = opts.reduce((b, o, j) => ((o.n || 0) > (opts[b].n || 0) ? j : b), 0);
|
||||
events.push({ ...here, optionText: offered[i] });
|
||||
const to = playedTo(opts[i]);
|
||||
id = to ? to[0] : null;
|
||||
}
|
||||
return advised;
|
||||
}
|
||||
|
||||
test("every colour, sample and goal plays the recorded screens without an error or an impossible pick", () => {
|
||||
for (const sample of ["all", "lowBias"]) {
|
||||
for (const target of Object.keys(ATLAS_COLOURS)) {
|
||||
for (const objective of ["thisAttempt", "eventually"]) {
|
||||
// the first screen (company) always has advice the bot can click
|
||||
assert.ok(play(target, sample, objective).length >= 1, `${target} ${sample} ${objective}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("for the Black the bot is pointed through both gates and up the tree", () => {
|
||||
const picked = play("black", "all", "eventually").map((t) => t.toLowerCase());
|
||||
assert.ok(picked.some((t) => t.startsWith("investigate the scream")), picked.join(" | "));
|
||||
assert.ok(!picked.some((t) => t.startsWith("keep walking")), picked.join(" | "));
|
||||
assert.ok(picked.some((t) => t.startsWith("find the tallest tree")), picked.join(" | "));
|
||||
});
|
||||
|
||||
test("the experiment plan assigns every attempt something the advisor can play (docs/BOT_INTEGRATION.md)", () => {
|
||||
const plan = JSON.parse(fs.readFileSync(path.join(ROOT, "data/public/experiments.json"), "utf8"));
|
||||
const game = policy.samples.all.model.game;
|
||||
let assigned = 0;
|
||||
for (let accountSeq = 0; accountSeq < 20; accountSeq++) {
|
||||
for (let attempt = 1; attempt <= 6; attempt++) {
|
||||
for (const sawShadowBefore of [false, true]) {
|
||||
const a = Solver.assign(plan, { accountSeq, attempt, facts: { sawShadowBefore } });
|
||||
if (!a) continue;
|
||||
assigned++;
|
||||
assert.ok(Object.values(ATLAS_COLOURS).includes(a.target), `${a.experimentId}: target ${a.target}`);
|
||||
assert.ok(a.propensity > 0 && a.propensity <= 1, `${a.experimentId}: propensity ${a.propensity}`);
|
||||
for (const [k, v] of Object.entries(a.fix || {})) {
|
||||
assert.ok(game.decisions[k] && game.decisions[k].options.includes(v), `${a.experimentId}: fix ${k} = ${v}`);
|
||||
}
|
||||
const adv = Solver.advisor(policy.samples.all, a.target, a.objective, { attempt, fix: a.fix, sampling: a.sampling, seed: a.seed });
|
||||
const first = adv.next({});
|
||||
assert.ok(first && first.choice, `${a.experimentId}: no advice on the first screen`);
|
||||
if (a.fix && a.fix.company) assert.strictEqual(first.choice, a.fix.company, a.experimentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.ok(assigned > 0);
|
||||
// a fresh account's first attempt is the Black attempt
|
||||
assert.strictEqual(Solver.assign(plan, { accountSeq: 0, attempt: 1, facts: { sawShadowBefore: false } }).target, "Black");
|
||||
});
|
||||
|
||||
test("known answers load and answer in the shape the bot expects", () => {
|
||||
const sc = Object.values(tree.screens).find((s) => s.stage === "TARGET_BONDING" && Object.keys(s.options).length > 1);
|
||||
const r = Solver.knownAnswer(known, Object.values(sc.options).map((o) => o.text), { target: "black", sceneColour: sc.tint ? ATLAS_COLOURS[sc.tint] || null : null });
|
||||
if (r !== null) {
|
||||
assert.ok(r.pick === null || Number.isInteger(r.pick));
|
||||
assert.ok(Array.isArray(r.choices));
|
||||
}
|
||||
});
|
||||
|
||||
test("the bot's tie rule never takes an option that rules the Black out, even when every option's odds are about zero", () => {
|
||||
// the bot (src/atlasPolicy.js) picks at random among options within tieMargin of the best. On a later attempt the
|
||||
// data put the Black near zero everywhere, so before the advisor ruled such options out every option tied, and the
|
||||
// bot walked away from the squadmate or went to the valley (DragonKind research runs 90, 91, 102, November 2026).
|
||||
const TIE = 0.002; // DEFAULT_TIE_MARGIN in the bot
|
||||
const tiedAt = (offered, history) => {
|
||||
const rec = advise({ targetDragon: "black", events: history, offered });
|
||||
if (!rec || rec.margin === null) return rec ? [rec.choice] : [];
|
||||
const best = Math.max(...Object.values(rec.options).map((v) => v.pX));
|
||||
return Object.entries(rec.options).filter(([, v]) => best - v.pX < TIE).map(([o]) => o);
|
||||
};
|
||||
// the screens exactly as the bot saw them (DragonKind research run 91)
|
||||
const start = [{ optionText: "Enter the valley alone" }, { optionText: "Head toward the center of the forest" }, { tint: "red", optionText: "Lower your eyes in respect" }, { optionText: "Head deeper into the forest" }];
|
||||
const t1 = tiedAt(["Investigate the scream", "Keep walking. The cadets are just as dangerous as the dragons today"], [...start, {}]);
|
||||
assert.ok(t1.length && !t1.includes("Keep walking"), `scream: ${t1}`);
|
||||
const t2 = tiedAt(["Play it safe and leave them to their own defense so you can find your dragon", "Help your squadmate"], [...start, { optionText: "Investigate the scream" }, {}]);
|
||||
assert.ok(t2.length && !t2.includes("Walk away"), `clearing: ${t2}`);
|
||||
const path = [...start, { optionText: "Investigate the scream" }, { optionText: "Help your squadmate" }, { optionText: "Pause to assess the situation even though it may risk your squadmate's life" },
|
||||
{ optionText: "Engage the smaller cadet" }, { optionText: "Allow your squadmate to exact their own revenge" }, { optionText: "Walk farther into the forest" }, {}];
|
||||
const t3 = tiedAt(["Find the tallest tree and climb for a better view", "Continue toward the center of the valley"], path);
|
||||
assert.deepStrictEqual(t3, ["Tree"], `hour: ${t3}`);
|
||||
});
|
||||
@@ -0,0 +1,185 @@
|
||||
"""The route model's arithmetic (core/atlas/model.py) on small hand-made datasets whose answers are worked out by hand
|
||||
in the comments: the hierarchical back-off, the empirical-Bayes concentration and its guard, the gate on the shadow,
|
||||
which bonds an encounter allows, the first-attempt given, and the reproducible random numbers."""
|
||||
import unittest
|
||||
|
||||
from atlas import model, solver
|
||||
|
||||
|
||||
def fs_run(direction, fs, company=None, left=None):
|
||||
"""A prepared run that says only which dragon came first (the fs roll)."""
|
||||
return {"direction": direction, "fs": fs, "company": company, "left": left}
|
||||
|
||||
|
||||
def tree_run(attempt, shadow, scream="Investigate the scream", clearing="Help your squadmate"):
|
||||
"""A prepared run that reached the tree; the shadow's gate is open unless scream / clearing say otherwise."""
|
||||
v = {"attempt": attempt, "scream": scream, "shadow": shadow}
|
||||
if clearing:
|
||||
v["clearing"] = clearing
|
||||
return v
|
||||
|
||||
|
||||
class BackOff(unittest.TestCase):
|
||||
def test_counts_at_every_level_until_a_context_step_is_missing(self):
|
||||
T = model.count_tables([fs_run("East", "Red", "Alone", model.ALONE), fs_run("West", "Brown")])
|
||||
t = T["fs"]
|
||||
self.assertEqual(t["0:"], {"Red": 1, "Brown": 1})
|
||||
self.assertEqual(t["1:East"], {"Red": 1})
|
||||
self.assertEqual(t["2:East|Alone"], {"Red": 1})
|
||||
self.assertEqual(t["3:East|Alone|(alone)"], {"Red": 1})
|
||||
self.assertEqual(t["1:West"], {"Brown": 1})
|
||||
self.assertFalse(any(k.startswith("2:West") for k in t)) # no company: the West run stops at level 1
|
||||
|
||||
def test_weights_scale_the_counts_and_zero_leaves_a_run_out(self):
|
||||
runs = [fs_run("East", "Red"), fs_run("East", "Red"), fs_run("East", "Brown")]
|
||||
T = model.count_tables(runs, [{"fs": 0.5}, {"fs": 0}, {}])
|
||||
self.assertEqual(T["fs"]["0:"], {"Red": 0.5, "Brown": 1})
|
||||
|
||||
def test_each_level_is_shrunk_toward_the_level_above(self):
|
||||
# 3 West runs saw a Red, 1 East run a Brown. Outcomes in game.yaml order: Red, Brown, Green, Orange.
|
||||
T = model.count_tables([fs_run("West", "Red")] * 3 + [fs_run("East", "Brown")])
|
||||
p = model.Params(T, "mean", alphas={"fs": 12})
|
||||
got = lambda state: [float(p.chance("fs", state)[k][0]) for k in ("Red", "Brown", "Green", "Orange")] # noqa: E731
|
||||
# level 0: counts + 1/2 = [3.5, 1.5, .5, .5] / 6 = [7, 3, 1, 1] / 12
|
||||
top = [7 / 12, 3 / 12, 1 / 12, 1 / 12]
|
||||
for a, b in zip(got({}), top):
|
||||
self.assertAlmostEqual(a, b)
|
||||
# East: its own count [0, 1, 0, 0] + alpha 12 x level 0 = [7, 4, 1, 1] / 13
|
||||
for a, b in zip(got({"direction": "East"}), [7 / 13, 4 / 13, 1 / 13, 1 / 13]):
|
||||
self.assertAlmostEqual(a, b)
|
||||
# West: [3, 0, 0, 0] + [7, 3, 1, 1] = [10, 3, 1, 1] / 15
|
||||
for a, b in zip(got({"direction": "West"}), [10 / 15, 3 / 15, 1 / 15, 1 / 15]):
|
||||
self.assertAlmostEqual(a, b)
|
||||
# a direction nobody took: no counts of its own, so exactly the level above
|
||||
for a, b in zip(got({"direction": "Center"}), top):
|
||||
self.assertAlmostEqual(a, b)
|
||||
|
||||
|
||||
class Concentration(unittest.TestCase):
|
||||
def fit(self, runs):
|
||||
return model.fit_alpha(model.count_tables(runs), "fs")["alpha"]
|
||||
|
||||
def test_routes_that_differ_get_a_small_concentration(self):
|
||||
self.assertLessEqual(self.fit([fs_run("East", "Red")] * 200 + [fs_run("West", "Brown")] * 200), 2)
|
||||
|
||||
def test_routes_that_do_not_differ_get_a_large_one(self):
|
||||
same = [fs_run(d, c) for d in ("East", "West") for c in ("Red", "Brown") for _ in range(100)]
|
||||
self.assertGreaterEqual(self.fit(same), 500)
|
||||
|
||||
def test_guard_a_roll_seen_only_one_way_is_pooled_fully(self):
|
||||
# without the guard the fit would let every route's chance of the unseen outcome go to zero
|
||||
self.assertEqual(self.fit([fs_run("East", "Red")] * 50 + [fs_run("West", "Red")] * 5), max(model.ALPHA_GRID))
|
||||
|
||||
def test_no_context_levels_keeps_the_default(self):
|
||||
T = model.count_tables([{"fs": "Red"}, {"fs": "Brown"}]) # no direction: only level 0
|
||||
self.assertEqual(model.fit_alpha(T, "fs"), {"alpha": model.ALPHA, "logLik": None})
|
||||
|
||||
def test_levels_that_are_not_pooled_are_not_fitted(self):
|
||||
# the shadow's first context step (the attempt) is `distinct`: its level is not one of the fitted pairs
|
||||
T = model.count_tables([tree_run("First attempt", True)] * 10 + [tree_run("Later attempt", False)] * 10)
|
||||
self.assertEqual(model.fit_alpha(T, "shadow")["alpha"], model.ALPHA)
|
||||
|
||||
|
||||
class Gate(unittest.TestCase):
|
||||
def test_gate_open(self):
|
||||
self.assertTrue(model.gate_open("shadow", tree_run("First attempt", True)))
|
||||
self.assertFalse(model.gate_open("shadow", tree_run("First attempt", True, scream="Keep walking", clearing=None)))
|
||||
self.assertFalse(model.gate_open("shadow", tree_run("First attempt", True, clearing="Walk away")))
|
||||
self.assertTrue(model.gate_open("fs", {})) # an ungated roll
|
||||
|
||||
def test_runs_through_a_closed_gate_say_nothing_about_the_roll(self):
|
||||
runs = [tree_run("Later attempt", False)] * 4 + [tree_run("Later attempt", False, scream="Keep walking", clearing=None)] * 6 \
|
||||
+ [tree_run("Later attempt", True, clearing="Walk away")] # a shadow through a closed gate: not counted
|
||||
self.assertEqual(model.count_tables(runs)["shadow"]["0:"], {"no": 4})
|
||||
|
||||
def test_a_closed_gate_always_gives_otherwise(self):
|
||||
p = model.Params(model.count_tables([tree_run("Later attempt", True)] * 5), "mean")
|
||||
c = p.chance("shadow", {"scream": "Keep walking"})
|
||||
self.assertEqual((float(c["yes"][0]), float(c["no"][0])), (0.0, 1.0))
|
||||
self.assertGreater(float(p.chance("shadow", tree_run(None, None))["yes"][0]), 0.5)
|
||||
|
||||
|
||||
class FirstAttempt(unittest.TestCase):
|
||||
# first attempts: 1 shadow in 2; later attempts: none in 8
|
||||
RUNS = [tree_run("First attempt", True), tree_run("First attempt", False)] + [tree_run("Later attempt", False)] * 8
|
||||
|
||||
def test_each_attempt_is_its_own_roll_with_a_token_prior(self):
|
||||
p = model.Params(model.count_tables(self.RUNS), "mean", alphas={"shadow": 20})
|
||||
gate = {"scream": "Investigate the scream", "clearing": "Help your squadmate"}
|
||||
# level 0: [yes 1, no 9] + 1/2 = [1.5, 9.5] / 11. The attempt level is distinct, so its prior weighs one run
|
||||
# (not alpha = 20): first [1 + 1.5/11, 1 + 9.5/11] / 3, later [0 + 1.5/11, 8 + 9.5/11] / 9
|
||||
first = float(p.having(attempt="First attempt").chance("shadow", gate)["yes"][0])
|
||||
later = float(p.chance("shadow", gate)["yes"][0]) # the default given is a later attempt
|
||||
self.assertAlmostEqual(first, (1 + 1.5 / 11) / 3)
|
||||
self.assertAlmostEqual(later, (1.5 / 11) / 9)
|
||||
|
||||
def test_givens_and_their_names(self):
|
||||
self.assertEqual(model.DEFAULT_GIVEN, {"attempt": "Later attempt"})
|
||||
self.assertEqual(solver.other_givens(), [{"attempt": "First attempt"}])
|
||||
self.assertEqual(solver.given_key({"attempt": "First attempt"}), "firstAttempt")
|
||||
|
||||
|
||||
class Bonds(unittest.TestCase):
|
||||
def test_can_bond(self):
|
||||
self.assertTrue(model.can_bond("tree-Greens", "Green"))
|
||||
self.assertTrue(model.can_bond("tree-Greens", "Orange")) # an Orange or a Brown can swoop in
|
||||
self.assertTrue(model.can_bond("tree-Greens", "Brown"))
|
||||
self.assertFalse(model.can_bond("tree-Greens", "Red"))
|
||||
self.assertTrue(model.can_bond("meadow-Blue", "burn"))
|
||||
self.assertFalse(model.can_bond("meadow-Blue", "Orange"))
|
||||
self.assertFalse(model.can_bond("shadow-Black", "Blue"))
|
||||
|
||||
def test_encounter_odds_count_only_possible_bonds(self):
|
||||
enc = lambda o: {"encCtx": "tree-Greens", "encOutcome": o} # noqa: E731
|
||||
T = model.count_tables([enc("Green"), enc("Green"), enc("burn"), enc("Orange"), enc("Red")])
|
||||
self.assertEqual(T["encounter"]["tree-Greens"]["outcomes"], {"Green": 2, "burn": 1, "Orange": 1})
|
||||
e = model.Params(T, "mean").encounter("tree-Greens")
|
||||
# outcomes that can happen here and were seen (or are the encounter's own colour), + 1/2: burn, Orange, Green
|
||||
self.assertEqual(list(e), ["burn", "Orange", "Green"])
|
||||
for k, n in (("burn", 1.5), ("Orange", 1.5), ("Green", 2.5)):
|
||||
self.assertAlmostEqual(float(e[k][0]), n / 5.5)
|
||||
|
||||
|
||||
class Solved(unittest.TestCase):
|
||||
"""The gate and the given carried through the solver: no Black without investigating and helping."""
|
||||
|
||||
def setUp(self):
|
||||
runs = self.RUNS = FirstAttempt.RUNS + [{"encCtx": "shadow-Black", "encOutcome": "Black"}] * 3
|
||||
self.T = model.count_tables(runs)
|
||||
self.support, _ = model.support_from(runs, 0)
|
||||
|
||||
def black(self, params, **only):
|
||||
return float(solver.solve(params, "Black", {**self.support, **only}).value[0][0])
|
||||
|
||||
def test_closing_the_gate_makes_the_black_impossible(self):
|
||||
p = model.Params(self.T, "mean")
|
||||
self.assertGreater(self.black(p), 0)
|
||||
self.assertEqual(self.black(p, scream=["Keep walking"]), 0.0)
|
||||
self.assertEqual(self.black(p, clearing=["Walk away"]), 0.0)
|
||||
|
||||
def test_a_first_attempt_is_better_for_the_black(self):
|
||||
p = model.Params(self.T, "mean")
|
||||
self.assertGreater(self.black(p.having(attempt="First attempt")), 5 * self.black(p))
|
||||
|
||||
|
||||
class Random(unittest.TestCase):
|
||||
def test_xorshift_matches_the_javascript_model(self):
|
||||
r = model.Rng(1)
|
||||
# 1 ^ 1<<13 = 8193; ^ >>17 leaves it; ^ <<5: 8193 ^ 262176 = 270369
|
||||
self.assertEqual(r(), 270369 / 2 ** 32)
|
||||
self.assertEqual(model.Rng(0).s, 1) # a zero seed would stay zero forever
|
||||
|
||||
def test_dirichlet_draws_average_to_the_normalised_counts(self):
|
||||
r = model.Rng(20261101)
|
||||
draws = [model.dirichlet([2, 6, 2], r) for _ in range(4000)]
|
||||
for i, want in enumerate((0.2, 0.6, 0.2)):
|
||||
self.assertAlmostEqual(sum(d[i] for d in draws) / len(draws), want, delta=0.01)
|
||||
|
||||
def test_lgamma(self):
|
||||
import math
|
||||
for x in (0.5, 1, 2.5, 10, 300):
|
||||
self.assertAlmostEqual(model.lgamma(x), math.lgamma(x), places=8)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,127 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user