Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee07ee143e | ||
|
|
4837332a7d | ||
|
|
614bfcda7c | ||
|
|
8713ccff1a | ||
|
|
8f1f0383fe | ||
|
|
64fd3af235 | ||
|
|
2271fe0976 | ||
|
|
c0355616b6 | ||
|
|
d37eaa3378 | ||
|
|
43066ad67f |
@@ -0,0 +1,24 @@
|
||||
# Tests on every push and pull request (Gitea Actions; GitHub's copy is .github/workflows/ci.yml).
|
||||
# The branch rule for main (docs/REPO_SETTINGS.md) requires this check, named "CI / test".
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest # a runner label on the server (act_runner); change it if the server uses another
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
- run: pip install -r requirements.txt
|
||||
- run: npm test
|
||||
- name: graph.json is up to date
|
||||
run: node analysis/network/build-graph.js && git diff --exit-code data/public/graph.json
|
||||
- name: the page builds
|
||||
run: node site/build.js
|
||||
@@ -0,0 +1,92 @@
|
||||
# Every day: check every source (collection/pipeline.yaml), and when something changed, rebuild the runs, the
|
||||
# graph, the route model and the statistics, run the tests and open a pull request that merges itself once CI
|
||||
# passes. A source that cannot be reached, or new answers the coding rules do not know, open an issue instead.
|
||||
# Gitea Actions; GitHub's copy (with GitHub Pages) is .github/workflows/update-sources.yml.
|
||||
#
|
||||
# Secrets (repository Settings -> Actions -> Secrets; docs/REPO_SETTINGS.md):
|
||||
# ATLAS_BOT_TOKEN a Gitea access token (repository: read and write; issue: read and write). Needed to push the
|
||||
# update branch and open the pull request; the built-in token cannot start the CI it needs.
|
||||
# RAW_ARCHIVE_KEY optional: encrypts the private raw store kept in the Actions cache between runs
|
||||
# REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET optional: read the megathreads through the Reddit API
|
||||
name: Check sources for new data
|
||||
on:
|
||||
schedule:
|
||||
- cron: "23 10 * * *" # daily
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest # a runner label on the server (act_runner)
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.ATLAS_BOT_TOKEN }}
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
- run: pip install -r requirements.txt
|
||||
- name: Restore the private raw archive
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: ${{ runner.temp }}/raw-archive
|
||||
key: raw-archive-none
|
||||
restore-keys: raw-archive-
|
||||
- name: Decrypt it
|
||||
env:
|
||||
RAW_ARCHIVE_KEY: ${{ secrets.RAW_ARCHIVE_KEY }}
|
||||
run: |
|
||||
f="$RUNNER_TEMP/raw-archive/raw.tgz.enc"
|
||||
if [ -n "$RAW_ARCHIVE_KEY" ] && [ -f "$f" ]; then
|
||||
openssl enc -d -aes-256-cbc -pbkdf2 -pass env:RAW_ARCHIVE_KEY -in "$f" | tar -xz -C data
|
||||
fi
|
||||
- id: check
|
||||
env:
|
||||
ATLAS_BOT_TOKEN: ${{ secrets.ATLAS_BOT_TOKEN }}
|
||||
REDDIT_CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }}
|
||||
REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }}
|
||||
run: python -m collection update --report "$RUNNER_TEMP/report.md"
|
||||
- name: Rebuild the analysis and run tests
|
||||
if: steps.check.outputs.changed == 'true'
|
||||
run: |
|
||||
node analysis/network/build-graph.js
|
||||
npm run policy
|
||||
npm run stats
|
||||
python -m collection build
|
||||
npm test
|
||||
- name: Encrypt the raw store
|
||||
id: archive
|
||||
env:
|
||||
RAW_ARCHIVE_KEY: ${{ secrets.RAW_ARCHIVE_KEY }}
|
||||
run: |
|
||||
if [ -n "$RAW_ARCHIVE_KEY" ] && [ -d data/raw ]; then
|
||||
mkdir -p "$RUNNER_TEMP/raw-archive"
|
||||
tar -czf - -C data raw | openssl enc -aes-256-cbc -pbkdf2 -salt -pass env:RAW_ARCHIVE_KEY -out "$RUNNER_TEMP/raw-archive/raw.tgz.enc"
|
||||
echo "save=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
- name: Save it (a new copy only when a raw file changed)
|
||||
if: steps.archive.outputs.save == 'true'
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
path: ${{ runner.temp }}/raw-archive
|
||||
key: raw-archive-${{ hashFiles('data/manifest.json') }}
|
||||
- name: Open a pull request with the new data (it merges itself once CI passes)
|
||||
if: steps.check.outputs.changed == 'true'
|
||||
env:
|
||||
ATLAS_BOT_TOKEN: ${{ secrets.ATLAS_BOT_TOKEN }}
|
||||
run: |
|
||||
branch="data/source-update-$(date -u +%Y%m%d)"
|
||||
git config user.name "Atlas data bot"
|
||||
git config user.email "atlas-bot@noreply.localhost"
|
||||
git checkout -b "$branch"
|
||||
git add -A data analysis/reports core/graph.js .github/ISSUE_TEMPLATE
|
||||
git commit -m "data: update from community sources"
|
||||
git push origin "$branch"
|
||||
python -m collection forge open-pr --head "$branch" --title "New data from the community sources" --body-file "$RUNNER_TEMP/report.md" --automerge
|
||||
- name: Report a broken source or new answers
|
||||
if: steps.check.outputs.failed != ''
|
||||
env:
|
||||
ATLAS_BOT_TOKEN: ${{ secrets.ATLAS_BOT_TOKEN }}
|
||||
run: |
|
||||
python -m collection forge open-issue --title "Source check failed: ${{ steps.check.outputs.failed }}" --body-file "$RUNNER_TEMP/report.md"
|
||||
@@ -9,7 +9,8 @@ body:
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for reporting a run! Answer what you remember; leave anything you're unsure of on "Not sure".
|
||||
Every answer here is **public** (this is a GitHub issue) and goes into the Atlas's open data as source "reported".
|
||||
Every answer here is visible to everyone who can see this repository (it is an issue) and goes into the Atlas's
|
||||
open data as source "reported".
|
||||
Please don't include your DragonKind account name or anything personal.
|
||||
You can also use the community [Threshing Routes form](https://forms.gle/DRpj9tG8gb5E4Hcu7) linked from the r/fourthwing megathread; please report each run only once.
|
||||
- type: dropdown
|
||||
|
||||
@@ -238,3 +238,6 @@ undefined/
|
||||
# hand-off zips and local reports (python -m collection export-bot-kit / refresh)
|
||||
exports/
|
||||
inbox/
|
||||
|
||||
# PyCharm
|
||||
.idea/
|
||||
|
||||
@@ -42,7 +42,8 @@ npm test # pipeline, coding rules, statistics, route model, game spec, a
|
||||
|
||||
## New data from the community sources
|
||||
|
||||
A GitHub Action (`.github/workflows/update-sources.yml`) runs the collection pipeline every day
|
||||
A scheduled workflow (`.gitea/workflows/update-sources.yml` on the Atlas's Gitea; `.github/workflows/` holds the
|
||||
GitHub version) runs the collection pipeline every day
|
||||
(`python -m collection update`, see `collection/README.md`). It checks every source in `collection/pipeline.yaml`,
|
||||
and if anything changed it rebuilds the runs and the analysis, runs the tests and opens a pull request that says
|
||||
what changed: new responses, new or renamed questions, new run reports, new result links on Reddit, and for the PDF
|
||||
@@ -75,7 +76,7 @@ See `docs/BOT_DATA_PROTOCOL.md` for what the bot should log.
|
||||
|
||||
## Running everything locally
|
||||
|
||||
`python -m collection refresh` does what the daily GitHub workflow does: checks every source, rebuilds the runs,
|
||||
`python -m collection refresh` does what the daily workflow does: checks every source, rebuilds the runs,
|
||||
the graph, the route model and the statistics. Add `--bot <folder or zip>` to import bot runs, and
|
||||
`python -m collection export-bot-kit` zips the files the bot uses (see `docs/BOT_INTEGRATION.md`).
|
||||
|
||||
|
||||
+736
-724
File diff suppressed because it is too large
Load Diff
@@ -4,8 +4,24 @@
|
||||
"""
|
||||
import json
|
||||
|
||||
from . import forge
|
||||
from .common import path, read_yaml
|
||||
|
||||
LINKS = "data/public/links.json"
|
||||
|
||||
|
||||
def links():
|
||||
"""The links the page shows, from forge.yaml and pipeline.yaml (site/build.js fills them into the page)."""
|
||||
f = forge.config()
|
||||
src = read_yaml("collection/pipeline.yaml")["sources"]
|
||||
host = f["url"].split("://", 1)[-1].rstrip("/")
|
||||
return {
|
||||
"repo": forge.repo_url(f), "repo_label": f"{host}/{f['repo']}", "host": host, "kind": f["kind"],
|
||||
"visibility": f.get("visibility", "public"),
|
||||
"report": forge.new_issue_url(".github/ISSUE_TEMPLATE/report-a-run.yml", f),
|
||||
"form": src["reddit_spreadsheet"]["links"]["form"], "sheet": src["reddit_spreadsheet"]["links"]["sheet"],
|
||||
}
|
||||
|
||||
GRAPH_JS = "core/graph.js"
|
||||
BEGIN = " // BEGIN CROSSWALK"
|
||||
END = " // END CROSSWALK\n"
|
||||
|
||||
+21
-25
@@ -10,6 +10,8 @@ Each extractor returns the raw bytes, or raises Skip when the source cannot be r
|
||||
secret, the bot's private repo not on this machine).
|
||||
"""
|
||||
import base64
|
||||
import fnmatch
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
@@ -62,22 +64,10 @@ def reddit(spec, env):
|
||||
return json.dumps(threads, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
||||
|
||||
|
||||
def github_issues(spec, env):
|
||||
"""Every issue with the label (open and closed), through the GitHub REST API."""
|
||||
headers = {"Accept": "application/vnd.github+json"}
|
||||
token = env.get("GITHUB_TOKEN") or env.get("GH_TOKEN")
|
||||
if token:
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
label = urllib.parse.quote(spec["label"])
|
||||
issues, page = [], 1
|
||||
while True:
|
||||
url = f"https://api.github.com/repos/{spec['repo']}/issues?labels={label}&state=all&per_page=100&page={page}"
|
||||
batch = json.loads(_get(url, headers=headers))
|
||||
issues += [i for i in batch if "pull_request" not in i]
|
||||
if len(batch) < 100:
|
||||
break
|
||||
page += 1
|
||||
issues.sort(key=lambda i: i["number"])
|
||||
def forge_issues(spec, env):
|
||||
"""Every issue with the label (open and closed), from the repository's host (forge.yaml: Gitea or GitHub)."""
|
||||
from . import forge
|
||||
issues = forge.list_issues(spec["label"], env)
|
||||
return json.dumps(issues, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
||||
|
||||
|
||||
@@ -87,9 +77,12 @@ def local_dir(spec, env):
|
||||
if not root:
|
||||
raise Skip(f"the bot's repo is private: set {spec['env']} to a local copy to import it")
|
||||
files = {}
|
||||
for rel in spec["files"]:
|
||||
p = os.path.join(root, rel)
|
||||
files[rel] = Path(p).read_text(encoding="utf-8") if os.path.exists(p) else None
|
||||
for pattern in spec["files"]: # a pattern may have * for one folder level (one folder per bot account)
|
||||
hits = sorted(glob.glob(os.path.join(root, pattern)))
|
||||
for p in hits:
|
||||
files[os.path.relpath(p, root).replace(os.sep, "/")] = Path(p).read_text(encoding="utf-8")
|
||||
if not hits and "*" not in pattern:
|
||||
files[pattern] = None
|
||||
return json.dumps(files, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
||||
|
||||
|
||||
@@ -99,19 +92,22 @@ def pack_local(spec, src):
|
||||
src = Path(src).expanduser()
|
||||
if src.is_dir():
|
||||
return local_dir(spec, {spec["env"]: str(src)})
|
||||
files = {rel: None for rel in spec["files"]}
|
||||
files = {rel: None for rel in spec["files"] if "*" not in rel}
|
||||
with zipfile.ZipFile(src) as z:
|
||||
names = [n for n in z.namelist() if not n.endswith("/") and "__MACOSX" not in n]
|
||||
for rel in spec["files"]:
|
||||
hits = sorted((n for n in names if n == rel or n.endswith("/" + rel)), key=len)
|
||||
if hits:
|
||||
files[rel] = z.read(hits[0]).decode("utf-8")
|
||||
for pattern in spec["files"]:
|
||||
for n in names:
|
||||
# the files may sit under a top folder (a zipped repo): match the pattern on the end of the name
|
||||
parts = n.split("/")
|
||||
rel = next(("/".join(parts[i:]) for i in range(len(parts)) if fnmatch.fnmatchcase("/".join(parts[i:]), pattern)), None)
|
||||
if rel and files.get(rel) is None:
|
||||
files[rel] = z.read(n).decode("utf-8")
|
||||
if not any(files.values()):
|
||||
raise RuntimeError(f"{src.name}: none of {', '.join(spec['files'])} found inside")
|
||||
return json.dumps(files, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
||||
|
||||
|
||||
EXTRACTORS = {"http": http, "reddit": reddit, "github_issues": github_issues, "local_dir": local_dir}
|
||||
EXTRACTORS = {"http": http, "reddit": reddit, "forge_issues": forge_issues, "local_dir": local_dir}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- the raw store
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
"""The repository host (forge.yaml): links, and the few API calls the pipeline makes, for Gitea and GitHub.
|
||||
|
||||
python -m collection forge open-pr --head BRANCH --title T --body-file F [--automerge]
|
||||
python -m collection forge open-issue --title T --body-file F (skipped if an open issue has that title)
|
||||
python -m collection forge ensure-label --name N --color HEX
|
||||
|
||||
The token comes from ATLAS_BOT_TOKEN, then GITEA_TOKEN / GITHUB_TOKEN / GH_TOKEN.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
from .common import read_yaml
|
||||
|
||||
USER_AGENT = "threshing-atlas-collector/1.0"
|
||||
|
||||
|
||||
def config():
|
||||
return read_yaml("forge.yaml")
|
||||
|
||||
|
||||
def repo_url(f=None):
|
||||
f = f or config()
|
||||
return f"{f['url'].rstrip('/')}/{f['repo']}"
|
||||
|
||||
|
||||
def file_url(path, f=None, raw=True):
|
||||
"""A file in the repository on its main branch (raw content, or the page that shows it)."""
|
||||
f = f or config()
|
||||
if f["kind"] == "github":
|
||||
if raw:
|
||||
return f"https://raw.githubusercontent.com/{f['repo']}/{f['branch']}/{path}"
|
||||
return f"{repo_url(f)}/blob/{f['branch']}/{path}"
|
||||
return f"{repo_url(f)}/{'raw' if raw else 'src'}/branch/{f['branch']}/{path}"
|
||||
|
||||
|
||||
def new_issue_url(template, f=None):
|
||||
"""The "new issue" page for an issue form in .github/ISSUE_TEMPLATE/."""
|
||||
f = f or config()
|
||||
if f["kind"] == "github":
|
||||
return f"{repo_url(f)}/issues/new?template={os.path.basename(template)}"
|
||||
return f"{repo_url(f)}/issues/new?template={urllib.parse.quote(template)}"
|
||||
|
||||
|
||||
def api_base(f=None):
|
||||
f = f or config()
|
||||
if f["kind"] == "github":
|
||||
return f"https://api.github.com/repos/{f['repo']}"
|
||||
return f"{f['url'].rstrip('/')}/api/v1/repos/{f['repo']}"
|
||||
|
||||
|
||||
def token(env=None):
|
||||
env = os.environ if env is None else env
|
||||
for k in ("ATLAS_BOT_TOKEN", "GITEA_TOKEN", "GITHUB_TOKEN", "GH_TOKEN"):
|
||||
if env.get(k):
|
||||
return env[k]
|
||||
return None
|
||||
|
||||
|
||||
def _call(method, url, body=None, tok=None, f=None):
|
||||
f = f or config()
|
||||
headers = {"User-Agent": USER_AGENT, "Accept": "application/json"}
|
||||
if tok:
|
||||
headers["Authorization"] = f"{'Bearer' if f['kind'] == 'github' else 'token'} {tok}"
|
||||
data = None
|
||||
if body is not None:
|
||||
data = json.dumps(body).encode("utf-8")
|
||||
headers["Content-Type"] = "application/json"
|
||||
req = urllib.request.Request(url, data=data, method=method, headers=headers)
|
||||
with urllib.request.urlopen(req, timeout=60) as r:
|
||||
text = r.read().decode("utf-8")
|
||||
return json.loads(text) if text.strip() else None
|
||||
|
||||
|
||||
def list_issues(label, env=None, f=None):
|
||||
"""Every issue (open and closed, no pull requests) with the label, oldest first, in GitHub's field names
|
||||
(number, body, labels, state, state_reason, created_at), which both hosts share."""
|
||||
f = f or config()
|
||||
tok = token(env)
|
||||
lab = urllib.parse.quote(label)
|
||||
out, page = [], 1
|
||||
while True:
|
||||
if f["kind"] == "github":
|
||||
url = f"{api_base(f)}/issues?labels={lab}&state=all&per_page=100&page={page}"
|
||||
else:
|
||||
url = f"{api_base(f)}/issues?labels={lab}&state=all&type=issues&limit=50&page={page}"
|
||||
batch = _call("GET", url, tok=tok, f=f) or []
|
||||
out += [i for i in batch if "pull_request" not in i or not i["pull_request"]]
|
||||
if len(batch) < (100 if f["kind"] == "github" else 50):
|
||||
break
|
||||
page += 1
|
||||
for i in out:
|
||||
i.setdefault("state_reason", None) # Gitea has no close reason: reports are rejected with labels
|
||||
return sorted(out, key=lambda i: i["number"])
|
||||
|
||||
|
||||
def open_pr(head, title, body, automerge=False, env=None, f=None):
|
||||
f = f or config()
|
||||
tok = token(env)
|
||||
pr = _call("POST", f"{api_base(f)}/pulls", {"head": head, "base": f["branch"], "title": title, "body": body}, tok, f)
|
||||
n = pr["number"]
|
||||
if automerge:
|
||||
if f["kind"] == "github":
|
||||
# GitHub's auto-merge needs GraphQL; the repo's auto-merge setting merges it when checks pass
|
||||
print(f"opened #{n}; turn on auto-merge in the pull request page if it is not on by default")
|
||||
else:
|
||||
_call("POST", f"{api_base(f)}/pulls/{n}/merge",
|
||||
{"Do": "squash", "merge_when_checks_succeed": True, "delete_branch_after_merge": True}, tok, f)
|
||||
return n
|
||||
|
||||
|
||||
def open_issue(title, body, env=None, f=None):
|
||||
f = f or config()
|
||||
tok = token(env)
|
||||
q = urllib.parse.quote(title)
|
||||
found = _call("GET", f"{api_base(f)}/issues?state=open&type=issues&q={q}" if f["kind"] == "gitea"
|
||||
else f"{api_base(f)}/issues?state=open&per_page=100", tok=tok, f=f) or []
|
||||
if any(i.get("title") == title for i in found):
|
||||
return None
|
||||
return _call("POST", f"{api_base(f)}/issues", {"title": title, "body": body}, tok, f)["number"]
|
||||
|
||||
|
||||
def ensure_label(name, color, env=None, f=None):
|
||||
f = f or config()
|
||||
tok = token(env)
|
||||
labels = _call("GET", f"{api_base(f)}/labels?limit=50&per_page=100", tok=tok, f=f) or []
|
||||
if any(lb["name"] == name for lb in labels):
|
||||
return False
|
||||
_call("POST", f"{api_base(f)}/labels", {"name": name, "color": ("#" if f["kind"] == "gitea" else "") + color.lstrip("#")}, tok, f)
|
||||
return True
|
||||
|
||||
|
||||
def main(argv):
|
||||
import argparse
|
||||
ap = argparse.ArgumentParser(prog="python -m collection forge")
|
||||
sub = ap.add_subparsers(dest="cmd", required=True)
|
||||
p = sub.add_parser("open-pr")
|
||||
p.add_argument("--head", required=True)
|
||||
p.add_argument("--title", required=True)
|
||||
p.add_argument("--body-file", required=True)
|
||||
p.add_argument("--automerge", action="store_true")
|
||||
i = sub.add_parser("open-issue")
|
||||
i.add_argument("--title", required=True)
|
||||
i.add_argument("--body-file", required=True)
|
||||
lb = sub.add_parser("ensure-label")
|
||||
lb.add_argument("--name", required=True)
|
||||
lb.add_argument("--color", default="e8b07e")
|
||||
a = ap.parse_args(argv)
|
||||
if a.cmd == "open-pr":
|
||||
body = open(a.body_file, encoding="utf-8").read()
|
||||
print(f"pull request #{open_pr(a.head, a.title, body, a.automerge)}")
|
||||
elif a.cmd == "open-issue":
|
||||
n = open_issue(a.title, open(a.body_file, encoding="utf-8").read())
|
||||
print(f"issue #{n}" if n else "an open issue with that title exists already")
|
||||
elif a.cmd == "ensure-label":
|
||||
print("created" if ensure_label(a.name, a.color) else "exists")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -7,6 +7,7 @@ Written by `python -m collection build` (a test checks it is up to date).
|
||||
"""
|
||||
import json
|
||||
|
||||
from . import forge
|
||||
from .common import ROOT, pipeline, read_yaml, sha256_file
|
||||
|
||||
OUT = "data/croissant.json"
|
||||
@@ -67,6 +68,7 @@ def field_description(spec):
|
||||
def build(dictionary=None):
|
||||
d = dictionary or load_dictionary()
|
||||
ds = d["dataset"]
|
||||
fg = forge.config()
|
||||
sources = pipeline()["sources"]
|
||||
|
||||
distribution = []
|
||||
@@ -77,7 +79,7 @@ def build(dictionary=None):
|
||||
"@id": key,
|
||||
"name": key,
|
||||
"description": " ".join(spec["description"].split()),
|
||||
"contentUrl": spec.get("url") or f"{ds['repository']}/blob/main/{spec['path']}",
|
||||
"contentUrl": forge.file_url(spec["path"], fg),
|
||||
"encodingFormat": spec["format"],
|
||||
"sha256": sha256(path),
|
||||
"contentSize": f"{path.stat().st_size} B",
|
||||
@@ -102,12 +104,12 @@ def build(dictionary=None):
|
||||
"conformsTo": "http://mlcommons.org/croissant/1.0",
|
||||
"name": ds["name"],
|
||||
"description": " ".join(ds["description"].split()),
|
||||
"url": ds["url"],
|
||||
"sameAs": ds["repository"],
|
||||
"url": fg.get("site") or forge.repo_url(fg),
|
||||
"sameAs": forge.repo_url(fg),
|
||||
"license": ds["license"],
|
||||
"creator": {"@type": "sc:Person", "name": ds["creator"], "url": f"https://github.com/{ds['creator']}"},
|
||||
"creator": {"@type": "sc:Person", "name": ds["creator"]},
|
||||
"keywords": ds["keywords"],
|
||||
"citeAs": ds["citation"],
|
||||
"citeAs": ds["citation"].format(repository=forge.repo_url(fg)),
|
||||
"isLiveDataset": True,
|
||||
"isBasedOn": [
|
||||
{"@type": "sc:CreativeWork", "name": s["label"], "url": next(iter(s["links"].values()))}
|
||||
|
||||
+44
-5
@@ -150,10 +150,27 @@ def bot_variables(traj, crosswalk):
|
||||
return v, unmapped
|
||||
|
||||
|
||||
BURN_REASONS = { # why the bot chose to die, in words (the bot's own reason codes)
|
||||
"TREE_NO_SHADOW_AUTO_BURN": "no shadow at the tree",
|
||||
"MEADOW_NO_BLUE_AUTO_BURN": "no Blue in the meadow",
|
||||
}
|
||||
|
||||
|
||||
def _seen_after(steps, start, key):
|
||||
"""Values the bot saw (step["seen"][key]) from step index `start` on."""
|
||||
out = []
|
||||
for st in steps[start:]:
|
||||
v = (st.get("seen") or {}).get(key)
|
||||
if v is not None:
|
||||
out += v if isinstance(v, list) else [v]
|
||||
return out
|
||||
|
||||
|
||||
def bot(name, spec):
|
||||
cw = [(re.compile(rx), col, val) for rx, col, val in read_yaml(spec["transform"]["spec"])["crosswalk"]]
|
||||
rows = []
|
||||
for traj in bot_trajectories(spec):
|
||||
steps = traj["steps"]
|
||||
v, _ = bot_variables(traj, cw)
|
||||
red = v.pop("red", None)
|
||||
v.pop("scream_investigate", None)
|
||||
@@ -165,18 +182,40 @@ def bot(name, spec):
|
||||
if o["type"] == "BONDED":
|
||||
outcome, colour = "Bonded", (o.get("colour") or "").capitalize() or None
|
||||
elif o["type"] == "BURNED":
|
||||
last_tint = traj["steps"][-1].get("tint")
|
||||
last_tint = steps[-1].get("tint") if steps else None
|
||||
outcome = "Incinerated" if v.get("hour") else "Died before the hour"
|
||||
colour = last_tint.capitalize() if last_tint and v.get("hour") else None
|
||||
if o.get("intentional"):
|
||||
flags.append("deliberate burn (the bot chose to die)")
|
||||
else:
|
||||
why = BURN_REASONS.get(o.get("reason") or "", "")
|
||||
flags.append("deliberate burn (the bot chose to die" + (f": {why}" if why else "") + ")")
|
||||
else: # ABORTED, ENDED_NO_BOND: the run stopped without an ending the bot saw
|
||||
outcome, colour = "No outcome recorded", None
|
||||
if not steps:
|
||||
flags.append("bonded dragon only (the bot logged no steps)")
|
||||
target = (meta.get("target") or "").capitalize() or None
|
||||
row = blank_row(run_id=traj["id"], source=spec["run_source"], date=(meta.get("startedAt") or "")[:10] or None,
|
||||
attempt=meta.get("attempt"), goal=target if target in COLOURS else None,
|
||||
row = blank_row(run_id=traj["id"], source=spec["run_source"], bot_mode=meta.get("decisionMode"),
|
||||
date=(meta.get("startedAt") or "")[:10] or None, attempt=meta.get("attempt"),
|
||||
goal=target if target in COLOURS else None,
|
||||
outcome=outcome, outcome_color=colour, data_flags="; ".join(flags), **v)
|
||||
row["attempt_group"] = attempt_group(row["attempt"])
|
||||
if target: # the bot never bonds a dragon it was not sent for: it dies on purpose instead (Malek)
|
||||
row["malek_intent"] = "Yes"
|
||||
if outcome == "Died before the hour" and not o.get("intentional"): # where the game killed it
|
||||
if row["scream"] == "Unknown":
|
||||
row["scream"] = "DIED at first sighting"
|
||||
elif row["scream"] == "Investigate & help" and row["resolution"] == "Unknown":
|
||||
row["resolution"] = "DIED in combat"
|
||||
else:
|
||||
row["hour"] = "DIED before the hour"
|
||||
# what the bot saw: the shadow at the treetop, and which dragons waited in the meadow
|
||||
shadow = _seen_after(steps, 0, "shadow")
|
||||
if row["hour"] == "Tree" and shadow:
|
||||
row["saw_shadow"] = any(shadow)
|
||||
if row["branch"] == "Passed the Red: meadow":
|
||||
i = next((k for k, st in enumerate(steps) if re.search(r"no way this is your dragon", _norm(st["optionText"]))), len(steps))
|
||||
meadow = _seen_after(steps, i + 1, "dragons")
|
||||
if meadow or o.get("reason") == "MEADOW_NO_BLUE_AUTO_BURN":
|
||||
row["saw_blue_meadow"] = "blue" in meadow or colour == "Blue"
|
||||
encounter_columns(row, intentional=bool(o.get("intentional")))
|
||||
rows.append(row)
|
||||
return rows
|
||||
|
||||
@@ -215,17 +215,145 @@ def merge_scenes(existing, scenes):
|
||||
return dict(sorted(out.items()))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- run records with steps (the bot's schema 2)
|
||||
|
||||
def _to(key):
|
||||
"""The bot's toKey -> ours: a scene id, BURNED or BONDED:<colour>."""
|
||||
key = str(key or "")
|
||||
if key == "TERMINAL:BURNED":
|
||||
return "BURNED"
|
||||
if key.startswith("TERMINAL:BONDED"):
|
||||
return "BONDED:" + (key.split("_", 1)[1].lower() if "_" in key else "unknown")
|
||||
return key or None
|
||||
|
||||
|
||||
def _seen(observed):
|
||||
"""What the bot saw on a screen that the route model needs: the dragons (from the tint) and the shadow."""
|
||||
o = observed or {}
|
||||
out = {}
|
||||
if o.get("dragons"):
|
||||
out["dragons"] = [str(d).lower() for d in o["dragons"]]
|
||||
if "shadow" in o:
|
||||
out["shadow"] = bool(o["shadow"])
|
||||
return out
|
||||
|
||||
|
||||
def trajectory_from_run(r, account_key):
|
||||
"""A run record that carries its own steps -> a trajectory. Nothing but choice text, ids and outcomes is kept."""
|
||||
steps = []
|
||||
for st in r.get("steps") or []:
|
||||
text = st.get("choiceText") or st.get("choiceNorm")
|
||||
if not text:
|
||||
continue
|
||||
steps.append({
|
||||
"scene": st.get("nodeId"), "stage": st.get("stage") or "UNKNOWN", "tint": st.get("tint"),
|
||||
"option": option_id(text), "optionText": text,
|
||||
"offered": [option_id(o.get("text") or o.get("norm")) for o in st.get("offered") or [] if o.get("text") or o.get("norm")],
|
||||
"rule": st.get("rule"), "decisionMode": "manual" if st.get("manual") else st.get("decisionMode"),
|
||||
"manual": bool(st.get("manual")), "at": st.get("at"), "seen": _seen(st.get("observed")),
|
||||
"propensity": st.get("propensity"), "to": _to(st.get("toKey")),
|
||||
})
|
||||
colour = str(r["dragonColor"]).lower() if r.get("dragonColor") else None
|
||||
return {
|
||||
"id": "bot-" + sha1(r["runId"], 10),
|
||||
"source": "bot",
|
||||
"meta": {"attempt": r.get("accountAttempt") or r.get("attempt"), "startedAt": r.get("startedAt"),
|
||||
"accountKey": account_key, "accountRole": r.get("accountRole"), "target": r.get("targetDragon"),
|
||||
"decisionMode": r.get("decisionMode"), "policyId": r.get("policyId"),
|
||||
"experimentId": r.get("experimentId"), "arm": r.get("arm")},
|
||||
"steps": steps,
|
||||
"outcome": {"type": r.get("outcome") or "ABORTED", "colour": colour, "intentional": bool(r.get("intentionalBurn")),
|
||||
"reason": (r.get("burn") or {}).get("reason")},
|
||||
}
|
||||
|
||||
|
||||
def _account_files(files):
|
||||
"""{account: {"runs": [...], "encounters": [...]}} from the packed files. The top-level files are the bot's
|
||||
original single account; data/accounts/<name>/ and logs/accounts/<name>/ hold one account each."""
|
||||
out = {}
|
||||
for rel, text in files.items():
|
||||
if text is None:
|
||||
continue
|
||||
parts = rel.split("/")
|
||||
acct = parts[2] if len(parts) == 4 and parts[1] == "accounts" else "(default)"
|
||||
kind = "runs" if rel.endswith("runs.jsonl") else "encounters" if rel.endswith("encounters.jsonl") else None
|
||||
if kind:
|
||||
out.setdefault(acct, {"runs": [], "encounters": []})[kind] += _jsonl(text)
|
||||
# since the bot keeps one folder per account, its top-level files mirror its first account (the same runs,
|
||||
# logged a moment apart): counting both would count those runs twice
|
||||
if len(out) > 1:
|
||||
out.pop("(default)", None)
|
||||
return out
|
||||
|
||||
|
||||
def account_salt(env, privacy):
|
||||
"""The salt that turns account names into anonymous keys: the environment variable if set, otherwise one made
|
||||
once and kept in the private raw store (data/raw/bot/account-salt.txt, never committed)."""
|
||||
salt = env.get(privacy.get("account_salt_env", ""))
|
||||
if salt:
|
||||
return salt
|
||||
from ..common import path
|
||||
import secrets
|
||||
p = path("data/raw/bot/account-salt.txt")
|
||||
if not p.exists():
|
||||
p.parent.mkdir(parents=True, exist_ok=True)
|
||||
p.write_text(secrets.token_hex(16), encoding="utf-8")
|
||||
return p.read_text(encoding="utf-8").strip()
|
||||
|
||||
|
||||
def transform(raw_path, spec, ctx):
|
||||
with open(raw_path, encoding="utf-8") as f:
|
||||
files = json.load(f)
|
||||
k = files.get("data/knowledge.json")
|
||||
knowledge = json.loads(k) if k else {"nodes": {}}
|
||||
encounters = _jsonl(files.get("logs/encounters.jsonl"))
|
||||
runs = _jsonl(files.get("data/runs.jsonl"))
|
||||
privacy = spec.get("privacy") or {}
|
||||
scenes, trajectories, unlabeled = import_bot(knowledge, encounters, runs, ctx.get("env", {}).get(privacy.get("account_salt_env", "")))
|
||||
salt = account_salt(ctx.get("env", {}), privacy)
|
||||
accounts = _account_files(files)
|
||||
all_encounters = [e for a in accounts.values() for e in a["encounters"]]
|
||||
scenes = build_scenes(knowledge, all_encounters)
|
||||
trajectories, seen_ids = [], set()
|
||||
for acct, data in sorted(accounts.items()):
|
||||
key = sha1(f"{salt}:{acct}", 10)
|
||||
with_steps = [r for r in data["runs"] if r.get("steps") and r.get("runId")]
|
||||
for r in with_steps:
|
||||
t = trajectory_from_run(r, key)
|
||||
if t["id"] not in seen_ids:
|
||||
seen_ids.add(t["id"])
|
||||
trajectories.append(t)
|
||||
# older runs without steps: rebuild them from the decision log, as before
|
||||
legacy = [r for r in data["runs"] if not r.get("steps")]
|
||||
window = SPEC["match_hours"] * 3600e3
|
||||
same_run = lambda t, r: (t["meta"]["attempt"] == (r.get("accountAttempt") or r.get("attempt")) # noqa: E731
|
||||
and abs(_ms(t["meta"]["startedAt"]) - _ms(r.get("startedAt"))) < window)
|
||||
old = attach_run_meta(trajectories_from_encounters(data["encounters"], scenes), legacy, salt)
|
||||
kept = []
|
||||
for t in old: # the decision log also holds the runs that have steps: keep only the others
|
||||
if any(same_run(t, r) for r in with_steps) or t["id"] in seen_ids:
|
||||
continue
|
||||
t["meta"]["accountKey"] = key
|
||||
seen_ids.add(t["id"])
|
||||
trajectories.append(t)
|
||||
kept.append(t)
|
||||
# bonded runs logged without any steps still say which dragon was bonded
|
||||
for r in legacy:
|
||||
if r.get("outcome") == "BONDED" and r.get("runId") and not any(same_run(t, r) for t in kept):
|
||||
t = trajectory_from_run({**r, "steps": []}, key)
|
||||
if t["id"] not in seen_ids:
|
||||
seen_ids.add(t["id"])
|
||||
trajectories.append(t)
|
||||
# scenes the run records show but the knowledge file does not have yet
|
||||
for t in trajectories:
|
||||
for st in t["steps"]:
|
||||
if st["scene"] and st["scene"] not in scenes:
|
||||
scenes[st["scene"]] = {"stage": st["stage"], "tint": st["tint"], "backdrop": None,
|
||||
"label": label_for(st["scene"], {"stage": st["stage"], "tint": st["tint"]}), "options": []}
|
||||
sc = scenes.get(st["scene"])
|
||||
if sc is not None and st["option"] not in {o["id"] for o in sc["options"]}:
|
||||
sc["options"].append({"id": st["option"], "text": st["optionText"]})
|
||||
unlabeled = [f"{sid} ({s['stage']}{', ' + s['tint'] if s['tint'] else ''})" for sid, s in scenes.items() if sid not in SPEC["labels"]]
|
||||
for obj in (scenes, trajectories):
|
||||
check_public(obj, set(privacy.get("refuse_fields", [])), privacy.get("max_string", 200))
|
||||
trajectories.sort(key=lambda t: (str(t["meta"].get("startedAt")), t["id"]))
|
||||
return {"scenes": scenes, "trajectories": trajectories, "_unlabeled": unlabeled}
|
||||
|
||||
|
||||
|
||||
@@ -66,11 +66,11 @@ sources:
|
||||
runs: reddit_results
|
||||
|
||||
reported:
|
||||
label: Runs reported on the Atlas ("Report a run", a GitHub issue form)
|
||||
label: Runs reported on the Atlas ("Report a run", an issue form on the Atlas's repository)
|
||||
run_source: reported
|
||||
links: { report: "https://github.com/ekcSchiano/threshing-atlas/issues/new?template=report-a-run.yml" }
|
||||
extract: { kind: github_issues, repo: ekcSchiano/threshing-atlas, label: run report, ext: json }
|
||||
# GitHub usernames are dropped; issues closed as "not planned" or labelled "invalid" are left out
|
||||
# the repository's host is forge.yaml (Gitea or GitHub); its "new issue" link is made from it
|
||||
extract: { kind: forge_issues, label: run report, ext: json }
|
||||
# usernames are dropped; issues closed as "not planned" (GitHub) or labelled invalid/duplicate are left out
|
||||
transform: { name: reports, form: collection/specs/report_form.yaml, reject_labels: [invalid, duplicate] }
|
||||
load: data/public/reports.json
|
||||
runs: reports
|
||||
@@ -79,10 +79,16 @@ sources:
|
||||
label: DragonKind bot runs (Ken's private bot, imported locally)
|
||||
run_source: bot
|
||||
# the bot's repo is private: this step runs only on a machine with a copy of it
|
||||
extract: { kind: local_dir, env: DRAGONKIND_BOT_DIR, files: [data/knowledge.json, data/runs.jsonl, logs/encounters.jsonl] }
|
||||
# data/accounts/<account>/ and logs/accounts/<account>/: one folder per game account (account names are
|
||||
# replaced by salted hashes); the top-level files are the bot's original single account
|
||||
extract:
|
||||
kind: local_dir
|
||||
env: DRAGONKIND_BOT_DIR
|
||||
files: [data/knowledge.json, data/runs.jsonl, logs/encounters.jsonl, data/accounts/*/runs.jsonl, logs/accounts/*/encounters.jsonl]
|
||||
transform: { name: bot, spec: collection/specs/bot.yaml }
|
||||
privacy:
|
||||
account_salt_env: DK_ACCOUNT_SALT # account ids are hashed with this salt, which is never committed
|
||||
account_salt_env: DK_ACCOUNT_SALT # account names are hashed with this salt (or, if unset, one kept in
|
||||
# data/raw/bot/account-salt.txt); never committed
|
||||
refuse_fields: [prose, proseNorm, proseExcerpt, email, password, accountId, accountName]
|
||||
max_string: 200 # anything longer looks like game prose
|
||||
load: data/bot # scenes.json (merged) + trajectories-<date>.jsonl
|
||||
|
||||
@@ -78,6 +78,8 @@ def build(check=False, report=None):
|
||||
out.append(report_form.TEMPLATE)
|
||||
if L.write_bytes(codegen.GRAPH_JS, codegen.graph_js().encode("utf-8"), check):
|
||||
out.append(codegen.GRAPH_JS)
|
||||
if L.json_file(codegen.LINKS, codegen.links(), check, compact=False):
|
||||
out.append(codegen.LINKS)
|
||||
# the metadata hashes the files above, so it is built from what is (or would be) on disk
|
||||
if not check or not out:
|
||||
if L.write_bytes(metadata.OUT, metadata.render(metadata.build()).encode("utf-8"), check):
|
||||
@@ -100,12 +102,17 @@ def main(argv=None):
|
||||
up.add_argument("--report")
|
||||
b = sub.add_parser("build")
|
||||
b.add_argument("--check", action="store_true")
|
||||
fg = sub.add_parser("forge", help="pull requests, issues and labels on the repository's host (forge.yaml)")
|
||||
fg.add_argument("args", nargs=argparse.REMAINDER)
|
||||
k = sub.add_parser("export-bot-kit", help="zip policy.json, solver.js and graph.js for the bot")
|
||||
k.add_argument("--out", default="exports")
|
||||
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)")
|
||||
a = ap.parse_args(argv)
|
||||
|
||||
if a.cmd == "forge":
|
||||
from .etl import forge
|
||||
return forge.main(a.args)
|
||||
if a.cmd == "export-bot-kit":
|
||||
from .etl.handoff import export_bot_kit
|
||||
print(f"wrote {export_bot_kit(a.out)}")
|
||||
|
||||
@@ -46,15 +46,20 @@ crosswalk:
|
||||
- ["^enter the valley alone", company, "Alone"]
|
||||
- ["^enter the valley with one of your squadmates", company, "1 Squadmate"]
|
||||
- ["^enter the valley with two of your squadmates", company, "2 Squadmates"]
|
||||
- ["^leave your squadmates?$", left_squadmates, true]
|
||||
- ["^head east toward the roar", direction, "East"]
|
||||
- ["^head west toward the scent", direction, "West"]
|
||||
- ["^head toward the center of the forest", direction, "Center"]
|
||||
# with squadmates, the direction is agreed with them
|
||||
- ["^go east with your squad|^convince them to head east", direction, "East"]
|
||||
- ["^go west with your squad|^convince them to head west", direction, "West"]
|
||||
- ["^keep walking the cadets are just as dangerous", scream, "Ignore the scream"]
|
||||
- ["^run and hope", sighting_action, "Retreat / run"]
|
||||
- ["hold still", sighting_action, "Hold still"]
|
||||
- ["hold still|hold your ground", sighting_action, "Hold still"]
|
||||
- ["lower your eyes in respect|lower your eyes and turn to face it", sighting_action, "Respect / face it"]
|
||||
- ["meeting its gaze", sighting_action, "Meet its gaze"]
|
||||
- ["^hide behind a tree", sighting_action, "Hide"]
|
||||
- ["^hide behind a tree|^duck behind a boulder", sighting_action, "Hide"]
|
||||
- ["^approach with confidence|^approach from the left", sighting_action, "Approach"]
|
||||
- ["^investigate the scream", scream_investigate, true]
|
||||
- ["^help your squadmate", scream, "Investigate & help"]
|
||||
- ["^play it safe and leave them", scream, "Investigate & leave"]
|
||||
@@ -68,14 +73,22 @@ crosswalk:
|
||||
- ["^leave the bullies alive", resolution, "Left bullies to the dragons"]
|
||||
- ["tourniquet", resolution, "Tourniquet"]
|
||||
# the wounded cadet's other two choices (the bot has not logged this screen yet, so these are kept loose)
|
||||
- ["leave (them|him|her) to die", resolution, "Left injured cadet"]
|
||||
- ["take (their|his|her) weapons?", resolution, "Took their weapons"]
|
||||
- ["leave (them|him|her) to die|^keep going clearly they've been found lacking", resolution, "Left injured cadet"]
|
||||
- ["take (their|his|her|the cadet's) weapons?", resolution, "Took their weapons"]
|
||||
- ["^walk toward the east", post_path, "East"]
|
||||
- ["^walk toward the west", post_path, "West"]
|
||||
- ["^walk farther into the forest", post_path, "Forest"]
|
||||
- ["^continue toward the center of the valley", hour, "Valley"]
|
||||
- ["^find the tallest tree", hour, "Tree"]
|
||||
# the Red in the valley centre
|
||||
- ["^there's no way this is your dragon", branch, "Passed the Red: meadow"]
|
||||
- ["^this is your dragon and it's time to start bonding", branch, "Valley Red"]
|
||||
- ["^descend quickly", branch, "Descend quickly: Red"]
|
||||
- ["^climb down slowly to pursue the green", branch, "Descend slowly: two Greens"]
|
||||
- ["^reds are too hot tempered", red, "Let it pass (two Greens)"]
|
||||
- ["^jump (now|in a few seconds)", red, "Jump onto the Red"]
|
||||
|
||||
# Route choices (before the hour) that no column of the coded runs has a value for; they are coded as unknown.
|
||||
# tests/collection/test_collection.py fails on any other unmapped route choice.
|
||||
not_coded:
|
||||
- "^stare at the ground and drop the weapon" # a first-sighting reaction with no form category
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# "Report a run": the questions of the GitHub issue form, and how each answer becomes a column of runs_clean.csv.
|
||||
# "Report a run": the questions of the issue form (on the Atlas's repository: forge.yaml), and how each answer becomes a column of runs_clean.csv.
|
||||
#
|
||||
# collection/etl/report_form.py writes .github/ISSUE_TEMPLATE/report-a-run.yml from this file (a test checks it is
|
||||
# up to date), and collection/etl/runs.py codes every report with it. Each option is "label shown: column value";
|
||||
@@ -11,7 +11,8 @@ title: "Run report"
|
||||
label: run report
|
||||
intro: |
|
||||
Thanks for reporting a run! Answer what you remember; leave anything you're unsure of on "Not sure".
|
||||
Every answer here is **public** (this is a GitHub issue) and goes into the Atlas's open data as source "reported".
|
||||
Every answer here is visible to everyone who can see this repository (it is an issue) and goes into the Atlas's
|
||||
open data as source "reported".
|
||||
Please don't include your DragonKind account name or anything personal.
|
||||
You can also use the community [Threshing Routes form](https://forms.gle/DRpj9tG8gb5E4Hcu7) linked from the r/fourthwing megathread; please report each run only once.
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
"""Reporting bias: some sources report a rare sighting more readily than a miss.
|
||||
|
||||
The bot logs every run, and bulk-pasted logs record every run of the players who kept them ("complete" groups).
|
||||
Form submissions and reports are chosen by the rider, and a run with a shadow or a meadow Blue is more likely to be
|
||||
written up than one without. For each rare roll and each selective group, the bias is the factor by which the
|
||||
group's odds of the rare outcome exceed the complete groups' odds:
|
||||
|
||||
rho = odds(rare | group) / odds(rare | complete groups)
|
||||
|
||||
Each rare outcome a group reports then counts 1/rho in the route model's tables. That keeps the group's pattern
|
||||
across routes and moves its overall level to what complete logging shows. The assumption: the bias is the same on
|
||||
every route (planner/policy.yaml says which groups, rolls and settings are used).
|
||||
"""
|
||||
import random
|
||||
|
||||
from . import model
|
||||
|
||||
|
||||
def group_of(r, groups, rare_goals):
|
||||
"""The first group in planner/policy.yaml whose condition the run meets."""
|
||||
for g in groups:
|
||||
w = g.get("when", {})
|
||||
if "source" in w and r.get("source") != w["source"]:
|
||||
continue
|
||||
if "entry_not" in w and r.get("entry") in (None, w["entry_not"]):
|
||||
continue
|
||||
if w.get("goal") == "rare" and r.get("goal") not in rare_goals:
|
||||
continue
|
||||
return g["name"]
|
||||
return None
|
||||
|
||||
|
||||
def _odds(y, n):
|
||||
p = (y + 0.5) / (n + 1) # Jeffreys
|
||||
return p / (1 - p)
|
||||
|
||||
|
||||
def estimate(runs, prepared, cfg, rare_goals, seed=20261109, sims=4000):
|
||||
"""{group: {roll: {rare, n, rho, lo, hi, used}}} and the group of every run."""
|
||||
groups = cfg["groups"]
|
||||
names = [group_of(r, groups, rare_goals) for r in runs]
|
||||
complete = {g["name"] for g in groups if g.get("complete")}
|
||||
rolls = cfg["rolls"]
|
||||
tally = {}
|
||||
for name, v in zip(names, prepared):
|
||||
for node, rare in rolls.items():
|
||||
y = model.OBSERVE[node](v)
|
||||
if y is None:
|
||||
continue
|
||||
t = tally.setdefault(name, {}).setdefault(node, [0, 0])
|
||||
t[0] += y == rare
|
||||
t[1] += 1
|
||||
ref = {node: [sum(tally.get(g, {}).get(node, [0, 0])[i] for g in complete) for i in (0, 1)] for node in rolls}
|
||||
rnd = random.Random(seed)
|
||||
out = {}
|
||||
for g in groups:
|
||||
name = g["name"]
|
||||
out[name] = {}
|
||||
for node in rolls:
|
||||
y, n = tally.get(name, {}).get(node, [0, 0])
|
||||
ry, rn = ref[node]
|
||||
e = {"rare": y, "n": n, "completeRare": ry, "completeN": rn}
|
||||
if g.get("complete"):
|
||||
e.update(rho=1.0, lo=1.0, hi=1.0, used="complete: counted as reported")
|
||||
elif ry < cfg.get("min_complete_rare", 5):
|
||||
# complete logging has (almost) never seen it: the bias cannot be estimated, so this roll is learned
|
||||
# from complete logging only (its range then shows how little is known)
|
||||
e.update(rho=None, lo=None, hi=None, exclude=True,
|
||||
used=f"left out: complete logs have only {ry} rare outcomes, too few to estimate the bias")
|
||||
elif n < cfg.get("min_runs", 30) or rn < cfg.get("min_runs", 30):
|
||||
e.update(rho=None, used=f"too few runs: uses {g.get('same_as') or 'no correction'}")
|
||||
else:
|
||||
rho = _odds(y, n) / _odds(ry, rn)
|
||||
sim = [] # a 90% range for rho from the two rates' posteriors
|
||||
for _ in range(sims):
|
||||
a = rnd.betavariate(y + 0.5, n - y + 0.5)
|
||||
b = rnd.betavariate(ry + 0.5, rn - ry + 0.5)
|
||||
sim.append((a / (1 - a)) / (b / (1 - b)))
|
||||
sim.sort()
|
||||
e.update(rho=rho, lo=sim[int(0.05 * sims)], hi=sim[int(0.95 * sims) - 1], used="estimated")
|
||||
out[name][node] = e
|
||||
# groups with too little data borrow another group's estimate
|
||||
for g in groups:
|
||||
for node in rolls:
|
||||
e = out[g["name"]][node]
|
||||
if e.get("rho") is None and not e.get("exclude"):
|
||||
src = out.get(g.get("same_as") or "", {}).get(node, {})
|
||||
e["rho"] = src.get("rho") or 1.0
|
||||
e["lo"], e["hi"] = src.get("lo", e["rho"]), src.get("hi", e["rho"])
|
||||
return out, names
|
||||
|
||||
|
||||
def weights(names, prepared, est, rolls):
|
||||
"""Per run: {roll: weight of the outcome it observed}: 1/rho for a rare outcome from a biased group, 0 for any
|
||||
outcome of a roll its group is left out of. Only where it differs from 1."""
|
||||
out = []
|
||||
for name, v in zip(names, prepared):
|
||||
w = {}
|
||||
for node, rare in rolls.items():
|
||||
e = (est.get(name) or {}).get(node, {})
|
||||
y = model.OBSERVE[node](v)
|
||||
if y is None:
|
||||
continue
|
||||
if e.get("exclude"):
|
||||
w[node] = 0.0
|
||||
elif y == rare and (e.get("rho") or 1.0) != 1.0:
|
||||
w[node] = 1.0 / e["rho"]
|
||||
out.append(w)
|
||||
return out
|
||||
+47
-10
@@ -69,7 +69,14 @@ def prepare_run(r):
|
||||
v["diedSight"] = r["scream"] == "DIED at first sighting"
|
||||
if v["diedSight"]:
|
||||
return v
|
||||
if r["scream"] not in ("Investigate & help", "Ignore the scream", "Investigate & leave"):
|
||||
v["sightUnknown"] = True # no answer after the first dragon: whether the rider survived it is not known
|
||||
return v
|
||||
res = r["resolution"]
|
||||
# the choices at the scream, by their names in game.yaml (gates are written with these)
|
||||
v["scream"] = "Keep walking" if r["scream"] == "Ignore the scream" else "Investigate the scream"
|
||||
if r["scream"] in ("Investigate & help", "Investigate & leave"):
|
||||
v["clearing"] = "Help your squadmate" if r["scream"] == "Investigate & help" else "Walk away"
|
||||
if r["scream"] == "Investigate & help":
|
||||
v["help"] = True
|
||||
v["fight"] = FIGHT_OF.get(r.get("combat_first"))
|
||||
@@ -113,7 +120,9 @@ def prepare_run(r):
|
||||
ended = lambda c: r.get("enc_" + c) and r.get("enc_" + c) != "Changed my mind" # noqa: E731
|
||||
v["meadow"] = "Blue" if (r.get("enc_Blue") or r.get("rare_reported") == "Blue (valley)") else \
|
||||
"Orange" if ended("Orange") else "Brown" if ended("Brown") else \
|
||||
"Orange" if r.get("enc_Orange") else "Brown" if r.get("enc_Brown") else None
|
||||
"Orange" if r.get("enc_Orange") else "Brown" if r.get("enc_Brown") else \
|
||||
"Blue" if r.get("saw_blue_meadow") is True else \
|
||||
r["outcome_color"] if r.get("saw_blue_meadow") is False and r.get("outcome_color") in ("Orange", "Brown") else None
|
||||
if v["meadow"]:
|
||||
v["encCtx"] = "meadow-" + v["meadow"]
|
||||
if v.get("encCtx"):
|
||||
@@ -124,13 +133,19 @@ def prepare_run(r):
|
||||
return v
|
||||
|
||||
|
||||
# what each chance event observed in a prepared run
|
||||
def gate_open(node, state):
|
||||
"""Whether a gated roll (game.yaml `requires`) can come out any other way than `otherwise`."""
|
||||
req = CHANCE[node].get("requires") or {}
|
||||
return all(state.get(k) == v for k, v in req.items())
|
||||
|
||||
|
||||
# what each chance event observed in a prepared run (a gated roll only where its gate was open)
|
||||
OBSERVE = {
|
||||
"fs": lambda v: v.get("fs"),
|
||||
"dieSight": lambda v: ("die" if v.get("diedSight") else "live") if v.get("fs") else None,
|
||||
"dieSight": lambda v: ("die" if v.get("diedSight") else "live") if v.get("fs") and not v.get("sightUnknown") else None,
|
||||
"dieCombat": lambda v: ("die" if v.get("diedCombat") else "live") if v.get("help") else None,
|
||||
"dieHour": lambda v: ("die" if v.get("diedHour") else "live") if v.get("survivedCadets") else None,
|
||||
"shadow": lambda v: None if "shadow" not in v else ("yes" if v["shadow"] else "no"),
|
||||
"shadow": lambda v: None if "shadow" not in v or not gate_open("shadow", v) else ("yes" if v["shadow"] else "no"),
|
||||
"shadowColour": lambda v: v.get("shadowColour"),
|
||||
"meadow": lambda v: v.get("meadow"),
|
||||
}
|
||||
@@ -143,31 +158,46 @@ def ctx_key(v, names):
|
||||
|
||||
# ---------------------------------------------------------------- 2. counts
|
||||
|
||||
def count_tables(prepared):
|
||||
"""Counts for every chance event at every back-off level, plus each encounter's outcomes."""
|
||||
def can_bond(ctx, colour):
|
||||
"""Whether a bond with this colour is possible at this encounter (game.yaml `encounters`)."""
|
||||
e = G["encounters"][ctx]
|
||||
return colour == "burn" or colour == e["colour"] or colour in (e.get("also") or [])
|
||||
|
||||
|
||||
def count_tables(prepared, weights=None):
|
||||
"""Counts for every chance event at every back-off level, plus each encounter's outcomes. weights: per run,
|
||||
{chance event: weight of the outcome it observed} (reporting-bias corrections, core/atlas/bias.py)."""
|
||||
T = {}
|
||||
for node, sp in CHANCE.items():
|
||||
t = T[node] = {}
|
||||
for v in prepared:
|
||||
for i, v in enumerate(prepared):
|
||||
y = OBSERVE[node](v)
|
||||
if not y:
|
||||
continue
|
||||
w = weights[i].get(node, 1) if weights else 1
|
||||
if w == 0:
|
||||
continue
|
||||
for L in range(len(sp["context"]) + 1):
|
||||
names = sp["context"][:L]
|
||||
if any(v.get(k) is None for k in names):
|
||||
break
|
||||
c = t.setdefault(f"{L}:{ctx_key(v, names)}", {})
|
||||
c[y] = c.get(y, 0) + 1
|
||||
c[y] = c.get(y, 0) + w
|
||||
for t in T.values(): # weighted counts are fractions: keep them short and stable
|
||||
for c in t.values():
|
||||
for k, x in c.items():
|
||||
if isinstance(x, float):
|
||||
c[k] = round(x, 4)
|
||||
enc = T["encounter"] = {}
|
||||
for v in prepared:
|
||||
if not v.get("encCtx"):
|
||||
continue
|
||||
c = enc.setdefault(v["encCtx"], {"outcomes": {}, "seen": {}})
|
||||
if v.get("encOutcome"):
|
||||
if v.get("encOutcome") and can_bond(v["encCtx"], v["encOutcome"]):
|
||||
c["outcomes"][v["encOutcome"]] = c["outcomes"].get(v["encOutcome"], 0) + 1
|
||||
# which colours can ever end a run in this context (from all runs, genuine or not)
|
||||
for v in prepared:
|
||||
if v.get("encCtx") and v.get("encOutcome") and v["encOutcome"] != "burn":
|
||||
if v.get("encCtx") and v.get("encOutcome") and v["encOutcome"] != "burn" and can_bond(v["encCtx"], v["encOutcome"]):
|
||||
enc[v["encCtx"]]["seen"][v["encOutcome"]] = 1
|
||||
return T
|
||||
|
||||
@@ -256,6 +286,10 @@ def fit_alpha(T, node):
|
||||
pairs.append(([t[key].get(k, 0) for k in cats], pooled(parent)))
|
||||
if not pairs:
|
||||
return {"alpha": ALPHA, "logLik": None}
|
||||
# a roll that has only ever come out one way says nothing about whether routes differ: pool fully (the fit
|
||||
# would otherwise drive every route's chance of the unseen outcome to zero)
|
||||
if sum(1 for k in cats if t.get("0:", {}).get(k, 0) > 0) < 2:
|
||||
return {"alpha": max(ALPHA_GRID), "logLik": None}
|
||||
best_a, best_ll, lls = ALPHA, -math.inf, {}
|
||||
for a in ALPHA_GRID:
|
||||
ll = 0
|
||||
@@ -371,6 +405,9 @@ class Params:
|
||||
return self.memo[mk]
|
||||
|
||||
def chance(self, node, state):
|
||||
if not gate_open(node, state): # a closed gate: the roll always comes out the same way
|
||||
other = CHANCE[node]["otherwise"]
|
||||
return {k: np.full(self.D, 1.0 if k == other else 0.0) for k in CHANCE[node]["outcomes"]}
|
||||
# once every world has been drawn, the answer depends only on the context values: cache it
|
||||
ck = (node, tuple(state.get(k) for k in CHANCE[node]["context"]))
|
||||
if self.world is None and ck in self._cache:
|
||||
|
||||
+13
-4
@@ -311,12 +311,18 @@ def summarise(xs):
|
||||
|
||||
# ---------------------------------------------------------------- the published policy
|
||||
|
||||
def build_policy(runs, draws=200, seed=20261101, min_support=None, alpha=None, colours=None):
|
||||
"""The full policy for every colour. runs: coded runs (atlas.coding), as dicts."""
|
||||
def build_policy(runs, draws=200, seed=20261101, min_support=None, alpha=None, colours=None, bias_config=None):
|
||||
"""The full policy for every colour. runs: coded runs (data/public/runs_clean.csv), as dicts. bias_config:
|
||||
planner/policy.yaml `reporting_bias` (None: every run counts as reported)."""
|
||||
colours = colours or model.COLOURS
|
||||
min_support = G["min_support"] if min_support is None else min_support
|
||||
prepared = [model.prepare_run(r) for r in runs]
|
||||
T = model.count_tables(prepared)
|
||||
bias_est, w = None, None
|
||||
if bias_config:
|
||||
from . import bias
|
||||
bias_est, names = bias.estimate(runs, prepared, bias_config, set(model.RARE_GOALS))
|
||||
w = bias.weights(names, prepared, bias_est, bias_config["rolls"])
|
||||
T = model.count_tables(prepared, w)
|
||||
support, counts = model.support_from(prepared, min_support)
|
||||
fitted = {k: model.fit_alpha(T, k) for k in model.CHANCE}
|
||||
alphas = {k: alpha for k in model.CHANCE} if alpha else {k: f["alpha"] for k, f in fitted.items()}
|
||||
@@ -325,7 +331,8 @@ def build_policy(runs, draws=200, seed=20261101, min_support=None, alpha=None, c
|
||||
# Cross-fitting: choose the policy on one random half of the runs and score it on the other half.
|
||||
r = model.Rng(seed)
|
||||
fold = [0 if r() < 0.5 else 1 for _ in prepared]
|
||||
halves = [model.count_tables([v for v, f in zip(prepared, fold) if f == h]) for h in (0, 1)]
|
||||
halves = [model.count_tables([v for v, f in zip(prepared, fold) if f == h],
|
||||
[x for x, f in zip(w, fold) if f == h] if w else None) for h in (0, 1)]
|
||||
half_params = [model.Params(Th, "mean", alphas=alphas) for Th in halves]
|
||||
|
||||
targets = {}
|
||||
@@ -366,6 +373,8 @@ def build_policy(runs, draws=200, seed=20261101, min_support=None, alpha=None, c
|
||||
"chanceContext": {k: s["context"] for k, s in model.CHANCE.items()},
|
||||
"decisions": model.DECISIONS, "support": support, "supportCounts": counts,
|
||||
"tables": T,
|
||||
# how much each kind of source over-reports each rare roll, and the correction applied (bias.py)
|
||||
"reportingBias": bias_est,
|
||||
# the game itself (core/spec/game.yaml), so the advisor in core/solver.js can re-solve from any point
|
||||
"game": {k: G[k] for k in ("version", "colours", "decisions", "chance", "encounters", "encounter_outcomes",
|
||||
"by_colour", "start", "steps", "from_form", "bot_text")},
|
||||
|
||||
+10
-4
@@ -84,15 +84,19 @@
|
||||
[/^enter the valley alone/, "company", "Alone"],
|
||||
[/^enter the valley with one of your squadmates/, "company", "1 Squadmate"],
|
||||
[/^enter the valley with two of your squadmates/, "company", "2 Squadmates"],
|
||||
[/^leave your squadmates?$/, "left_squadmates", true],
|
||||
[/^head east toward the roar/, "direction", "East"],
|
||||
[/^head west toward the scent/, "direction", "West"],
|
||||
[/^head toward the center of the forest/, "direction", "Center"],
|
||||
[/^go east with your squad|^convince them to head east/, "direction", "East"],
|
||||
[/^go west with your squad|^convince them to head west/, "direction", "West"],
|
||||
[/^keep walking the cadets are just as dangerous/, "scream", "Ignore the scream"],
|
||||
[/^run and hope/, "sighting_action", "Retreat / run"],
|
||||
[/hold still/, "sighting_action", "Hold still"],
|
||||
[/hold still|hold your ground/, "sighting_action", "Hold still"],
|
||||
[/lower your eyes in respect|lower your eyes and turn to face it/, "sighting_action", "Respect / face it"],
|
||||
[/meeting its gaze/, "sighting_action", "Meet its gaze"],
|
||||
[/^hide behind a tree/, "sighting_action", "Hide"],
|
||||
[/^hide behind a tree|^duck behind a boulder/, "sighting_action", "Hide"],
|
||||
[/^approach with confidence|^approach from the left/, "sighting_action", "Approach"],
|
||||
[/^investigate the scream/, "scream_investigate", true],
|
||||
[/^help your squadmate/, "scream", "Investigate & help"],
|
||||
[/^play it safe and leave them/, "scream", "Investigate & leave"],
|
||||
@@ -105,13 +109,15 @@
|
||||
[/^allow your squadmate to exact/, "resolution", "Squadmate's revenge"],
|
||||
[/^leave the bullies alive/, "resolution", "Left bullies to the dragons"],
|
||||
[/tourniquet/, "resolution", "Tourniquet"],
|
||||
[/leave (them|him|her) to die/, "resolution", "Left injured cadet"],
|
||||
[/take (their|his|her) weapons?/, "resolution", "Took their weapons"],
|
||||
[/leave (them|him|her) to die|^keep going clearly they've been found lacking/, "resolution", "Left injured cadet"],
|
||||
[/take (their|his|her|the cadet's) weapons?/, "resolution", "Took their weapons"],
|
||||
[/^walk toward the east/, "post_path", "East"],
|
||||
[/^walk toward the west/, "post_path", "West"],
|
||||
[/^walk farther into the forest/, "post_path", "Forest"],
|
||||
[/^continue toward the center of the valley/, "hour", "Valley"],
|
||||
[/^find the tallest tree/, "hour", "Tree"],
|
||||
[/^there's no way this is your dragon/, "branch", "Passed the Red: meadow"],
|
||||
[/^this is your dragon and it's time to start bonding/, "branch", "Valley Red"],
|
||||
[/^descend quickly/, "branch", "Descend quickly: Red"],
|
||||
[/^climb down slowly to pursue the green/, "branch", "Descend slowly: two Greens"],
|
||||
[/^reds are too hot tempered/, "red", "Let it pass (two Greens)"],
|
||||
|
||||
+54
-14
@@ -24,12 +24,39 @@
|
||||
const encColour = (ctx) => (ctx === "tree-Greens" ? "Green" : ctx.split("-")[1]);
|
||||
const api = {};
|
||||
|
||||
/* ---------- the odds: posterior means with hierarchical back-off (as in core/atlas/model.py) ---------- */
|
||||
function makeParams(T, { alphas = {}, game }) {
|
||||
/* ---------- posterior draws, for Thompson sampling ---------- */
|
||||
function rng(seed) {
|
||||
let x = (seed >>> 0) || 0x9e3779b9;
|
||||
return () => { x ^= x << 13; x >>>= 0; x ^= x >>> 17; x ^= x << 5; x >>>= 0; return (x + 0.5) / 4294967296; };
|
||||
}
|
||||
function normal(rand) { return Math.sqrt(-2 * Math.log(rand())) * Math.cos(2 * Math.PI * rand()); }
|
||||
function gamma(k, rand) { // Marsaglia and Tsang
|
||||
if (k < 1) return gamma(k + 1, rand) * Math.pow(rand(), 1 / k);
|
||||
const d = k - 1 / 3, c = 1 / Math.sqrt(9 * d);
|
||||
for (;;) {
|
||||
let x, v;
|
||||
do { x = normal(rand); v = 1 + c * x; } while (v <= 0);
|
||||
v = v * v * v;
|
||||
const u = rand();
|
||||
if (u < 1 - 0.0331 * x ** 4 || Math.log(u) < 0.5 * x * x + d * (1 - v + Math.log(v))) return d * v;
|
||||
}
|
||||
}
|
||||
function dirichlet(a, rand) {
|
||||
const g = a.map((x) => Math.max(gamma(x, rand), 1e-300));
|
||||
let s = 0; for (const x of g) s += x;
|
||||
return g.map((x) => x / s);
|
||||
}
|
||||
|
||||
/* ---------- the odds: posterior means (or, with rand, one posterior draw) with hierarchical back-off ---------- */
|
||||
function makeParams(T, { alphas = {}, game, rand = null }) {
|
||||
const normalise = (a) => { let sum = 0; for (const x of a) sum += x; return a.map((x) => x / sum); };
|
||||
const estimate = rand ? (a) => dirichlet(a, rand) : normalise;
|
||||
const memo = new Map();
|
||||
const ctxKey = (s, names) => names.map((k) => (s[k] == null ? "?" : s[k])).join("|");
|
||||
function chance(node, state) {
|
||||
const sp = game.chance[node], cats = sp.outcomes;
|
||||
// a closed gate (game.yaml `requires`): the roll always comes out as `otherwise`
|
||||
if (sp.requires && Object.entries(sp.requires).some(([k, v]) => state[k] !== v)) return Object.fromEntries(cats.map((k) => [k, k === sp.otherwise ? 1 : 0]));
|
||||
let p = null;
|
||||
for (let L = 0; L <= sp.context.length; L++) {
|
||||
const names = sp.context.slice(0, L);
|
||||
@@ -38,8 +65,7 @@
|
||||
if (memo.has(mk)) { p = memo.get(mk); continue; }
|
||||
const c = T[node][key] || {}, al = alphas[node] || ALPHA;
|
||||
const a = cats.map((k, i) => (c[k] || 0) + (p ? al * p[i] : 0.5));
|
||||
let sum = 0; for (const x of a) sum += x;
|
||||
p = a.map((x) => x / sum);
|
||||
p = estimate(a);
|
||||
memo.set(mk, p);
|
||||
}
|
||||
return Object.fromEntries(cats.map((k, i) => [k, p[i]]));
|
||||
@@ -49,9 +75,8 @@
|
||||
if (!memo.has(mk)) {
|
||||
const e = T.encounter[ctx] || { outcomes: {}, seen: {} };
|
||||
const cats = game.encounter_outcomes.filter((k) => k === "burn" || e.seen[k] || (e.outcomes[k] || 0) > 0 || k === encColour(ctx));
|
||||
const a = cats.map((k) => (e.outcomes[k] || 0) + 0.5);
|
||||
let sum = 0; for (const x of a) sum += x;
|
||||
memo.set(mk, Object.fromEntries(cats.map((k, i) => [k, a[i] / sum])));
|
||||
const a = estimate(cats.map((k) => (e.outcomes[k] || 0) + 0.5));
|
||||
memo.set(mk, Object.fromEntries(cats.map((k, i) => [k, a[i]])));
|
||||
}
|
||||
return memo.get(mk);
|
||||
}
|
||||
@@ -149,17 +174,31 @@
|
||||
* the deadly roll just passed on the step after it. When h already has a later step but skips an earlier
|
||||
* decision (an older form record, say), the recommended option is assumed for the skipped one.
|
||||
*/
|
||||
function advisor(sample, X, objective = "eventually", { only = null } = {}) {
|
||||
function advisor(sample, X, objective = "eventually", { only = null, sampling = "best", seed = 1, draws = 40 } = {}) {
|
||||
const m = sample.model, game = m.game;
|
||||
api.game = game; api.ENCOUNTERS = game.by_colour;
|
||||
const params = makeParams(m.tables, { alphas: m.alphas, game });
|
||||
const sol = objective === "eventually" ? solveRatio(params, game, m.support, X, only) : solve(params, game, m.support, X, 0, only);
|
||||
const solveWith = (params) => (objective === "eventually" ? solveRatio(params, game, m.support, X, only) : solve(params, game, m.support, X, 0, only));
|
||||
// "best": the best route under the posterior means. "thompson": the best route of one posterior draw of the odds
|
||||
// (one per attempt: make a new advisor with a new seed for each attempt), so every option is tried about as
|
||||
// often as it is likely to be the best one; as the data firm up, sampling settles on the best route.
|
||||
const thompson = sampling === "thompson";
|
||||
const params = makeParams(m.tables, { alphas: m.alphas, game, rand: thompson ? rng(seed) : null });
|
||||
const sol = solveWith(params);
|
||||
// the chance Thompson sampling picks each option at a history, estimated from `draws` other draws: the
|
||||
// propensity to log, so the runs can be re-weighted later
|
||||
let worlds = null;
|
||||
const propensityAt = (key, choice) => {
|
||||
if (!thompson) return 1;
|
||||
if (!worlds) worlds = Array.from({ length: draws }, (_, i) => solveWith(makeParams(m.tables, { alphas: m.alphas, game, rand: rng(seed * 7919 + i + 1) })).choices);
|
||||
return worlds.filter((c) => c.get(key) === choice).length / draws;
|
||||
};
|
||||
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) || {};
|
||||
return { kind: "decision", var: name, label: label(name), choice: sol.choices.get(key),
|
||||
const choice = sol.choices.get(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 };
|
||||
};
|
||||
|
||||
@@ -197,13 +236,13 @@
|
||||
throw new Error("the game has no end");
|
||||
}
|
||||
return {
|
||||
colour: X, objective, only, value: sol.value, step, params, game,
|
||||
colour: X, objective, only, sampling, seed: thompson ? seed : null, value: sol.value, step, params, game,
|
||||
/** attempts recorded at an encounter (genuine attempts only), to show how much data a bond chance rests on */
|
||||
attempts: (ctx) => Object.values(((m.tables.encounter || {})[ctx] || { outcomes: {} }).outcomes).reduce((a, b) => a + b, 0),
|
||||
/** 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, options: s.options } : null;
|
||||
return s.kind === "decision" ? { decision: s.var, label: s.label, choice: s.choice, propensity: s.propensity, options: s.options } : null;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -222,7 +261,8 @@
|
||||
const pat = ((adv.game.bot_text || {})[rec.decision] || {})[rec.choice];
|
||||
const idx = pat ? offered.map(norm).findIndex((t) => new RegExp(pat).test(t)) : -1;
|
||||
const values = Object.values(rec.options).map((v) => v.pX).sort((a, b) => b - a);
|
||||
return { index: idx < 0 ? null : idx, decision: rec.decision, choice: rec.choice, margin: values.length > 1 ? values[0] - values[1] : null,
|
||||
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,
|
||||
reason: idx < 0 && rec.decision !== "encounter" ? "the recommended choice is not on this screen; use the bot's own rules" : `${rec.label}: ${rec.choice}` };
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ answers:
|
||||
"Respect / Face it": "Respect / face it"
|
||||
"Retreat / Run / Back Away": "Retreat / run"
|
||||
"Hide / Duck": "Hide"
|
||||
"Protect / Help Squadmate": "Protect squadmate"
|
||||
"Draw / Drop Weapon": "Weapon"
|
||||
"Meet Gaze": "Meet its gaze"
|
||||
"Protect / Help Sqaudmate": "Protect squadmate"
|
||||
|
||||
+14
-4
@@ -48,22 +48,32 @@ min_support: 20
|
||||
# ---------------------------------------------------------------- chance events: the game's rolls
|
||||
# outcomes: in a fixed order. context: the earlier steps the odds may depend on, most important first; the
|
||||
# estimate for a full context is shrunk toward the estimate for a shorter one (hierarchical Dirichlet back-off,
|
||||
# strength learned from the data).
|
||||
# strength learned from the data). requires: earlier choices without which the roll always comes out as
|
||||
# `otherwise` (a gate); runs that did not make them say nothing about the roll and are not counted.
|
||||
chance:
|
||||
fs: { label: First dragon, outcomes: [Red, Brown, Green, Orange], context: [direction, company, left] }
|
||||
# rolls that can kill you: risk_label names the danger when the advisor reports it
|
||||
dieSight: { label: Survive the first dragon, outcomes: [die, live], context: [fs, direction, company, left, react], risk_label: Killed at the first sighting }
|
||||
dieCombat: { label: Survive the fight, outcomes: [die, live], context: [fight, dagger, fs, direction], risk_label: Killed in the fight }
|
||||
dieHour: { label: Survive the hour, outcomes: [die, live], context: [cadet, post], risk_label: Killed before the hour }
|
||||
shadow: { label: Shadow at the tree, outcomes: ["yes", "no"], context: [cadet, post, fs, direction, company] }
|
||||
shadow:
|
||||
label: Shadow at the tree
|
||||
outcomes: ["yes", "no"]
|
||||
context: [cadet, post, fs, direction, company]
|
||||
# the "Black Dragon Gates" of the community route PDF (November 2026). The runs agree: in the spreadsheet,
|
||||
# 78 shadows in 4199 tree runs that investigated and helped, 2 (both form submissions) in 646 that did not.
|
||||
requires: { scream: Investigate the scream, clearing: Help your squadmate }
|
||||
otherwise: "no"
|
||||
shadowColour: { label: Shadow dragon, outcomes: [Black, Blue], context: [] }
|
||||
meadow: { label: Meadow dragon, outcomes: [Orange, Brown, Blue], context: [cadet, post, fs, direction, company] }
|
||||
|
||||
# Bonding encounters: where each colour can be bonded. tree-Greens can also end in an Orange or Brown rescue.
|
||||
# Bonding encounters: where each colour can be bonded. A run can only bond the encounter's own colour, except at
|
||||
# the two Greens, where an Orange or a Brown can swoop in (`also`). A recorded bond with any other colour is a
|
||||
# data-entry error and is not counted.
|
||||
encounters:
|
||||
valley-Red: { label: The valley Red, colour: Red }
|
||||
tree-Red: { label: The Red below the tree, colour: Red }
|
||||
tree-Greens: { label: The two Greens, colour: Green }
|
||||
tree-Greens: { label: The two Greens, colour: Green, also: [Orange, Brown] }
|
||||
meadow-Orange: { label: The meadow Orange, colour: Orange }
|
||||
meadow-Brown: { label: The meadow Brown, colour: Brown }
|
||||
meadow-Blue: { label: The meadow Blue, colour: Blue }
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
{
|
||||
"01c36238ed4d": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": "red",
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST · red",
|
||||
"options": [
|
||||
{
|
||||
"id": "8815af6f63",
|
||||
"text": "There’s no way this is your dragon and you need to get out of here"
|
||||
},
|
||||
{
|
||||
"id": "ec479648fd",
|
||||
"text": "This is your dragon and it’s time to start bonding"
|
||||
}
|
||||
]
|
||||
},
|
||||
"07e24681e3b3": {
|
||||
"stage": "TREE_SHADOW_CHECK",
|
||||
"tint": "green",
|
||||
@@ -19,6 +35,22 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"0905c924562b": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": null,
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST",
|
||||
"options": [
|
||||
{
|
||||
"id": "fad9b2b701",
|
||||
"text": "Approach the orange dragon"
|
||||
},
|
||||
{
|
||||
"id": "4003505565",
|
||||
"text": "Approach the brown dragon"
|
||||
}
|
||||
]
|
||||
},
|
||||
"0a561d53ad19": {
|
||||
"stage": "THORN_WALK",
|
||||
"tint": null,
|
||||
@@ -75,6 +107,202 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"13673f2461a1": {
|
||||
"stage": "SCREAM_AND_CADETS",
|
||||
"tint": null,
|
||||
"backdrop": "forest",
|
||||
"label": "SCREAM_AND_CADETS",
|
||||
"options": [
|
||||
{
|
||||
"id": "1477a0f34f",
|
||||
"text": "Keep going. Clearly they’ve been found lacking and weak riders threaten the wing"
|
||||
},
|
||||
{
|
||||
"id": "2de42c6660",
|
||||
"text": "Take the cadet’s weapons and continue along your way. Good steel shouldn’t go to waste"
|
||||
},
|
||||
{
|
||||
"id": "8cf4b0cf60",
|
||||
"text": "Use the cadet’s own belt as a tourniquet to staunch the blood flow and wait for a wingleader to come along"
|
||||
}
|
||||
]
|
||||
},
|
||||
"3f5d4c880fa9": {
|
||||
"stage": "MEADOW_ENCOUNTER",
|
||||
"tint": "brown",
|
||||
"backdrop": "clearing",
|
||||
"label": "MEADOW_ENCOUNTER · brown",
|
||||
"options": [
|
||||
{
|
||||
"id": "f1aaea7f76",
|
||||
"text": "You point out that it’s already talking to you, so clearly you’re on the right track"
|
||||
},
|
||||
{
|
||||
"id": "ef5d1b474e",
|
||||
"text": "You’ll respect its decision and hope for a clean death"
|
||||
},
|
||||
{
|
||||
"id": "aed44971b9",
|
||||
"text": "You’ll convince it with charm"
|
||||
}
|
||||
]
|
||||
},
|
||||
"4118582c85df": {
|
||||
"stage": "TARGET_BONDING",
|
||||
"tint": "blue",
|
||||
"backdrop": "clearing",
|
||||
"label": "TARGET_BONDING · blue",
|
||||
"options": [
|
||||
{
|
||||
"id": "7d7788a891",
|
||||
"text": "Hold the blue’s glare and advance"
|
||||
},
|
||||
{
|
||||
"id": "06a35668b0",
|
||||
"text": "Keep moving forward with your eyes lowered"
|
||||
},
|
||||
{
|
||||
"id": "6a855c9d5c",
|
||||
"text": "Halt your approach and lower your eyes"
|
||||
}
|
||||
]
|
||||
},
|
||||
"4f4ae4c4e49a": {
|
||||
"stage": "MEADOW_ENCOUNTER",
|
||||
"tint": "orange",
|
||||
"backdrop": "clearing",
|
||||
"label": "MEADOW_ENCOUNTER · orange",
|
||||
"options": [
|
||||
{
|
||||
"id": "c95309baca",
|
||||
"text": "Take a chance and try a tail-mount"
|
||||
}
|
||||
]
|
||||
},
|
||||
"545578ddbe46": {
|
||||
"stage": "ENTER_THRESHING",
|
||||
"tint": null,
|
||||
"backdrop": "forest",
|
||||
"label": "ENTER_THRESHING",
|
||||
"options": [
|
||||
{
|
||||
"id": "1147432132",
|
||||
"text": "Convince them to head east instead"
|
||||
},
|
||||
{
|
||||
"id": "5501c1635f",
|
||||
"text": "Go west with your squadmate"
|
||||
},
|
||||
{
|
||||
"id": "81dae2ed4f",
|
||||
"text": "Leave your squadmate"
|
||||
}
|
||||
]
|
||||
},
|
||||
"5b2713be89b2": {
|
||||
"stage": "MEADOW_ENCOUNTER",
|
||||
"tint": "orange",
|
||||
"backdrop": "clearing",
|
||||
"label": "MEADOW_ENCOUNTER · orange",
|
||||
"options": [
|
||||
{
|
||||
"id": "31b348db0c",
|
||||
"text": "On second thought, a nice brown sounds great"
|
||||
},
|
||||
{
|
||||
"id": "900576c438",
|
||||
"text": "Absolutely. I have a feeling this is my dragon"
|
||||
}
|
||||
]
|
||||
},
|
||||
"5ddaca4ebf6c": {
|
||||
"stage": "TARGET_BONDING",
|
||||
"tint": "blue",
|
||||
"backdrop": "clearing",
|
||||
"label": "TARGET_BONDING · blue",
|
||||
"options": [
|
||||
{
|
||||
"id": "3f99a5c45d",
|
||||
"text": "Do nothing. It’s worked so far"
|
||||
},
|
||||
{
|
||||
"id": "b67f49441d",
|
||||
"text": "Speak first, claiming the dragon as yours"
|
||||
},
|
||||
{
|
||||
"id": "8d768b0ef2",
|
||||
"text": "Straighten your spine and wait for it to speak"
|
||||
}
|
||||
]
|
||||
},
|
||||
"69c5b0e2b790": {
|
||||
"stage": "ENTER_THRESHING",
|
||||
"tint": "orange",
|
||||
"backdrop": "forest",
|
||||
"label": "ENTER_THRESHING · orange",
|
||||
"options": [
|
||||
{
|
||||
"id": "a137e8047c",
|
||||
"text": "Duck behind a boulder"
|
||||
},
|
||||
{
|
||||
"id": "b98b30e96d",
|
||||
"text": "Lower your eyes in respect and retreat"
|
||||
},
|
||||
{
|
||||
"id": "ddad2bafb4",
|
||||
"text": "Approach with confidence"
|
||||
}
|
||||
]
|
||||
},
|
||||
"6b8a5625b88d": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": "red",
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST · red",
|
||||
"options": [
|
||||
{
|
||||
"id": "1a981e7715",
|
||||
"text": "You’re absolutely sure"
|
||||
},
|
||||
{
|
||||
"id": "e99d6c3481",
|
||||
"text": "On second thought, let’s get out of here"
|
||||
}
|
||||
]
|
||||
},
|
||||
"78afc925529f": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": "brown",
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST · brown",
|
||||
"options": [
|
||||
{
|
||||
"id": "b2a9ecfcd0",
|
||||
"text": "Ehh. On second thought, maybe it won’t see if you change direction"
|
||||
},
|
||||
{
|
||||
"id": "70a4f53a6d",
|
||||
"text": "You’re sure. The heart doesn’t lie, and it’s set on that brown"
|
||||
}
|
||||
]
|
||||
},
|
||||
"792fc5ad90c3": {
|
||||
"stage": "MEADOW_ENCOUNTER",
|
||||
"tint": "brown",
|
||||
"backdrop": "clearing",
|
||||
"label": "MEADOW_ENCOUNTER · brown",
|
||||
"options": [
|
||||
{
|
||||
"id": "b4d31960c6",
|
||||
"text": "Immediately throw your body weight onto the tail and hold on for dear life"
|
||||
},
|
||||
{
|
||||
"id": "732901a659",
|
||||
"text": "Wait for the tail to return for a more advantageous angle"
|
||||
}
|
||||
]
|
||||
},
|
||||
"84780dab01e3": {
|
||||
"stage": "FIRST_SIGHTING",
|
||||
"tint": "red",
|
||||
@@ -87,6 +315,62 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"848f03f8f298": {
|
||||
"stage": "TARGET_BONDING",
|
||||
"tint": "blue",
|
||||
"backdrop": "clearing",
|
||||
"label": "TARGET_BONDING · blue",
|
||||
"options": [
|
||||
{
|
||||
"id": "7d771616e4",
|
||||
"text": "No. I have better odds with the orange"
|
||||
},
|
||||
{
|
||||
"id": "78b3ba405f",
|
||||
"text": "Absolutely. My whole life hinges on this moment"
|
||||
},
|
||||
{
|
||||
"id": "f0e858698f",
|
||||
"text": "Nope. I’d rather live bonded to a brown than die pursuing a blue"
|
||||
}
|
||||
]
|
||||
},
|
||||
"900d49229a84": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": null,
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST",
|
||||
"options": [
|
||||
{
|
||||
"id": "4003505565",
|
||||
"text": "Approach the brown dragon"
|
||||
},
|
||||
{
|
||||
"id": "fad9b2b701",
|
||||
"text": "Approach the orange dragon"
|
||||
},
|
||||
{
|
||||
"id": "4bbcb73ed1",
|
||||
"text": "Approach the blue dragon"
|
||||
}
|
||||
]
|
||||
},
|
||||
"959e965095c3": {
|
||||
"stage": "TARGET_BONDING",
|
||||
"tint": "blue",
|
||||
"backdrop": "clearing",
|
||||
"label": "TARGET_BONDING · blue",
|
||||
"options": [
|
||||
{
|
||||
"id": "0f1d136c69",
|
||||
"text": "Launch yourself to the right, taking cover behind a boulder"
|
||||
},
|
||||
{
|
||||
"id": "442a0fc4eb",
|
||||
"text": "Hold steady, fear will get you killed"
|
||||
}
|
||||
]
|
||||
},
|
||||
"96b68612eaf4": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": null,
|
||||
@@ -103,6 +387,22 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"9dc9518d8c84": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": "green",
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST · green",
|
||||
"options": [
|
||||
{
|
||||
"id": "fe2406af4e",
|
||||
"text": "Glance over at the dragon on the right, keeping situational awareness"
|
||||
},
|
||||
{
|
||||
"id": "6c7e2bb27b",
|
||||
"text": "Don’t move a muscle"
|
||||
}
|
||||
]
|
||||
},
|
||||
"a2368b0dc212": {
|
||||
"stage": "SCREAM_AND_CADETS",
|
||||
"tint": null,
|
||||
@@ -143,6 +443,26 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"ab2da0553abf": {
|
||||
"stage": "ENTER_THRESHING",
|
||||
"tint": null,
|
||||
"backdrop": "forest",
|
||||
"label": "ENTER_THRESHING",
|
||||
"options": [
|
||||
{
|
||||
"id": "44095be371",
|
||||
"text": "Go east with your squad"
|
||||
},
|
||||
{
|
||||
"id": "eaf6e41387",
|
||||
"text": "Leave your squadmates"
|
||||
},
|
||||
{
|
||||
"id": "55fe423f15",
|
||||
"text": "Convince them to head west instead"
|
||||
}
|
||||
]
|
||||
},
|
||||
"abe3011378ac": {
|
||||
"stage": "ENTER_THRESHING",
|
||||
"tint": "brown",
|
||||
@@ -163,6 +483,22 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"afc48a9ae27f": {
|
||||
"stage": "TARGET_BONDING",
|
||||
"tint": "blue",
|
||||
"backdrop": "clearing",
|
||||
"label": "TARGET_BONDING · blue",
|
||||
"options": [
|
||||
{
|
||||
"id": "bdbd932924",
|
||||
"text": "Do nothing"
|
||||
},
|
||||
{
|
||||
"id": "5a76aa2e2f",
|
||||
"text": "Intervene and help"
|
||||
}
|
||||
]
|
||||
},
|
||||
"b209bacacec3": {
|
||||
"stage": "SCREAM_AND_CADETS",
|
||||
"tint": null,
|
||||
@@ -183,6 +519,90 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"b637d4115786": {
|
||||
"stage": "ENTER_THRESHING",
|
||||
"tint": "green",
|
||||
"backdrop": "forest",
|
||||
"label": "ENTER_THRESHING · green",
|
||||
"options": [
|
||||
{
|
||||
"id": "ad4f3fb6f4",
|
||||
"text": "Lower your eyes and hold your ground"
|
||||
},
|
||||
{
|
||||
"id": "911bbead41",
|
||||
"text": "Approach from the left"
|
||||
},
|
||||
{
|
||||
"id": "04c3fb524d",
|
||||
"text": "Stare at the ground and drop the weapon"
|
||||
}
|
||||
]
|
||||
},
|
||||
"b7e1483dd17a": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": "green",
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST · green",
|
||||
"options": [
|
||||
{
|
||||
"id": "fbc43edf79",
|
||||
"text": "You overextend yourself constantly"
|
||||
},
|
||||
{
|
||||
"id": "cda997fd10",
|
||||
"text": "Your lack of flaws is a flaw itself"
|
||||
},
|
||||
{
|
||||
"id": "8bd1cc6042",
|
||||
"text": "You’re pretty certain you’re always right… even when you’re wrong"
|
||||
},
|
||||
{
|
||||
"id": "92e06f9e6b",
|
||||
"text": "Your struggle with your temper"
|
||||
}
|
||||
]
|
||||
},
|
||||
"b98aff0fa16a": {
|
||||
"stage": "TARGET_BONDING",
|
||||
"tint": "blue",
|
||||
"backdrop": "clearing",
|
||||
"label": "TARGET_BONDING · blue",
|
||||
"options": [
|
||||
{
|
||||
"id": "6bde02709a",
|
||||
"text": "Seize the opportunity to mount"
|
||||
},
|
||||
{
|
||||
"id": "f93b47698d",
|
||||
"text": "Stand strong, waiting for an invitation"
|
||||
},
|
||||
{
|
||||
"id": "7d564d5caf",
|
||||
"text": "Move forward slowly, waiting for an invitation"
|
||||
}
|
||||
]
|
||||
},
|
||||
"bbc8a53dc679": {
|
||||
"stage": "ENTER_THRESHING",
|
||||
"tint": null,
|
||||
"backdrop": "forest",
|
||||
"label": "ENTER_THRESHING",
|
||||
"options": [
|
||||
{
|
||||
"id": "05d19abb5d",
|
||||
"text": "Head toward the center of the forest"
|
||||
},
|
||||
{
|
||||
"id": "5f7eefac34",
|
||||
"text": "Head east toward the roar"
|
||||
},
|
||||
{
|
||||
"id": "9c613e0d47",
|
||||
"text": "Head west toward the scent"
|
||||
}
|
||||
]
|
||||
},
|
||||
"bc4ee4754b9c": {
|
||||
"stage": "ENTER_THRESHING",
|
||||
"tint": "red",
|
||||
@@ -259,6 +679,58 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"ea9997720545": {
|
||||
"stage": "TARGET_BONDING",
|
||||
"tint": "blue",
|
||||
"backdrop": "clearing",
|
||||
"label": "TARGET_BONDING · blue",
|
||||
"options": [
|
||||
{
|
||||
"id": "ea7c0027e7",
|
||||
"text": "Lower your eyes for the cadet’s dignity"
|
||||
},
|
||||
{
|
||||
"id": "973f57cd35",
|
||||
"text": "Show your honor by helping the cadet"
|
||||
},
|
||||
{
|
||||
"id": "80e3020dea",
|
||||
"text": "Hold the dragon’s glare and watch as it crushes the cadet to death"
|
||||
}
|
||||
]
|
||||
},
|
||||
"f0fb1451568a": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": "green",
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST · green",
|
||||
"options": [
|
||||
{
|
||||
"id": "6e46acb832",
|
||||
"text": "Don’t move a muscle. Holding your ground is imperative"
|
||||
},
|
||||
{
|
||||
"id": "f50fb7bd4c",
|
||||
"text": "Take a single step back. Getting speared won’t get you bonded"
|
||||
}
|
||||
]
|
||||
},
|
||||
"f0fc086c6590": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": "red",
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST · red",
|
||||
"options": [
|
||||
{
|
||||
"id": "871b243a92",
|
||||
"text": "Continue your approach. You’re certain this is your path"
|
||||
},
|
||||
{
|
||||
"id": "8e79717d1b",
|
||||
"text": "That growl changes everything, and it’s time to exit gracefully"
|
||||
}
|
||||
]
|
||||
},
|
||||
"f4b4944d3f3b": {
|
||||
"stage": "SCREAM_AND_CADETS",
|
||||
"tint": null,
|
||||
@@ -295,6 +767,46 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"f82683b20f3b": {
|
||||
"stage": "FORK_IN_FOREST",
|
||||
"tint": "brown",
|
||||
"backdrop": "clearing",
|
||||
"label": "FORK_IN_FOREST · brown",
|
||||
"options": [
|
||||
{
|
||||
"id": "8b53b3dfbf",
|
||||
"text": "Run after the brown dragon"
|
||||
},
|
||||
{
|
||||
"id": "939b596a85",
|
||||
"text": "Try your luck with the remaining orange"
|
||||
}
|
||||
]
|
||||
},
|
||||
"f8b8d90014f1": {
|
||||
"stage": "TARGET_BONDING",
|
||||
"tint": "blue",
|
||||
"backdrop": "clearing",
|
||||
"label": "TARGET_BONDING · blue",
|
||||
"options": [
|
||||
{
|
||||
"id": "1437cd23ea",
|
||||
"text": "I want to bring down an empire"
|
||||
},
|
||||
{
|
||||
"id": "2237667d16",
|
||||
"text": "You already know"
|
||||
},
|
||||
{
|
||||
"id": "cf4766824b",
|
||||
"text": "I seek revenge"
|
||||
},
|
||||
{
|
||||
"id": "16ca950973",
|
||||
"text": "I want to defend the helpless"
|
||||
}
|
||||
]
|
||||
},
|
||||
"fbe0f0bea700": {
|
||||
"stage": "SCREAM_AND_CADETS",
|
||||
"tint": null,
|
||||
|
||||
File diff suppressed because one or more lines are too long
+39
-30
@@ -46,13 +46,12 @@
|
||||
"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://ekcschiano.github.io/threshing-atlas/",
|
||||
"sameAs": "https://github.com/ekcSchiano/threshing-atlas",
|
||||
"url": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas",
|
||||
"sameAs": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas",
|
||||
"license": "https://creativecommons.org/licenses/by/4.0/",
|
||||
"creator": {
|
||||
"@type": "sc:Person",
|
||||
"name": "ekcSchiano",
|
||||
"url": "https://github.com/ekcSchiano"
|
||||
"name": "ekcSchiano"
|
||||
},
|
||||
"keywords": [
|
||||
"Dragonkind",
|
||||
@@ -62,7 +61,7 @@
|
||||
"route planning",
|
||||
"community data"
|
||||
],
|
||||
"citeAs": "ekcSchiano and contributors (2026). Threshing Atlas. https://github.com/ekcSchiano/threshing-atlas",
|
||||
"citeAs": "ekcSchiano and contributors (2026). Threshing Atlas. https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas",
|
||||
"isLiveDataset": true,
|
||||
"isBasedOn": [
|
||||
{
|
||||
@@ -79,11 +78,6 @@
|
||||
"@type": "sc:CreativeWork",
|
||||
"name": "Runs posted in the r/fourthwing Dragonkind megathreads",
|
||||
"url": "https://www.reddit.com/r/fourthwing/comments/1wvwfp9/"
|
||||
},
|
||||
{
|
||||
"@type": "sc:CreativeWork",
|
||||
"name": "Runs reported on the Atlas (\"Report a run\", a GitHub issue form)",
|
||||
"url": "https://github.com/ekcSchiano/threshing-atlas/issues/new?template=report-a-run.yml"
|
||||
}
|
||||
],
|
||||
"distribution": [
|
||||
@@ -92,27 +86,27 @@
|
||||
"@id": "runs_clean",
|
||||
"name": "runs_clean",
|
||||
"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://ekcschiano.github.io/threshing-atlas/data/runs_clean.csv",
|
||||
"contentUrl": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas/raw/branch/main/data/public/runs_clean.csv",
|
||||
"encodingFormat": "text/csv",
|
||||
"sha256": "766d8708dad77327534063df42cd4ff806ab707497618ab5263cf3dce98a30c7",
|
||||
"contentSize": "2146368 B"
|
||||
"sha256": "cbca1afd189a1c86b400015177a40eba14256994e880ec19b14307bb5310011b",
|
||||
"contentSize": "3033793 B"
|
||||
},
|
||||
{
|
||||
"@type": "cr:FileObject",
|
||||
"@id": "form_responses",
|
||||
"name": "form_responses",
|
||||
"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://github.com/ekcSchiano/threshing-atlas/blob/main/data/public/form_responses.json",
|
||||
"contentUrl": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas/raw/branch/main/data/public/form_responses.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "4c5791f78ce81f5e88f1fb99d933acd06d8223ff9a573e96b6fcb3a6fd9c8d22",
|
||||
"contentSize": "8293395 B"
|
||||
"sha256": "7ca72f9967a9b15fd52160106b1508c8cfbde804539d6afa3f04df326d7bf2b2",
|
||||
"contentSize": "11019524 B"
|
||||
},
|
||||
{
|
||||
"@type": "cr:FileObject",
|
||||
"@id": "reports",
|
||||
"name": "reports",
|
||||
"description": "Runs reported through the Atlas's \"Report a run\" form (GitHub issues), answers only, no usernames.",
|
||||
"contentUrl": "https://github.com/ekcSchiano/threshing-atlas/blob/main/data/public/reports.json",
|
||||
"description": "Runs reported through the Atlas's \"Report a run\" form (issues on its repository), answers only, no usernames.",
|
||||
"contentUrl": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas/raw/branch/main/data/public/reports.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "d42eb04b9923eb1d2a8e5c356452f52daab78293be5a29a448cfb69c974eab30",
|
||||
"contentSize": "92 B"
|
||||
@@ -122,40 +116,40 @@
|
||||
"@id": "register",
|
||||
"name": "register",
|
||||
"description": "The Unofficial Dragon Register (which dragon each rider bonded), without rider names.",
|
||||
"contentUrl": "https://ekcschiano.github.io/threshing-atlas/data/register.json",
|
||||
"contentUrl": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas/raw/branch/main/data/public/register.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "f889c7e18068a934eb6872efda9b43599f4870d2e42bfdb3d447405976d59df8",
|
||||
"contentSize": "111095 B"
|
||||
"sha256": "b55e62a7be1d2f8858bc3bf0ad35881bbcd87f61a634f219f2b2bea5a453ff58",
|
||||
"contentSize": "116221 B"
|
||||
},
|
||||
{
|
||||
"@type": "cr:FileObject",
|
||||
"@id": "stats",
|
||||
"name": "stats",
|
||||
"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://ekcschiano.github.io/threshing-atlas/data/stats.json",
|
||||
"contentUrl": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas/raw/branch/main/data/public/stats.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "dc79c0762e5c27423f9fa2086f06aa7019b0aec6ae41d6a6dcbe59a1016cffab",
|
||||
"contentSize": "4269546 B"
|
||||
"sha256": "aa3b1eb313655b75c290f538373b72b1a29b4685f389feabea487b333c0f96a6",
|
||||
"contentSize": "5063942 B"
|
||||
},
|
||||
{
|
||||
"@type": "cr:FileObject",
|
||||
"@id": "policy",
|
||||
"name": "policy",
|
||||
"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://ekcschiano.github.io/threshing-atlas/data/policy.json",
|
||||
"contentUrl": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas/raw/branch/main/data/public/policy.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "26c3adad2236493b4a77b7d46454fe01c84e8f750f0f03b6e7dbe968af32ea4e",
|
||||
"contentSize": "617892 B"
|
||||
"sha256": "156c8ac049db20ecbc32cdfa4ea9054bb1575770073d82b1614bd14dfd45b257",
|
||||
"contentSize": "599165 B"
|
||||
},
|
||||
{
|
||||
"@type": "cr:FileObject",
|
||||
"@id": "graph",
|
||||
"name": "graph",
|
||||
"description": "The route graph over every run in runs_clean.csv, counted per source (analysis/network/build-graph.js).",
|
||||
"contentUrl": "https://ekcschiano.github.io/threshing-atlas/data/graph.json",
|
||||
"contentUrl": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas/raw/branch/main/data/public/graph.json",
|
||||
"encodingFormat": "application/json",
|
||||
"sha256": "72ef6fa6d6edc3a53026eff3f9cf39a883f7a709eacaaf21351c9ca1251a986a",
|
||||
"contentSize": "48783 B"
|
||||
"sha256": "80df43b82f1fa14d14c4b8af46fb32849deadc4e8220379ee8dcc3ba83de30cc",
|
||||
"contentSize": "73346 B"
|
||||
}
|
||||
],
|
||||
"recordSet": [
|
||||
@@ -213,6 +207,21 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "cr:Field",
|
||||
"@id": "runs/bot_mode",
|
||||
"name": "bot_mode",
|
||||
"description": "For bot runs, how the bot chose: \"auto_learn\" (its own rules and the route PDF), \"atlas_policy\" (the Atlas's route model), \"atlas_thompson\" (the route model, sampling routes in proportion to how likely each is best), \"explore\" (trying untested options), \"experiment\" (a randomised test), \"manual\" (a person clicked). Matters for analysis: the bot follows a strategy, so its choices are not like a player's. Empty for other sources. Values: auto_learn; atlas_policy; atlas_thompson; explore; experiment; manual.",
|
||||
"dataType": "sc:Text",
|
||||
"source": {
|
||||
"fileObject": {
|
||||
"@id": "runs_clean"
|
||||
},
|
||||
"extract": {
|
||||
"column": "bot_mode"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "cr:Field",
|
||||
"@id": "runs/date",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"sha256": "1c1b2b4e27c673cae4070a6abf57dbfbe98ab0f4b43b3d7232741a23612c490c",
|
||||
"bytes": 633332,
|
||||
"sha256": "3778ece486c7fca9b38f1738e7065ba20d7b1fd739bcd1b845d46e7520e3a22e",
|
||||
"bytes": 641363,
|
||||
"pages": 1,
|
||||
"page_hashes": [
|
||||
"d3b0a8d99799997a"
|
||||
"e88c846a14efc549"
|
||||
],
|
||||
"line_hashes": [
|
||||
"0005ef79b6b0",
|
||||
@@ -38,6 +38,7 @@
|
||||
"0e5021c854fd",
|
||||
"0fa4700b553a",
|
||||
"0fb542ca6733",
|
||||
"1060c135e592",
|
||||
"106a5842fc5f",
|
||||
"115b5cad43c0",
|
||||
"119a95345c45",
|
||||
@@ -46,6 +47,7 @@
|
||||
"14558e7e73c8",
|
||||
"14e2d4c37b5b",
|
||||
"1584dc810a09",
|
||||
"16367aacb67a",
|
||||
"16477688c0e0",
|
||||
"16486a0e2e7e",
|
||||
"16552853f950",
|
||||
@@ -58,8 +60,8 @@
|
||||
"1a1d05853cee",
|
||||
"1aefe47e20eb",
|
||||
"1b4c9133da73",
|
||||
"1de5fa381999",
|
||||
"1fa9e3998e8b",
|
||||
"1fbdd6f48a30",
|
||||
"20539cda4fc1",
|
||||
"208a6d1ce0de",
|
||||
"21499b8293b5",
|
||||
@@ -88,6 +90,7 @@
|
||||
"2f251aff0a77",
|
||||
"2f501595d6f2",
|
||||
"2f63258bd7ea",
|
||||
"2f80077a0788",
|
||||
"2f943c163229",
|
||||
"2fe14cd5feca",
|
||||
"306a70a396b4",
|
||||
@@ -132,6 +135,7 @@
|
||||
"41f20dee5da8",
|
||||
"429e5436f520",
|
||||
"42a21ed159ef",
|
||||
"42ff6957f0a3",
|
||||
"447048356f8c",
|
||||
"453962996160",
|
||||
"45847b618b88",
|
||||
@@ -212,6 +216,7 @@
|
||||
"743b4e8706ef",
|
||||
"7488af2a0881",
|
||||
"75ad72417087",
|
||||
"75fdd9027b0a",
|
||||
"7692c3ad3540",
|
||||
"76a796208b71",
|
||||
"771b94c11b83",
|
||||
@@ -260,6 +265,7 @@
|
||||
"935f14ac67b6",
|
||||
"94844cb129a8",
|
||||
"94ab1f4a7216",
|
||||
"954f0ca1b653",
|
||||
"95a14ed2a7fc",
|
||||
"95d77302ee47",
|
||||
"961836168b5b",
|
||||
@@ -285,6 +291,7 @@
|
||||
"a060335c66cf",
|
||||
"a093d3f5ecff",
|
||||
"a0f941fee4c0",
|
||||
"a2972765764c",
|
||||
"a2a92faf51c6",
|
||||
"a35c9fb774e6",
|
||||
"a36373ed77ba",
|
||||
@@ -295,6 +302,7 @@
|
||||
"a69a4139b340",
|
||||
"a6e0a42de76e",
|
||||
"a6e8ab03915b",
|
||||
"a7937b64b8ca",
|
||||
"a7cdf72224c0",
|
||||
"a7dbeb539e04",
|
||||
"a854942a3868",
|
||||
@@ -337,16 +345,19 @@
|
||||
"b4fbbe802d67",
|
||||
"b5afeb8db3aa",
|
||||
"b627f4168840",
|
||||
"b724cc07becf",
|
||||
"b7bd4220ff85",
|
||||
"b8ab74d65421",
|
||||
"b8b0e7effd20",
|
||||
"b9514000c923",
|
||||
"b95206531cb4",
|
||||
"ba4788b226aa",
|
||||
"bac081e175b0",
|
||||
"bb0e505c6386",
|
||||
"bb36f57782ca",
|
||||
"bb6db2fb1f33",
|
||||
"bb8b9de8437d",
|
||||
"bd2f2e2ce114",
|
||||
"bc807bf2a135",
|
||||
"be5ba8fe14a3",
|
||||
"bec9019352b4",
|
||||
"bf1563e43ef8",
|
||||
@@ -373,6 +384,7 @@
|
||||
"c98e94e2a5f1",
|
||||
"caa6a9ced701",
|
||||
"cb28392914d1",
|
||||
"cc2e668bb959",
|
||||
"cca94b79f1f1",
|
||||
"cd1bb3012bcf",
|
||||
"ce8371563887",
|
||||
@@ -393,7 +405,6 @@
|
||||
"d413d29b87df",
|
||||
"d4536f255583",
|
||||
"d5a0d90574d5",
|
||||
"d611fd25b98f",
|
||||
"d61483fb5f57",
|
||||
"d76d5e7a3df7",
|
||||
"d88c2c2a6831",
|
||||
@@ -433,6 +444,7 @@
|
||||
"e5a05ee2bbba",
|
||||
"e644b77bfa11",
|
||||
"e6c66d78c859",
|
||||
"e6e6263ada92",
|
||||
"e76566a6d54c",
|
||||
"e774d221fc45",
|
||||
"e7c0d9c5bc32",
|
||||
@@ -463,7 +475,6 @@
|
||||
"f4909e20a51e",
|
||||
"f51563619474",
|
||||
"f6a4807a956f",
|
||||
"f6e897aa0150",
|
||||
"f70b7769ae02",
|
||||
"f763b9be2dc9",
|
||||
"f8c25133ee80",
|
||||
@@ -474,10 +485,11 @@
|
||||
"fbd161e2c059",
|
||||
"fca413c36342",
|
||||
"fd5cd809e2aa",
|
||||
"fdbbfc2be926",
|
||||
"fe4c73974e0e",
|
||||
"ff06886f82e3",
|
||||
"ff1f017072cc",
|
||||
"ffe503ead4e4"
|
||||
],
|
||||
"checked": "2026-11-03"
|
||||
"checked": "2026-11-10"
|
||||
}
|
||||
+11
-9
@@ -14,19 +14,17 @@ dataset:
|
||||
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://ekcschiano.github.io/threshing-atlas/
|
||||
repository: https://github.com/ekcSchiano/threshing-atlas
|
||||
# the repository, the page and every file's link come from forge.yaml
|
||||
license: https://creativecommons.org/licenses/by/4.0/
|
||||
code_license: MIT
|
||||
creator: ekcSchiano
|
||||
keywords: [Dragonkind, Fourth Wing, threshing, decision tree, route planning, community data]
|
||||
citation: "ekcSchiano and contributors (2026). Threshing Atlas. https://github.com/ekcSchiano/threshing-atlas"
|
||||
citation: "ekcSchiano and contributors (2026). Threshing Atlas. {repository}"
|
||||
# Third-party sources keep their own terms (DATA_LICENSE.md); the route PDF is never redistributed.
|
||||
|
||||
files:
|
||||
runs_clean:
|
||||
path: data/public/runs_clean.csv
|
||||
url: https://ekcschiano.github.io/threshing-atlas/data/runs_clean.csv
|
||||
format: text/csv
|
||||
description: >-
|
||||
Every run from every source, one per row, coded into the same columns (collection/etl/runs.py; the form's
|
||||
@@ -40,29 +38,25 @@ files:
|
||||
reports:
|
||||
path: data/public/reports.json
|
||||
format: application/json
|
||||
description: Runs reported through the Atlas's "Report a run" form (GitHub issues), answers only, no usernames.
|
||||
description: Runs reported through the Atlas's "Report a run" form (issues on its repository), answers only, no usernames.
|
||||
register:
|
||||
path: data/public/register.json
|
||||
url: https://ekcschiano.github.io/threshing-atlas/data/register.json
|
||||
format: application/json
|
||||
description: The Unofficial Dragon Register (which dragon each rider bonded), without rider names.
|
||||
stats:
|
||||
path: data/public/stats.json
|
||||
url: https://ekcschiano.github.io/threshing-atlas/data/stats.json
|
||||
format: application/json
|
||||
description: >-
|
||||
Every number the Atlas page shows, for six filter presets (analysis/stats/site_stats.py; what is measured is
|
||||
analysis/stats/measures.yaml).
|
||||
policy:
|
||||
path: data/public/policy.json
|
||||
url: https://ekcschiano.github.io/threshing-atlas/data/policy.json
|
||||
format: application/json
|
||||
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).
|
||||
graph:
|
||||
path: data/public/graph.json
|
||||
url: https://ekcschiano.github.io/threshing-atlas/data/graph.json
|
||||
format: application/json
|
||||
description: The route graph over every run in runs_clean.csv, counted per source (analysis/network/build-graph.js).
|
||||
|
||||
@@ -87,6 +81,14 @@ columns:
|
||||
bulk-pasted logs keep the label they were pasted with. Bulk logs record every run of the players who kept
|
||||
them, so they are the least selectively reported rows. Empty for other sources.
|
||||
values: [Form, Data Import, BulkUpload3, Manual Upload, Historical import, Unknown import]
|
||||
bot_mode:
|
||||
type: text
|
||||
description: >-
|
||||
For bot runs, how the bot chose: "auto_learn" (its own rules and the route PDF), "atlas_policy" (the Atlas's
|
||||
route model), "atlas_thompson" (the route model, sampling routes in proportion to how likely each is best), "explore" (trying untested options), "experiment" (a randomised test), "manual" (a person
|
||||
clicked). Matters for analysis: the bot follows a strategy, so its choices are not like a player's. Empty for
|
||||
other sources.
|
||||
values: [auto_learn, atlas_policy, atlas_thompson, explore, experiment, manual]
|
||||
date: { type: date, description: "Date of the run or its report (YYYY-MM-DD): the form submission, the issue, or the bot attempt. Empty for bulk-pasted rows and result pages." }
|
||||
wing: { type: text, description: The rider's wing, from the form., values: [First, Second, Third, Fourth, Multiple, Unknown] }
|
||||
section: { type: text, description: The rider's section within the wing (free text as answered). }
|
||||
|
||||
+17
-2
@@ -1,9 +1,24 @@
|
||||
{
|
||||
"bot": {
|
||||
"sha256": "e7e6a3245170dba7320eab98d9721e6c1174e16143c4bb2ed827dc84f1eda00f",
|
||||
"bytes": 149013,
|
||||
"sha256": "fc3fbf23e39d29985d73a4693824c9b9bbadfc5b86361f8f5bd160aad094b1df",
|
||||
"bytes": 11742294,
|
||||
"changed": "2026-11-10"
|
||||
},
|
||||
"reddit_pdf": {
|
||||
"sha256": "3778ece486c7fca9b38f1738e7065ba20d7b1fd739bcd1b845d46e7520e3a22e",
|
||||
"bytes": 641363,
|
||||
"changed": "2026-11-10"
|
||||
},
|
||||
"reddit_spreadsheet": {
|
||||
"sha256": "97377c3c3cfc9756a3520580441111d5154642e224441e35754f021c701a46fd",
|
||||
"bytes": 4695125,
|
||||
"changed": "2026-11-12"
|
||||
},
|
||||
"register": {
|
||||
"sha256": "1a4e98f3a140015f8849c2ff5f3c1635def12614ad60461b8213dcb3b3b420a2",
|
||||
"bytes": 50431,
|
||||
"changed": "2026-11-12"
|
||||
},
|
||||
"reported": {
|
||||
"sha256": "4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945",
|
||||
"bytes": 2,
|
||||
|
||||
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,10 @@
|
||||
{
|
||||
"repo": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas",
|
||||
"repo_label": "git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas",
|
||||
"host": "git.kenschiano.net",
|
||||
"kind": "gitea",
|
||||
"visibility": "limited",
|
||||
"report": "https://git.kenschiano.net/YOUR-GITEA-USERNAME/threshing-atlas/issues/new?template=.github/ISSUE_TEMPLATE/report-a-run.yml",
|
||||
"form": "https://forms.gle/DRpj9tG8gb5E4Hcu7",
|
||||
"sheet": "https://docs.google.com/spreadsheets/d/1gnw1AdRg1XT4JsOfRM6QTA0jSaS3n9ZF-rPWnYewzv0"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+8573
-6017
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
+58
-10
@@ -9,14 +9,32 @@ Data flows both ways:
|
||||
└──────────── collection --source bot + PR ◄┘
|
||||
```
|
||||
|
||||
## Without GitHub: swapping zips
|
||||
## From the Atlas's Gitea repository
|
||||
|
||||
Both repositories live on git.kenschiano.net. The bot can read the atlas files straight from the repository with a
|
||||
Gitea token that can read it (the repository is "limited": signed-in users only), instead of a zip:
|
||||
|
||||
```
|
||||
https://git.kenschiano.net/<owner>/threshing-atlas/raw/branch/main/data/public/policy.json
|
||||
https://git.kenschiano.net/<owner>/threshing-atlas/raw/branch/main/core/solver.js
|
||||
https://git.kenschiano.net/<owner>/threshing-atlas/raw/branch/main/core/graph.js
|
||||
```
|
||||
|
||||
(header `Authorization: token <token>`). Keep the three files together: solver.js reads the game from policy.json.
|
||||
|
||||
## Without a shared repository: swapping zips
|
||||
|
||||
When GitHub Pages is not available, the same files travel as zips:
|
||||
|
||||
- **Atlas → bot:** `python -m collection export-bot-kit` writes `exports/atlas-for-bot-<date>-<policy id>.zip`
|
||||
(`policy.json`, `solver.js`, `graph.js`, a README with checksums). Unzip it into the bot's `vendor/threshing-atlas/`.
|
||||
- **Bot → atlas:** zip the bot's `data/runs.jsonl`, `data/knowledge.json` and `logs/encounters.jsonl` (folder names
|
||||
kept; a zip of the whole repo works too) and send it. Put it in the atlas's `inbox/` and run
|
||||
- **Bot → atlas:** zip the bot's `data/` and `logs/` folders (folder names kept; a zip of the whole repo works too;
|
||||
screenshots are not needed) and send it. The importer reads `data/knowledge.json` and, for every account,
|
||||
`data/accounts/<account>/runs.jsonl` and `logs/accounts/<account>/encounters.jsonl` (with one folder per
|
||||
account, the top-level `data/runs.jsonl` and `logs/encounters.jsonl` mirror the first account and are skipped).
|
||||
Run records that carry their own steps (the bot's schema 2) are used as they are, including what the bot saw
|
||||
(shadow, meadow dragons), its decision mode and the policy id; older runs are rebuilt from the decision log.
|
||||
Account names become salted hashes. Put it in the atlas's `inbox/` and run
|
||||
`python -m collection refresh --bot inbox/<the zip>`: it imports the runs (anonymised: no prose, no account names),
|
||||
rebuilds everything, and then `export-bot-kit` makes the new zip to send back.
|
||||
|
||||
@@ -120,12 +138,33 @@ The atlas is advice. The bot's own safety rules stay in charge:
|
||||
Log every atlas pick with `rule: 'ATLAS_POLICY'`, `source: 'atlas'`, and the run-level `policyId: policy.id`
|
||||
(see `docs/BOT_DATA_PROTOCOL.md`), so we can tell which policy produced which runs.
|
||||
|
||||
### Ties are free experiments
|
||||
### Learning: goal accounts follow the best route, research accounts sample
|
||||
|
||||
Many choices barely matter by the data we have (for Black, the first direction differs by a tenth of a percentage
|
||||
point). When `margin` is below the tie threshold (start with 0.002, i.e. 0.2 percentage points), pick at random
|
||||
among the tied options and log `propensity` (1 / number of tied options). That costs nothing in expected success,
|
||||
and it is exactly the randomised data the atlas needs to tell real history effects from guide-copying.
|
||||
The atlas learns from the bot's own runs: every zip of the bot's data that is imported adds its rolls (first dragon,
|
||||
deaths, the shadow, the meadow dragon, bond results) to the route model, and the next `atlas-for-bot` zip carries
|
||||
the updated model. Deliberate burns (Malek, "no shadow", "no Blue") never count as failed bond attempts.
|
||||
|
||||
How the bot should choose depends on the account's role:
|
||||
|
||||
- **Goal accounts** (`accountRole: "goal"`): the best route under the model, as before:
|
||||
`Solver.advisor(policy.samples.all, target, 'eventually')`.
|
||||
- **Research accounts** (`accountRole: "research"`): Thompson sampling. Make a new advisor for every attempt with a
|
||||
new seed:
|
||||
|
||||
```js
|
||||
const adv = Solver.advisor(policy.samples.all, target, 'eventually', { sampling: 'thompson', seed: attemptNumber });
|
||||
```
|
||||
|
||||
Each attempt follows the best route of one plausible version of the odds, drawn from the model's uncertainty. An
|
||||
option that might be the best one gets tried about as often as it is likely to be the best, so the attempts go
|
||||
where the model is least sure; as the data firm up, sampling settles on the best route by itself.
|
||||
`recommendOption()` then returns a `propensity` (the chance this option was picked, from 40 other draws; set
|
||||
`draws` to change that). Log it on the step with `decisionMode: "atlas_thompson"`, so the runs can be re-weighted.
|
||||
Making the advisor takes a few seconds per attempt (it solves the game once per draw).
|
||||
|
||||
The tie rule below still works for goal accounts; research accounts don't need it.
|
||||
|
||||
### Ties are free experiments
|
||||
|
||||
### Which numbers to trust
|
||||
|
||||
@@ -135,8 +174,17 @@ and it is exactly the randomised data the atlas needs to tell real history effec
|
||||
- `samples.lowBias`: bulk logs and riders not chasing a rare dragon. Use it for absolute expectations, such as how
|
||||
many attempts a Blue should take. Rare sightings are over-reported in form posts, so `all` is optimistic for Blue.
|
||||
|
||||
Current headline (from `analysis/reports/POLICY.md`): Black about 1.7% per attempt (about 60 attempts), Blue 3.7–7% per attempt
|
||||
(14–28 attempts), depending on the sample.
|
||||
Current headline, with the bot's runs and the reporting-bias correction (November 2026): Black about 0.03% per
|
||||
attempt (90% range 0–0.15%: the bot and bulk logs have never seen the shadow in about 700 tree runs), Blue about
|
||||
1.8–2.5% per attempt (40–55 attempts), depending on the sample.
|
||||
|
||||
The shadow is gated: it can only appear on runs that investigated the scream and helped the squadmate (the
|
||||
"Black Dragon Gates" of the community route PDF, and the runs agree). The model knows this
|
||||
(`core/spec/game.yaml`, `requires`), so it never sends a Black attempt off the gate.
|
||||
|
||||
Form submissions over-report rare sightings: riders report a meadow Blue about 4 times more readily than a meadow
|
||||
without one. The model estimates that bias for each kind of source and corrects for it (`planner/policy.yaml`,
|
||||
`reporting_bias`; the estimates are in `policy.json` under `model.reportingBias`).
|
||||
|
||||
## 2. From the bot to the atlas
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ Rules every part of the project follows. If a change would break one, stop and a
|
||||
|
||||
## Run reports
|
||||
|
||||
"Report a run" creates a public GitHub issue. The pipeline keeps only the issue number, the date and the answers
|
||||
"Report a run" creates an issue on the Atlas's repository (forge.yaml), visible to everyone who can see it. The pipeline keeps only the issue number, the date and the answers
|
||||
(`data/public/reports.json`); GitHub usernames are dropped. The form asks people not to include account names. A
|
||||
report closed as "not planned" or labelled `invalid` or `duplicate` is left out of the data.
|
||||
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
# Threshing Atlas: project context
|
||||
|
||||
A briefing for picking this project up in a new conversation. Written 2026-11-12 from the working state on
|
||||
Kathleen's Mac (`~/PycharmProjects/threshing-atlas`, latest commit `4837332`).
|
||||
|
||||
---
|
||||
|
||||
## 1. What this is
|
||||
|
||||
**Dragonkind** is a browser game set in the world of *Fourth Wing*. Its centrepiece, **the threshing**, is a short
|
||||
choose-your-path run: a cadet walks into a valley, makes a series of choices, the game rolls dice at certain points,
|
||||
and the run ends with the cadet either **bonded to a dragon** (Red, Orange, Brown, Green, Blue or Black) or
|
||||
**incinerated**. There's a cooldown of about four hours between attempts, Blue and Black are rare, and players want
|
||||
to know which choices give the best odds of the dragon they want.
|
||||
|
||||
The **Threshing Atlas** is a hobby, non-commercial, open-data project by **Kathleen Schiano (GitHub: ekcSchiano)**
|
||||
that:
|
||||
|
||||
1. **collects** every logged run it can find (a community Google Form and spreadsheet, Reddit, a bot, direct reports),
|
||||
2. **codes** them into one clean table, one run per row (`data/public/runs_clean.csv`),
|
||||
3. **analyses** them (factor tables, models, route rankings) for a public page,
|
||||
4. **plans** routes: a Bayesian model of the game's dice, solved as a decision tree, that recommends the best
|
||||
choice at every step for each target colour, and
|
||||
5. **feeds a bot**: Ken's DragonKind bot plays the game, uses the Atlas's route model to choose, and sends its runs
|
||||
back, so the model keeps learning.
|
||||
|
||||
Kathleen is a PhD researcher (informatics); she prefers **Python**, **declarative specs (YAML, data dictionaries,
|
||||
Croissant metadata)**, and JavaScript only where it must run in a browser or in Ken's Node bot.
|
||||
|
||||
## 2. People, places and accounts
|
||||
|
||||
| What | Where | Notes |
|
||||
|---|---|---|
|
||||
| The Atlas repo (canonical copy) | `~/PycharmProjects/threshing-atlas` on Kathleen's Mac | Python venv at `.venv` (Python 3.9); PyCharm. Has `scipy`; **Node is not installed** (so `graph.json` can't be rebuilt there; `brew install node` fixes it). |
|
||||
| GitHub repo | `github.com/ekcSchiano/threshing-atlas` (public) | **Account suspended** (flagged by GitHub's abuse detection, probably bursts of automated API activity from an AI assistant). Reinstatement request open with GitHub Support; they asked how she plans to use GitHub (answered: pet projects). GitHub Pages site paused. The Mac copy's `origin` still points here. |
|
||||
| Gitea | `git.kenschiano.net` (Ken's server) | The Atlas is prepared to move there (under Kathleen's own account, visibility "limited"), but **Ken's Gitea has a problem; skipped for now**. |
|
||||
| Ken | Gitea `kschiano`; GitHub issues author | Collaborator. Runs the **DragonKind bot** (private repo, now on his Gitea at `kschiano/DragonKind`). Kathleen has a local clone at `~/Desktop/DragonKind`: **read-only for us, never modify it** without asking. |
|
||||
| The page | Claude artifact "Threshing Route Atlas": https://claude.ai/artifact/Amr4D5Av7sBHkWvjJuXM8A | Last republished 2026-11-04 (older data). Kathleen will view new builds locally / as an artifact while GitHub Pages is paused. |
|
||||
| Community sources | u/ClumsyBadger's "Threshing Routes" Google Form (https://forms.gle/DRpj9tG8gb5E4Hcu7) and its responses spreadsheet; the "Unofficial Dragon Register"; the community route PDF; r/fourthwing Dragonkind megathreads (Part 3 `1wvwfp9`, Part 4 `1wz5cnj`) | Linked from the megathread post. u/Old_Regular3018 computes the PDF's percentages from the same spreadsheet; u/Smart_Trifle_2099 posted "precise Blue pathways" and Black theories. |
|
||||
| Backups | `threshing-atlas.bundle` sent in chat (git bundle of all branches) | `git clone threshing-atlas.bundle threshing-atlas` |
|
||||
|
||||
## 3. The game, as the Atlas models it
|
||||
|
||||
The game is written down declaratively in **`core/spec/game.yaml`** (the single source of truth for the route
|
||||
model, the advisor and the bot). In order:
|
||||
|
||||
1. **Company**: enter alone, with 1 or with 2 squadmates. **Leave** your squadmates or stay together.
|
||||
2. **First direction**: East, West or Center (the forest).
|
||||
3. **First dragon** (roll): Red, Brown, Green or Orange. **React**: hold still, respect/face it, run, hide, weapon,
|
||||
meet its gaze, protect squadmate (which reactions exist depends on the dragon). **Survive the first dragon** (roll).
|
||||
4. **The scream**: investigate it or keep walking.
|
||||
- **Investigate → the clearing** (your squadmate attacked by two bully cadets): help, or walk away.
|
||||
Help → **the fight**: pause to assess (then the dagger: engage the smaller cadet or charge the bigger one
|
||||
anyway), charge the smaller cadet ("even the numbers"), or charge the bigger one ("put yourself in the middle").
|
||||
**Survive the fight** (roll). Then **the bullies' fate**: kill them yourself, squadmate's revenge, or leave them
|
||||
to the dragons. Then a **fork**: Forest, West or East.
|
||||
- **Keep walking → the wounded cadet**: tourniquet, leave them to die, or take their weapons.
|
||||
5. **Survive the hour** (roll). **After an hour**: climb the tallest tree, or go to the valley centre.
|
||||
6. **Tree**: the **shadow** may appear (roll; **gated**, see below) → the shadow's colour (Black or Blue) → bonding
|
||||
encounter. If no shadow: **climb down quickly** (the Red below the tree: jump on it, or let it pass → the two
|
||||
Greens) or **slowly** (the two Greens).
|
||||
7. **Valley**: **face the Red**, or pass it into the **meadow**, where a dragon waits (roll: Orange, Brown, or a Blue).
|
||||
8. **Bonding encounters** (`encounters` in game.yaml): valley Red, tree Red, the two Greens (an Orange or Brown can
|
||||
swoop in and rescue/bond you), meadow Orange/Brown/Blue, the Blue at the redwood (shadow), the Black (shadow).
|
||||
A rider can attempt the bond or **die on purpose** ("seek Malek") rather than bond the wrong dragon.
|
||||
|
||||
Key modelling facts now in game.yaml:
|
||||
- **The shadow is gated**: it can only appear if you **investigated the scream and helped your squadmate** (the route
|
||||
PDF's "Black Dragon Gates"; data agree: 78 shadows in 4,199 gated tree runs vs 2 in 646 others, both likely
|
||||
mis-entered). A closed gate fixes the roll at "no" and those runs aren't counted for it.
|
||||
- **Possible bonds per encounter**: each encounter gives only its own colour (the two Greens also Orange/Brown).
|
||||
Anything else in the data is treated as a data-entry error (a form row once claimed a Green at the shadow's Blue,
|
||||
which broke the Green recommendation).
|
||||
|
||||
## 4. The four prongs + core (repo layout)
|
||||
|
||||
```
|
||||
core/ spec/form.yaml (how each form answer is coded), spec/game.yaml (the game)
|
||||
atlas/ (Python): coding.py (form → runs), model.py (counts, back-off, Params), solver.py (decision
|
||||
tree, posterior draws, policy export), bias.py (reporting bias), runs.py (read runs_clean.csv), spec.py
|
||||
solver.js (the small JS advisor), graph.js (route graph helpers + the bot crosswalk, generated block)
|
||||
collection/ pipeline.yaml (every source, declaratively), run.py (`python -m collection ...`),
|
||||
etl/ (extract, transform/*, validate, load, runs.py coders, metadata.py (Croissant), codegen.py,
|
||||
report_form.py, handoff.py (zips, local refresh), forge.py (Gitea/GitHub API)),
|
||||
specs/bot.yaml (bot labels + crosswalk), specs/report_form.yaml, manual/reddit_results.yaml
|
||||
analysis/ stats/measures.yaml (what the page measures), site_stats.py, stats_core.py;
|
||||
network/build-graph.js (graph.json); reports/POLICY.md (written by policy_report.py)
|
||||
planner/ policy.yaml (which runs the model learns from, low-bias sample, reporting-bias settings),
|
||||
build_policy.py, policy_report.py
|
||||
site/ atlas/ (index.html, app.js, ui.js, explorer.js (valley map), valley.js, dragons.js, register.js),
|
||||
build.js (→ dist/), qa/ (crawl.js, mapcheck.js: Playwright checks)
|
||||
data/ public/ (everything published: runs_clean.csv, form_responses.json, register.json, reports.json,
|
||||
stats.json, policy.json, graph.json, links.json), dictionary.yaml, croissant.json, manifest.json,
|
||||
bot/ (scenes.json, trajectories-*.jsonl: anonymised bot runs), derived/pdf_fingerprint.json,
|
||||
raw/ (git-ignored: current + previous raw file per source; never published)
|
||||
tests/ core/ (coding rules, game, solver, stats, bias + JS advisor/graph tests), collection/ (pipeline),
|
||||
fixtures/, parity/
|
||||
docs/ BOT_INTEGRATION.md, BOT_DATA_PROTOCOL.md, PRIVACY.md, REPO_SETTINGS.md, ROADMAP.md, COLOURS.md
|
||||
forge.yaml where the repo is hosted (gitea, git.kenschiano.net, repo: YOUR-GITEA-USERNAME/threshing-atlas placeholder)
|
||||
.gitea/workflows/ CI + daily update for Gitea .github/workflows/ CI, daily update, Pages for GitHub (paused)
|
||||
```
|
||||
|
||||
### 4a. Data collection: ETL (`collection/`)
|
||||
|
||||
`collection/pipeline.yaml` declares every source: how to **extract** it, which **transform**, its **privacy** rules,
|
||||
where it **loads**, and which **coder** turns it into runs.
|
||||
|
||||
- **extract** only fetches into `data/raw/<source>/current.<ext>` (the replaced one becomes `previous.<ext>`;
|
||||
nothing older is kept). `data/manifest.json` records the current raw checksum and change date.
|
||||
- **transform** is pure (no network, no clock) → the public source file.
|
||||
- **validate** checks runs against `data/dictionary.yaml` (types, every allowed value, unique ids). A new answer the
|
||||
rules don't know **stops the load** and is reported (add it to `core/spec/form.yaml`).
|
||||
- **load** is the only stage that writes; byte-stable.
|
||||
- **build** codes every public source file into `data/public/runs_clean.csv` and writes generated files: the
|
||||
"Report a run" issue form, the crosswalk block in `core/graph.js`, `data/public/links.json`, `data/croissant.json`.
|
||||
|
||||
| `source` in runs_clean | Pipeline source | Runs now | Notes |
|
||||
|---|---|---|---|
|
||||
| reddit spreadsheet | `reddit_spreadsheet` (the Threshing Routes form + sheet) | 8,132 | coded by `core/spec/form.yaml`; `entry` column keeps the sheet's own label ("Form" = form submission; others = bulk-pasted logs) |
|
||||
| bot | `bot` (Ken's bot, imported from a folder or zip) | 421 | per-account folders; account names salted-hashed (salt in `data/raw/bot/account-salt.txt` on the Mac, never committed); `bot_mode` column |
|
||||
| reddit thread | `reddit_thread` | 12 | dragonkind.com result pages read by hand (`collection/manual/reddit_results.yaml`); Reddit API extractor ready but needs `REDDIT_CLIENT_ID/SECRET` |
|
||||
| reported | `reported` ("Report a run" issue form) | 0 | GitHub issues; switched to Gitea via forge.yaml (currently 404s: GitHub suspended, Gitea not set up) |
|
||||
| reddit pdf | `reddit_pdf` | 0 | the route PDF is a flowchart, not runs: only its **fingerprint** is kept (never redistributed); changes are reported line by line |
|
||||
| (none) | `register` (Unofficial Dragon Register) | 0 | bonded dragons without routes; names and photos dropped |
|
||||
|
||||
Every column is described in `data/dictionary.yaml`; `data/croissant.json` is Croissant 1.0 metadata built from it.
|
||||
|
||||
### 4b. Data analysis (`analysis/`)
|
||||
|
||||
`analysis/stats/site_stats.py` reads runs_clean (sources in `measures.yaml`: **spreadsheet only** for now) and writes
|
||||
`data/public/stats.json`: every number the page shows, for six fixed filter presets (all, form only, bulk only, not
|
||||
chasing Blue/Black, chasing, unflagged). Factor tables (Fisher/Mantel–Haenszel, BH q-values), ridge-logistic models,
|
||||
route rankings at thresholds 5/10/20/30, per-stage route map counts. The page computes nothing itself.
|
||||
`analysis/network/build-graph.js` writes `graph.json` (route graph per source + the bot's scene graph).
|
||||
|
||||
### 4c. Route planner (`planner/` + `core/atlas/`)
|
||||
|
||||
- **Model**: each roll (first dragon, survive sighting/fight/hour, shadow, shadow colour, meadow dragon) is a
|
||||
categorical with a **hierarchical Dirichlet back-off** over its context (earlier choices); the shrinkage strength
|
||||
(alpha) is fitted by empirical Bayes. Bond outcomes per encounter likewise. Malek/deliberate burns are not counted
|
||||
as failed bonds.
|
||||
- **Learns from** (`planner/policy.yaml`): reddit spreadsheet + reported + **bot** runs.
|
||||
- **Reporting-bias correction** (`core/atlas/bias.py`): form submitters over-report rare sightings. For each rare roll
|
||||
and each group, rho = odds(rare | group) / odds(rare | complete logs), where complete logs = **bot + bulk logs**.
|
||||
Rare outcomes from biased groups count 1/rho. Current estimates (meadow Blue): **form, chasing Blue/Black rho 3.85
|
||||
[2.98–5.14]; form, other 3.17 [2.33–4.41]**. For the shadow, complete logs have **0 shadows in 579 gated tree runs**,
|
||||
so the bias can't be estimated and the shadow is learned from complete logs only. A roll seen only one way is pooled
|
||||
fully (alpha max). Caveats: assumes the bias is the same on every route; intervals don't include rho's uncertainty.
|
||||
- **Solver** (`core/atlas/solver.py`): walks game.yaml as a decision tree; two goals per colour: "this attempt"
|
||||
(maximise P(colour)) and "eventually" (Dinkelbach ratio: P(X) / (P(X)+P(other bond)), i.e. dying on purpose
|
||||
otherwise). 200 posterior draws give intervals and **stillBest** (share of draws where the recommended choice is best).
|
||||
Two samples: **all** and **lowBias** (bot + bulk + riders not chasing rare dragons).
|
||||
- **Output**: `data/public/policy.json` (game, count tables, alphas, reportingBias, support, trees per colour).
|
||||
- **JS advisor** (`core/solver.js`): reads policy.json, re-solves, `advisor(sample, colour, objective, opts)`,
|
||||
`recommendOption()` maps on-screen text to options (game.yaml `bot_text`). **Thompson sampling**:
|
||||
`{ sampling: 'thompson', seed }` follows one posterior draw per attempt and returns a **propensity**.
|
||||
|
||||
Current odds per attempt (sample "all", latest build `538bc1e3d694`):
|
||||
|
||||
| Colour | Per attempt (90% range) | Low-bias sample | stillBest of first choice |
|
||||
|---|---|---|---|
|
||||
| Red | 93.1% (86.9–97.4) | 94.1% | 0.30 |
|
||||
| Green | 25.2% (21.7–28.8) | 24.2% | 0.42 |
|
||||
| Orange | 13.5% (11.3–15.7) | 16.7% | 0.55 |
|
||||
| Brown | 9.3% (7.7–11.2) | 10.7% | 0.52 |
|
||||
| Blue | 2.5% (2.1–3.0) | 1.9% | 0.45 |
|
||||
| Black | 0.05% (0.00–0.25) | 0.04% | 0.31 |
|
||||
|
||||
(Before the bot data and bias correction, the model said Blue 7.3% and Black 2.1%: inflated by reporting bias.)
|
||||
|
||||
### 4d. Data visualisation (`site/`)
|
||||
|
||||
A single static page (tabs: Valley map, Odds, Dragons, Deep dive, Data & Methods, **Report a run**). The **valley
|
||||
map** (`explorer.js`) uses progressive disclosure: key moments only, a point's options appear when selected, picking
|
||||
a dragon shows its best path and choices; later choices keep the path you picked. The page shows precomputed
|
||||
`stats.json` and runs the JS advisor on `policy.json`. Links come from `data/public/links.json` (filled in by
|
||||
`site/build.js`). Build: `node site/build.js` → `dist/`. QA: `site/qa/crawl.js` (needs a local server on :8765),
|
||||
`site/qa/mapcheck.js`. Published so far as the Claude artifact above.
|
||||
|
||||
## 5. The bot loop (Ken)
|
||||
|
||||
- **Atlas → bot**: `python3 -m collection export-bot-kit` → `exports/atlas-for-bot-<date>-<policy id>.zip`
|
||||
(policy.json, solver.js, graph.js, README with checksums). Ken unzips into the bot's `vendor/threshing-atlas/`.
|
||||
Latest: `atlas-for-bot-2026-11-12-538bc1e3d694.zip`.
|
||||
- **Bot → atlas**: Ken zips the bot's `data/` and `logs/` folders; save in `inbox/` and run
|
||||
`python3 -m collection refresh --bot inbox/<zip>`. The importer reads `data/knowledge.json` and every
|
||||
`data/accounts/<acct>/runs.jsonl` + `logs/accounts/<acct>/encounters.jsonl` (top-level files mirror the first
|
||||
account and are skipped). Bot **schema-2** run records carry steps, what was seen (shadow, dragons), propensity,
|
||||
decisionMode, policyId. No game prose or account names are published (`check_public` refuses them).
|
||||
- **How the bot should choose** (docs/BOT_INTEGRATION.md): goal accounts follow the best route
|
||||
(`advisor(policy.samples.all, target, 'eventually')`); **research accounts use Thompson sampling** with a new seed
|
||||
per attempt and log `propensity` with `decisionMode: "atlas_thompson"`.
|
||||
- Ken's data so far: 13 accounts, 415 attempts (to 2026-11-10); research accounts burn on purpose when no shadow at
|
||||
the tree / no Blue in the meadow (`TREE_NO_SHADOW_AUTO_BURN`, `MEADOW_NO_BLUE_AUTO_BURN`).
|
||||
|
||||
## 6. Findings so far
|
||||
|
||||
- **Reporting bias is large.** Meadow Blue: complete logs ~10% (bot 16/126, bulk 30/328) vs form ~33%.
|
||||
- **Black is very rare.** 0 shadows in 579 gated tree runs from complete logs; form data show ~2% (inflated). Model:
|
||||
~0.05% per attempt. Fits Smart_Trifle_2099's guess of 1/500–1/1000 tree runs for a Black sighting.
|
||||
- **Route doesn't seem to move the rare rolls.** Shadow rate doesn't differ across routes (chi² 44 on 40 df); the
|
||||
"precise Blue pathways" (Smart_Trifle_2099 and the megathread post's ~47%/~63% routes) did no better than other
|
||||
meadow routes (23–30% vs 30% in the spreadsheet). Reaching the meadow seems to be the "unlock".
|
||||
- **The gate is real**: the shadow needs investigate + help.
|
||||
- **Tree Red is the hardest bond**: 1.7% (38/2,207), matching the post's "2%".
|
||||
- **First attempts** see the meadow Blue less often (16% vs 31%), surviving adjustment in the site's model.
|
||||
- Weekly swings in rates (and "the game was patched" claims) are confounded by who reports when.
|
||||
|
||||
## 7. How to run things (on the Mac, PyCharm terminal, venv active)
|
||||
|
||||
```
|
||||
python3 -m collection refresh # the daily update locally (~3 min): sources → runs → graph* → model → stats → build
|
||||
python3 -m collection refresh --bot inbox/x.zip # same, importing a bot zip
|
||||
python3 -m collection update --source NAME # one source; --file NAME=PATH to use a local file
|
||||
python3 -m collection build [--check] # rebuild runs_clean + generated files (CI uses --check)
|
||||
python3 -m collection export-bot-kit # zip for Ken
|
||||
python3 planner/build_policy.py # route model (~30–75 s); python3 planner/policy_report.py
|
||||
python3 analysis/stats/site_stats.py # page statistics (needs scipy)
|
||||
node analysis/network/build-graph.js # graph.json (*needs Node)
|
||||
node site/build.js # the page → dist/
|
||||
npm test # = build --check + Python unit tests + JS tests
|
||||
```
|
||||
|
||||
Reports land in `exports/last-report.md`. If a refresh stops with "values not in the dictionary", add the new form
|
||||
answer to `core/spec/form.yaml` (or the value to `data/dictionary.yaml`) and run `python3 -m collection build`.
|
||||
|
||||
## 8. Conventions and constraints (keep these)
|
||||
|
||||
- **Python first; declarative specs** (YAML for the form, game, pipeline, measures, planner, bot crosswalk, report
|
||||
form; dictionary + Croissant). JS only for the browser page and Ken's Node bot (`solver.js`, `graph.js`).
|
||||
- **Generated files are generated**: don't hand-edit `runs_clean.csv`, `croissant.json`, `links.json`, the
|
||||
crosswalk block in `core/graph.js`, `.github/ISSUE_TEMPLATE/report-a-run.yml`. Edit the spec, then build.
|
||||
- **Privacy**: no game prose, no account names/ids, no emails (redacted), no rider names (register), no Reddit or
|
||||
GitHub usernames; the route PDF is never redistributed (fingerprint only). Never commit `data/raw/`, `.env`,
|
||||
`.browser-profile/`, salts or tokens; tokens only in repository secrets. Don't scrape Discord with a personal token;
|
||||
Reddit only via the official API.
|
||||
- **Don't write to Ken's bot repo** (`~/Desktop/DragonKind`) without asking.
|
||||
- **Commits** as `ekcSchiano` / Kathleen's email, ending with `Co-Authored-By: Claude …` and `Claude-Session: …`
|
||||
lines. On GitHub, main was protected (PR + required `test` check, auto-merge). **Go easy on automated API
|
||||
activity** (that's the likely cause of the GitHub suspension).
|
||||
- Kathleen likes: progressive disclosure on the map, honest uncertainty, explaining what changed and why.
|
||||
|
||||
## 9. Status and open threads
|
||||
|
||||
- **Uncommitted / pending**: nothing important; Mac repo is clean at `4837332` (plus `.idea/`, `exports/`, `inbox/`
|
||||
ignored). The artifact page is older than the data; rebuild with `node site/build.js` (needs Node) and republish.
|
||||
- **GitHub**: suspended; reinstatement in progress. When back: `git push` to a branch + PR (main is protected);
|
||||
GitHub Pages resumes from `.github/workflows/pages.yml`; set `forge.yaml` `kind: github` (or keep Gitea + mirror).
|
||||
- **Gitea**: ready but on hold (Ken's server has a problem). Steps in `docs/REPO_SETTINGS.md`; set your username in
|
||||
`forge.yaml`; the `.gitea/workflows/` are untested (runner label assumed `ubuntu-latest`).
|
||||
- **"Report a run"** button points at a Gitea URL that doesn't exist yet; the Google Form is the working intake.
|
||||
- **Not done yet / ideas**:
|
||||
- Include bot and reported runs in the page's statistics (currently spreadsheet only; bot choices follow a strategy).
|
||||
- Propagate the bias estimate's uncertainty (rho) into the route model's intervals; consider a per-source
|
||||
reporting-bias model inside the posterior draws.
|
||||
- Inverse-propensity weighting of bot runs using logged propensities.
|
||||
- Port `build-graph.js` to Python; Reddit extractor live once API secrets exist; "Community claims, checked"
|
||||
section (claims YAML recomputed against data); a "random run?" question on the report form.
|
||||
- Reviews still pending from the original plan: analysis, planner (experiments.json, encounter answers), site.
|
||||
- **Environment gotchas** (for Claude sessions): the cloud workspace and the Mac's Linux helper can't reach Google,
|
||||
Gitea or PyPI; Kathleen's own Terminal can. The helper lacks `scipy`. Git in the helper needs delete permission
|
||||
for its lock files.
|
||||
@@ -1,5 +1,51 @@
|
||||
# Repository settings
|
||||
|
||||
The Atlas is hosted on Gitea (`forge.yaml`: git.kenschiano.net). The GitHub repository and its GitHub Pages site are
|
||||
paused while that account is suspended; their workflows stay in `.github/workflows/` for when it is back.
|
||||
|
||||
## Gitea: setting up the repository (once)
|
||||
|
||||
1. **Your account** on git.kenschiano.net (ask Ken), with 2FA on and your SSH key added (Settings → SSH / GPG Keys).
|
||||
2. **Create the repository** `threshing-atlas` under your account, visibility **limited** (only people signed in to
|
||||
the server), empty (no README or licence: they come from the push). Put your username in `forge.yaml` (`repo:`),
|
||||
then `python -m collection build` and commit.
|
||||
3. **Push** from your Mac copy:
|
||||
|
||||
```
|
||||
cd ~/PycharmProjects/threshing-atlas
|
||||
git remote rename origin github # keep the GitHub address for later
|
||||
git remote add origin git@git.kenschiano.net:<you>/threshing-atlas.git
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
4. **Turn on Actions** (repository Settings → Units → Actions) and ask Ken which runner label the server has. The
|
||||
workflows use `ubuntu-latest`; change `runs-on:` in `.gitea/workflows/*.yml` if it is different.
|
||||
5. **Secrets** (Settings → Actions → Secrets):
|
||||
|
||||
| Secret | What it is | How to make it |
|
||||
|---|---|---|
|
||||
| `ATLAS_BOT_TOKEN` | lets the daily update push its branch, open the pull request and issues | your Settings → Applications → Generate token; permissions: repository read and write, issue read and write |
|
||||
| `RAW_ARCHIVE_KEY` | encrypts the private raw store kept in the Actions cache between runs | any long random string (`openssl rand -base64 32`); keep a copy |
|
||||
| `REDDIT_CLIENT_ID`, `REDDIT_CLIENT_SECRET` | optional: read the megathreads through the Reddit API | see "Data collection secrets" below |
|
||||
|
||||
6. **Protect main** (Settings → Branches → Add rule for `main`): require a pull request, enable status checks and
|
||||
require the check from the CI workflow (it shows up as `CI / test` after its first run), and allow
|
||||
"merge when checks succeed". Leave required approvals at 0 so the daily update can merge itself.
|
||||
7. **The label** for reports: `python -m collection forge ensure-label --name "run report"` (with
|
||||
`ATLAS_BOT_TOKEN` set), or create it under Issues → Labels.
|
||||
|
||||
The daily update then runs at 10:23 UTC; run it by hand from the Actions tab (workflow "Check sources for new data").
|
||||
Locally, `python -m collection refresh` does the same.
|
||||
|
||||
## The page
|
||||
|
||||
The page is built by `node site/build.js` and viewed locally or published as a Claude artifact; Gitea has no Pages.
|
||||
Its links (the repository, "Report a run") come from `forge.yaml` through `data/public/links.json`.
|
||||
|
||||
## GitHub (paused)
|
||||
|
||||
# Repository settings
|
||||
|
||||
Some settings live on GitHub, not in the code. Only the repository owner (ekcSchiano) can change them.
|
||||
They go together: the ruleset makes CI a gate on `main`, auto-merge lets a pull request merge itself once
|
||||
it passes, and the token lets the daily data update do that on its own.
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
# Where the Atlas's repository is hosted. Everything that talks to the host reads this file: the daily workflow
|
||||
# (opening its pull request and issues), the "Report a run" collector, the links on the page and in the dataset
|
||||
# metadata (data/croissant.json). Moving hosts is an edit here (then `python -m collection build`).
|
||||
#
|
||||
# kind: gitea or github. The Gitea workflows live in .gitea/workflows/ (Gitea ignores .github/workflows/ when that
|
||||
# folder exists); the GitHub ones, including GitHub Pages, stay in .github/workflows/ for when GitHub is used again.
|
||||
version: 1
|
||||
|
||||
kind: gitea
|
||||
url: https://git.kenschiano.net
|
||||
repo: YOUR-GITEA-USERNAME/threshing-atlas # owner/name on the server (set your username here)
|
||||
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
|
||||
|
||||
# other copies of the repository (informational)
|
||||
mirrors:
|
||||
github: https://github.com/ekcSchiano/threshing-atlas # suspended; GitHub Pages workflow kept for later
|
||||
+22
-7
@@ -2,7 +2,8 @@
|
||||
|
||||
python planner/build_policy.py [--draws 200] [--out data/public/policy.json]
|
||||
|
||||
Two samples: every run, and a low-bias sample (bulk logs plus form runs from riders not chasing a rare dragon).
|
||||
Two samples, from the runs and rules in planner/policy.yaml: every run, and a low-bias sample (bot runs, bulk logs,
|
||||
and riders not chasing a rare dragon).
|
||||
The output has a content id, so each bot run can record which policy it followed.
|
||||
"""
|
||||
import argparse
|
||||
@@ -20,9 +21,19 @@ from atlas import runs as runs_io # noqa: E402
|
||||
|
||||
import yaml # noqa: E402
|
||||
|
||||
# the same runs the site's statistics use (analysis/stats/measures.yaml `sources`)
|
||||
with open(ROOT / "analysis/stats/measures.yaml", encoding="utf-8") as _f:
|
||||
SOURCES = yaml.safe_load(_f)["sources"]
|
||||
# which runs the model learns from, and the low-bias sample (planner/policy.yaml)
|
||||
with open(ROOT / "planner/policy.yaml", encoding="utf-8") as _f:
|
||||
CONFIG = yaml.safe_load(_f)
|
||||
SOURCES = CONFIG["sources"]
|
||||
|
||||
|
||||
def low_bias(r, lb=CONFIG["low_bias"]):
|
||||
"""Kept in the low-bias sample: every run of an always-kept source, bulk logs, and riders not chasing a rare dragon."""
|
||||
if r["source"] in lb["always"]:
|
||||
return True
|
||||
if r["source"] == "reddit spreadsheet" and "bulk" in lb["entries_kept"] and r["entry"] not in (None, "Form"):
|
||||
return True
|
||||
return r["goal"] not in lb["rare_goals"]
|
||||
|
||||
|
||||
def clean(o):
|
||||
@@ -49,12 +60,16 @@ def main(argv=None):
|
||||
rows = len(runs)
|
||||
samples = {
|
||||
"all": runs,
|
||||
"lowBias": [r for r in runs if r["entry"] != "Form" or r["goal"] not in model.RARE_GOALS],
|
||||
"lowBias": [r for r in runs if low_bias(r)],
|
||||
}
|
||||
t0 = time.time()
|
||||
out = {"schema": 1, "source": {"form_rows": rows}, "samples": {}}
|
||||
by_source = {}
|
||||
for r in runs:
|
||||
by_source[r["source"]] = by_source.get(r["source"], 0) + 1
|
||||
out = {"schema": 1, "source": {"form_rows": by_source.get("reddit spreadsheet", 0), "runs": rows, "by_source": by_source},
|
||||
"samples": {}}
|
||||
for name, rs in samples.items():
|
||||
out["samples"][name] = clean(solver.build_policy(rs, draws=a.draws))
|
||||
out["samples"][name] = clean(solver.build_policy(rs, draws=a.draws, bias_config=CONFIG.get("reporting_bias")))
|
||||
print(f"{name}: {len(rs)} runs, {time.time() - t0:.1f} s")
|
||||
# a content id (no timestamps: the build is reproducible)
|
||||
out["id"] = hashlib.sha1(json.dumps(out["samples"], separators=(",", ":"), sort_keys=True).encode()).hexdigest()[:12]
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Which runs the route model (data/public/policy.json) learns from. planner/build_policy.py reads this file.
|
||||
#
|
||||
# The model estimates the game's rolls (first dragon, deaths, shadow, meadow dragon, bond chances) given the choices
|
||||
# made before them, so any run that records its choices and what happened can teach it, whoever chose the route.
|
||||
# Deliberate deaths (Malek, the bot's "no shadow" / "no Blue" burns) are never counted as failed bond attempts.
|
||||
version: 1
|
||||
|
||||
# the `source` values of data/public/runs_clean.csv the model learns from
|
||||
sources: [reddit spreadsheet, reported, bot]
|
||||
|
||||
# Two samples. "all" is every run above. "lowBias" leaves out runs where a rare sighting is more likely to have
|
||||
# been reported than a miss: form submissions and reports from riders chasing Blue or Black. The bot logs every
|
||||
# run, and bulk-pasted logs record every run of the players who kept them, so both stay in.
|
||||
low_bias:
|
||||
always: [bot] # sources whose every run is kept
|
||||
entries_kept: [bulk] # spreadsheet rows whose `entry` is not "Form" (bulk-pasted logs)
|
||||
rare_goals: [Blue, Black, Blue or Black]
|
||||
|
||||
# Reporting bias (core/atlas/bias.py). A rider is more likely to write up a run with a shadow or a meadow Blue than
|
||||
# one without, so those sightings are over-represented in form submissions. For each rare roll below and each group
|
||||
# that is not complete, the model estimates how many times more often the group reports the rare outcome than the
|
||||
# complete groups do (rho, with a 90% range), and counts each rare outcome it reports as 1/rho. The group's pattern
|
||||
# across routes is kept; its overall level comes from complete logging. Assumes the bias is the same on every route.
|
||||
reporting_bias:
|
||||
rolls: { shadow: "yes", meadow: Blue } # roll: its rare outcome
|
||||
min_runs: 30 # fewer runs than this in a group (or the complete groups): borrow
|
||||
min_complete_rare: 5 # fewer rare outcomes than this in complete logs: the bias cannot be
|
||||
# estimated, so the roll is learned from complete logs only
|
||||
groups: # first match wins
|
||||
- { name: bot, when: { source: bot }, complete: true }
|
||||
- { name: bulk logs, when: { source: reddit spreadsheet, entry_not: Form }, complete: true }
|
||||
- { name: "form, chasing Blue/Black", when: { source: reddit spreadsheet, goal: rare } }
|
||||
- { name: "form, other", when: { source: reddit spreadsheet } }
|
||||
- { name: reported, when: { source: reported }, same_as: "form, other" }
|
||||
@@ -608,7 +608,7 @@ a { color: var(--accent); text-underline-offset: 2px; }
|
||||
</section>
|
||||
<section id="share" aria-labelledby="h-share">
|
||||
<div class="section-head"><span class="eyebrow">Open by design</span><h2 id="h-share">Share & reproduce</h2>
|
||||
<p class="muted small">Everything on this page is computed from the community form export by the code in the <a href="https://github.com/ekcSchiano/threshing-atlas" target="_blank" rel="noopener">GitHub repository</a>, which updates the data every day. The rules for reading each answer are in <code>core/spec/form.yaml</code>, the game in <code>core/spec/game.yaml</code>, and what is measured in <code>analysis/stats/measures.yaml</code>.</p></div>
|
||||
<p class="muted small">Everything on this page is computed from the community form export by the code in the <a href="{{repo}}" target="_blank" rel="noopener">repository</a>, which updates the data every day. The rules for reading each answer are in <code>core/spec/form.yaml</code>, the game in <code>core/spec/game.yaml</code>, and what is measured in <code>analysis/stats/measures.yaml</code>.</p></div>
|
||||
<div class="grid2">
|
||||
<div class="panel"><h3>Copy the outputs</h3>
|
||||
<div class="btnrow"><button type="button" id="cp-reddit" class="primary">Copy Reddit post (Markdown)</button><a class="btnlike" href="data/runs_clean.csv" download>Download coded runs (CSV)</a><button type="button" id="cp-json">Copy all results (JSON)</button></div>
|
||||
@@ -692,8 +692,8 @@ adjusted OR = exp(βⱼ), 95% CI = exp(βⱼ ± 1.96·SEⱼ)</div>
|
||||
<p class="muted">Every run anyone logs ends up in the Atlas's open data, <a href="data/runs_clean.csv" download>runs_clean.csv</a>, which anyone can download and reuse. Deaths are as useful as bonds: the odds on this page are only as good as the runs behind them. Please report each run in one place only.</p></div>
|
||||
<div class="grid2">
|
||||
<div class="panel"><h3>Report it on the Atlas</h3>
|
||||
<p class="small">A short form with the game's own choices (a GitHub issue, so you need a free GitHub account). Reports show up in the data the next day with the source <b>reported</b>. Reports are public: please leave out your account name.</p>
|
||||
<p><a class="btnlike primary" href="https://github.com/ekcSchiano/threshing-atlas/issues/new?template=report-a-run.yml" target="_blank" rel="noopener">Report a run</a></p>
|
||||
<p class="small">A short form with the game's own choices: an issue on the Atlas's repository at {{host}}, so you need an account there. Reports show up in the data the next day with the source <b>reported</b>. Everyone who can see the repository can read reports: please leave out your account name.</p>
|
||||
<p><a class="btnlike primary" href="{{report}}" target="_blank" rel="noopener">Report a run</a></p>
|
||||
</div>
|
||||
<div class="panel"><h3>Or use the community form</h3>
|
||||
<p class="small">The r/fourthwing megathreads collect runs with u/ClumsyBadger's Google Form, and its answers go into a public spreadsheet. The Atlas reads that spreadsheet every day (source <b>reddit spreadsheet</b>), so a run logged there is counted here too.</p>
|
||||
@@ -717,7 +717,7 @@ adjusted OR = exp(βⱼ), 95% CI = exp(βⱼ ± 1.96·SEⱼ)</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<footer><div class="wrap"><p><b>Data:</b> the community <a href="https://docs.google.com/spreadsheets/d/1gnw1AdRg1XT4JsOfRM6QTA0jSaS3n9ZF-rPWnYewzv0" target="_blank" rel="noopener">"Threshing Routes" responses</a> compiled by <a href="https://www.reddit.com/user/ClumsyBadger/" target="_blank" rel="noopener">u/ClumsyBadger</a>, with percentages in the <a href="https://drive.google.com/file/d/17o72ehHsSPW4UdsKF-sXTxMLEuinWeEg/view" target="_blank" rel="noopener">route PDF</a> by <a href="https://www.reddit.com/user/ClumsyBadger/" target="_blank" rel="noopener">u/ClumsyBadger</a>, <a href="https://www.reddit.com/user/Old_Regular3018/" target="_blank" rel="noopener">u/Old_Regular3018</a> and <a href="https://www.reddit.com/user/Smart_Trifle_2099/" target="_blank" rel="noopener">u/Smart_Trifle_2099</a>; the <a href="https://docs.google.com/spreadsheets/d/1KMiE9sec0l597Pzue1OhGYf07NF4howtQ_lPeqx7jXQ" target="_blank" rel="noopener">Unofficial Dragon Register</a>; and the r/fourthwing bonding megathreads (<a href="https://www.reddit.com/r/fourthwing/comments/1wvwfp9/" target="_blank" rel="noopener">Part 3</a>, <a href="https://www.reddit.com/r/fourthwing/comments/1wz5cnj/" target="_blank" rel="noopener">Part 4</a>). Code and data: <a href="https://github.com/ekcSchiano/threshing-atlas" target="_blank" rel="noopener">github.com/ekcSchiano/threshing-atlas</a> (MIT, data CC BY 4.0).</p>
|
||||
<footer><div class="wrap"><p><b>Data:</b> the community <a href="https://docs.google.com/spreadsheets/d/1gnw1AdRg1XT4JsOfRM6QTA0jSaS3n9ZF-rPWnYewzv0" target="_blank" rel="noopener">"Threshing Routes" responses</a> compiled by <a href="https://www.reddit.com/user/ClumsyBadger/" target="_blank" rel="noopener">u/ClumsyBadger</a>, with percentages in the <a href="https://drive.google.com/file/d/17o72ehHsSPW4UdsKF-sXTxMLEuinWeEg/view" target="_blank" rel="noopener">route PDF</a> by <a href="https://www.reddit.com/user/ClumsyBadger/" target="_blank" rel="noopener">u/ClumsyBadger</a>, <a href="https://www.reddit.com/user/Old_Regular3018/" target="_blank" rel="noopener">u/Old_Regular3018</a> and <a href="https://www.reddit.com/user/Smart_Trifle_2099/" target="_blank" rel="noopener">u/Smart_Trifle_2099</a>; the <a href="https://docs.google.com/spreadsheets/d/1KMiE9sec0l597Pzue1OhGYf07NF4howtQ_lPeqx7jXQ" target="_blank" rel="noopener">Unofficial Dragon Register</a>; and the r/fourthwing bonding megathreads (<a href="https://www.reddit.com/r/fourthwing/comments/1wvwfp9/" target="_blank" rel="noopener">Part 3</a>, <a href="https://www.reddit.com/r/fourthwing/comments/1wz5cnj/" target="_blank" rel="noopener">Part 4</a>). Code and data: <a href="{{repo}}" target="_blank" rel="noopener">{{repo_label}}</a> (MIT, data CC BY 4.0).</p>
|
||||
<p><b>Unofficial fan analysis,</b> not affiliated with <a href="https://dragonkind.com" target="_blank" rel="noopener">Dragonkind</a> or its authors. A 10% "chaos" chance of incineration on any choice has been described by the author, so <b>no route guarantees a bond</b>.</p></div></footer>
|
||||
<div id="tip" hidden></div>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
|
||||
|
||||
+4
-1
@@ -16,7 +16,10 @@ for (const f of fs.readdirSync(path.join(root, "site/atlas"))) copy(`site/atlas/
|
||||
// local serving, give it its own doctype, charset and viewport.
|
||||
{
|
||||
const p = path.join(out, "index.html");
|
||||
const html = fs.readFileSync(p, "utf8");
|
||||
// links from forge.yaml (data/public/links.json, written by `python -m collection build`)
|
||||
const links = JSON.parse(fs.readFileSync(path.join(root, "data/public/links.json"), "utf8"));
|
||||
const html = fs.readFileSync(p, "utf8").replace(/\{\{(\w+)\}\}/g, (m, k) => (k in links ? links[k] : m));
|
||||
fs.writeFileSync(p, html);
|
||||
if (!/^\s*<!doctype/i.test(html))
|
||||
fs.writeFileSync(p, `<!doctype html>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n${html}`);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""The collection pipeline: extract's raw store, every transform, the coders, validation and the generated files."""
|
||||
import csv
|
||||
import json
|
||||
import re
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -100,15 +101,42 @@ class Bot(unittest.TestCase):
|
||||
self.assertEqual(py, {k: v for k, v in j.items() if k not in ("outcome", "outcome_color")})
|
||||
|
||||
def test_every_bot_choice_is_mapped(self):
|
||||
"""Every choice the bot has seen maps onto a column, except answers inside a bonding encounter."""
|
||||
"""Every route choice the bot has seen before the hour maps onto a column (answers inside the bonding
|
||||
encounters are not route choices), unless bot.yaml lists it as not coded."""
|
||||
import re
|
||||
cw = [re.compile(rx) for rx, _, _ in read_yaml("collection/specs/bot.yaml")["crosswalk"]]
|
||||
spec = read_yaml("collection/specs/bot.yaml")
|
||||
cw = [re.compile(rx) for rx, _, _ in spec["crosswalk"]] + [re.compile(rx) for rx in spec.get("not_coded", [])]
|
||||
scenes = json.loads((ROOT / "data/bot/scenes.json").read_text(encoding="utf-8"))
|
||||
route = {"ENTER_THRESHING", "FIRST_SIGHTING", "SCREAM_AND_CADETS"}
|
||||
unmapped = [f"{s['label']}: {o['text']}" for s in scenes.values()
|
||||
if len(s["options"]) > 1 and "two Greens in the clearing" not in s["label"]
|
||||
if len(s["options"]) > 1 and s["stage"] in route and "two Greens in the clearing" not in s["label"]
|
||||
for o in s["options"] if not any(rx.search(bot.normalize(o["text"])) for rx in cw)]
|
||||
self.assertEqual(unmapped, [])
|
||||
|
||||
def test_runs_with_steps_and_accounts(self):
|
||||
"""The bot's newer run records (one folder per account) become trajectories without account names or
|
||||
prose; the top-level files mirror the first account and are skipped."""
|
||||
run = {"runId": "run-1", "attempt": 3, "accountAttempt": 3, "accountId": "someone-example-com",
|
||||
"accountRole": "research", "startedAt": "2026-11-09T22:02:14.430Z", "targetDragon": "black",
|
||||
"decisionMode": "atlas_policy", "policyId": "atlas:x", "outcome": "BURNED", "intentionalBurn": True,
|
||||
"burn": {"reason": "TREE_NO_SHADOW_AUTO_BURN"}, "dragonColor": None,
|
||||
"steps": [{"nodeId": "a68f681076c6", "stage": "ENTER_THRESHING", "choiceText": "Find the tallest tree and climb for a better view",
|
||||
"offered": [{"text": "Find the tallest tree and climb for a better view"}, {"text": "Continue toward the center of the valley"}],
|
||||
"observed": {"shadow": False, "dragons": ["Green"]}, "propensity": 0.5, "toKey": "TERMINAL:BURNED",
|
||||
"label": "x" * 300, "prose": "game text"}]}
|
||||
line = json.dumps(run) + "\n"
|
||||
files = {"data/runs.jsonl": line, "data/accounts/someone-example-com/runs.jsonl": line,
|
||||
"logs/accounts/someone-example-com/encounters.jsonl": ""}
|
||||
accts = bot._account_files(files)
|
||||
self.assertEqual(list(accts), ["someone-example-com"])
|
||||
t = bot.trajectory_from_run(run, "abc123")
|
||||
self.assertEqual(t["steps"][0]["seen"], {"dragons": ["green"], "shadow": False})
|
||||
self.assertEqual((t["steps"][0]["to"], t["meta"]["accountKey"], t["outcome"]["reason"]), ("BURNED", "abc123", "TREE_NO_SHADOW_AUTO_BURN"))
|
||||
text = json.dumps(t)
|
||||
self.assertNotIn("someone", text)
|
||||
self.assertNotIn("game text", text)
|
||||
bot.check_public(t, {"prose", "accountId"}, 200)
|
||||
|
||||
def test_graph_js_crosswalk_is_generated(self):
|
||||
self.assertEqual(codegen.graph_js(), (ROOT / codegen.GRAPH_JS).read_text(encoding="utf-8"))
|
||||
|
||||
@@ -120,7 +148,8 @@ class Handoff(unittest.TestCase):
|
||||
z = TMP / "ken.zip"
|
||||
with zipfile.ZipFile(z, "w") as f: # files under a top folder, as a zipped repo would have them
|
||||
for rel in spec["files"]:
|
||||
f.write(FX / rel, f"DragonKind-main/{rel}")
|
||||
if "*" not in rel:
|
||||
f.write(FX / rel, f"DragonKind-main/{rel}")
|
||||
self.assertEqual(extract.pack_local(spec, z), extract.pack_local(spec, FX))
|
||||
empty = TMP / "empty.zip"
|
||||
with zipfile.ZipFile(empty, "w") as f:
|
||||
@@ -139,6 +168,54 @@ class Handoff(unittest.TestCase):
|
||||
json.loads((ROOT / "data/public/policy.json").read_text(encoding="utf-8"))["id"])
|
||||
|
||||
|
||||
class Forge(unittest.TestCase):
|
||||
GITEA = {"kind": "gitea", "url": "https://git.example.net/", "repo": "me/threshing-atlas", "branch": "main"}
|
||||
GITHUB = {"kind": "github", "url": "https://github.com", "repo": "me/threshing-atlas", "branch": "main"}
|
||||
|
||||
def test_links(self):
|
||||
from collection.etl import forge
|
||||
self.assertEqual(forge.file_url("data/x.csv", self.GITEA), "https://git.example.net/me/threshing-atlas/raw/branch/main/data/x.csv")
|
||||
self.assertEqual(forge.file_url("data/x.csv", self.GITHUB), "https://raw.githubusercontent.com/me/threshing-atlas/main/data/x.csv")
|
||||
self.assertIn("template=.github/ISSUE_TEMPLATE/report-a-run.yml", forge.new_issue_url(".github/ISSUE_TEMPLATE/report-a-run.yml", self.GITEA))
|
||||
self.assertTrue(forge.new_issue_url(".github/ISSUE_TEMPLATE/report-a-run.yml", self.GITHUB).endswith("template=report-a-run.yml"))
|
||||
self.assertEqual(forge.api_base(self.GITEA), "https://git.example.net/api/v1/repos/me/threshing-atlas")
|
||||
|
||||
def test_gitea_calls(self):
|
||||
from collection.etl import forge
|
||||
calls = []
|
||||
|
||||
def fake(method, url, body=None, tok=None, f=None):
|
||||
calls.append((method, url, body, tok))
|
||||
if url.endswith("/pulls"):
|
||||
return {"number": 7}
|
||||
if "/issues?" in url:
|
||||
page = int(url.rsplit("page=", 1)[1])
|
||||
return [{"number": 50 * (page - 1) + i, "body": "", "labels": [], "state": "open"} for i in range(50 if page == 1 else 3)]
|
||||
return None
|
||||
old = forge._call
|
||||
forge._call = fake
|
||||
try:
|
||||
issues = forge.list_issues("run report", {"ATLAS_BOT_TOKEN": "t"}, self.GITEA)
|
||||
self.assertEqual(len(issues), 53)
|
||||
self.assertIsNone(issues[0]["state_reason"])
|
||||
self.assertIn("type=issues", calls[0][1])
|
||||
self.assertEqual(forge.open_pr("data/x", "T", "B", True, {"ATLAS_BOT_TOKEN": "t"}, self.GITEA), 7)
|
||||
merge = calls[-1]
|
||||
self.assertTrue(merge[1].endswith("/pulls/7/merge") and merge[2]["merge_when_checks_succeed"])
|
||||
self.assertEqual(merge[3], "t")
|
||||
finally:
|
||||
forge._call = old
|
||||
|
||||
def test_page_links_follow_forge_yaml(self):
|
||||
from collection.etl import codegen, forge
|
||||
links = codegen.links()
|
||||
self.assertEqual(links["repo"], forge.repo_url())
|
||||
self.assertTrue(links["report"].startswith(forge.repo_url()))
|
||||
page = (ROOT / "site/atlas/index.html").read_text(encoding="utf-8")
|
||||
for key in set(re.findall(r"\{\{(\w+)\}\}", page)):
|
||||
self.assertIn(key, links)
|
||||
|
||||
|
||||
class Sheets(unittest.TestCase):
|
||||
def test_privacy_rules(self):
|
||||
p = TMP / "sheet.csv"
|
||||
|
||||
@@ -110,3 +110,18 @@ test("solverHistory turns form variables into a history keyed by the game's step
|
||||
assert.strictEqual(l.leave, "Leave them");
|
||||
assert.strictEqual(l.red, "Let it pass (two Greens)");
|
||||
});
|
||||
|
||||
test("Thompson sampling: one posterior draw per seed, with the chance of each pick", () => {
|
||||
const S = require("../../core/solver.js");
|
||||
const P = require("../../data/public/policy.json");
|
||||
const best = S.advisor(P.samples.all, "Blue", "eventually").next({});
|
||||
assert.strictEqual(best.propensity, 1);
|
||||
const a = S.advisor(P.samples.all, "Blue", "eventually", { sampling: "thompson", seed: 3, draws: 8 });
|
||||
const b = S.advisor(P.samples.all, "Blue", "eventually", { sampling: "thompson", seed: 3, draws: 8 });
|
||||
const ra = a.next({}), rb = b.next({});
|
||||
assert.strictEqual(ra.choice, rb.choice); // same seed, same draw
|
||||
assert.ok(ra.propensity >= 0 && ra.propensity <= 1);
|
||||
const picks = new Set();
|
||||
for (let s = 1; s <= 12; s++) picks.add(S.advisor(P.samples.all, "Blue", "eventually", { sampling: "thompson", seed: s, draws: 1 }).next({}).choice);
|
||||
assert.ok(picks.size > 1, "different seeds explore different options");
|
||||
});
|
||||
|
||||
@@ -43,13 +43,4 @@ test("Beta credible interval", () => {
|
||||
assert.ok(p.lo >= 0 && p.hi < 0.5 && p.mean === 0.1);
|
||||
});
|
||||
|
||||
test("every choice the bot has seen maps onto a form variable, except answers inside a bonding encounter", () => {
|
||||
const scenes = require("../../data/bot/scenes.json");
|
||||
const unmapped = [];
|
||||
for (const s of Object.values(scenes)) {
|
||||
if (s.options.length < 2) continue; // nothing to choose
|
||||
if (/two Greens in the clearing/.test(s.label)) continue; // answers at the Greens' encounter: not modelled yet
|
||||
for (const o of s.options) if (!G.CROSSWALK.some(([re]) => re.test(G.norm(o.text)))) unmapped.push(`${s.label}: ${o.text}`);
|
||||
}
|
||||
assert.deepStrictEqual(unmapped, []);
|
||||
});
|
||||
// every route choice the bot has seen maps onto a column: tests/collection/test_collection.py (Bot)
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
"""Reporting-bias correction (core/atlas/bias.py)."""
|
||||
import unittest
|
||||
|
||||
from atlas import bias, model
|
||||
|
||||
CFG = {"rolls": {"meadow": "Blue"}, "min_runs": 30, "min_complete_rare": 5,
|
||||
"groups": [{"name": "bot", "when": {"source": "bot"}, "complete": True},
|
||||
{"name": "form", "when": {"source": "reddit spreadsheet"}}]}
|
||||
|
||||
|
||||
def meadow_run(source, colour):
|
||||
r = {"source": source, "entry": "Form", "goal": "Any (for fun)", "company": "Alone", "direction": "Center",
|
||||
"first_sighting": "Red", "sighting_action": None, "left_squadmates": None, "scream": "Ignore the scream",
|
||||
"resolution": "Tourniquet", "post_path": "(no fork)", "hour": "Valley", "branch": "Passed the Red: meadow",
|
||||
"outcome": "Incinerated", "outcome_color": colour, "malek_intent": "No", "rare_reported": None,
|
||||
"saw_blue_meadow": colour == "Blue"}
|
||||
for c in model.COLOURS:
|
||||
r["enc_" + c] = "Incinerated" if c == colour else None
|
||||
return r
|
||||
|
||||
|
||||
class Bias(unittest.TestCase):
|
||||
def runs(self, bot_blue, bot_n, form_blue, form_n):
|
||||
return ([meadow_run("bot", "Blue")] * bot_blue + [meadow_run("bot", "Orange")] * (bot_n - bot_blue) +
|
||||
[meadow_run("reddit spreadsheet", "Blue")] * form_blue + [meadow_run("reddit spreadsheet", "Orange")] * (form_n - form_blue))
|
||||
|
||||
def test_over_reporting_is_estimated_and_corrected(self):
|
||||
runs = self.runs(10, 100, 100, 300) # 10% when everything is logged, 33% in the form
|
||||
prep = [model.prepare_run(r) for r in runs]
|
||||
est, names = bias.estimate(runs, prep, CFG, set())
|
||||
rho = est["form"]["meadow"]["rho"]
|
||||
self.assertAlmostEqual(rho, 4.4, delta=0.5)
|
||||
self.assertLess(est["form"]["meadow"]["lo"], rho)
|
||||
self.assertGreater(est["form"]["meadow"]["hi"], rho)
|
||||
T = model.count_tables(prep, bias.weights(names, prep, est, CFG["rolls"]))
|
||||
c = T["meadow"]["0:"]
|
||||
# corrected: the form's Blue sightings count 1/rho each, so the pooled rate is close to what the bot sees
|
||||
self.assertAlmostEqual(c["Blue"] / (c["Blue"] + c["Orange"]), 0.10, delta=0.02)
|
||||
|
||||
def test_unestimable_bias_leaves_the_group_out(self):
|
||||
runs = self.runs(0, 200, 60, 300) # complete logging never saw it
|
||||
prep = [model.prepare_run(r) for r in runs]
|
||||
est, names = bias.estimate(runs, prep, CFG, set())
|
||||
self.assertTrue(est["form"]["meadow"]["exclude"])
|
||||
T = model.count_tables(prep, bias.weights(names, prep, est, CFG["rolls"]))
|
||||
self.assertEqual(T["meadow"]["0:"], {"Orange": 200})
|
||||
# a roll seen only one way: routes cannot be told apart, so it is pooled fully
|
||||
self.assertEqual(model.fit_alpha(T, "meadow")["alpha"], max(model.ALPHA_GRID))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class Gate(unittest.TestCase):
|
||||
def test_closed_gate_fixes_the_roll_and_is_not_counted(self):
|
||||
spec = model.CHANCE["shadow"]
|
||||
self.assertTrue(spec.get("requires"))
|
||||
state = {"scream": "Keep walking"}
|
||||
self.assertFalse(model.gate_open("shadow", state))
|
||||
p = model.Params({"shadow": {"0:": {"yes": 5, "no": 5}}}, "mean").chance("shadow", state)
|
||||
self.assertEqual((float(p["yes"][0]), float(p["no"][0])), (0.0, 1.0))
|
||||
# a tree run that ignored the scream says nothing about the shadow
|
||||
run = meadow_run("bot", "Orange")
|
||||
run.update(hour="Tree", branch="Descend slowly: two Greens", scream="Ignore the scream")
|
||||
self.assertIsNone(model.OBSERVE["shadow"](model.prepare_run(run)))
|
||||
run.update(scream="Investigate & help", resolution="Killed the bullies yourself", post_path="Forest",
|
||||
combat_first="Assess the situation", combat_second="Engage the smaller cadet")
|
||||
self.assertEqual(model.OBSERVE["shadow"](model.prepare_run(run)), "no")
|
||||
|
||||
|
||||
class PossibleBonds(unittest.TestCase):
|
||||
def test_impossible_bond_is_not_counted(self):
|
||||
good = meadow_run("reddit spreadsheet", "Orange")
|
||||
good.update(hour="Tree", branch="Shadow (rare)", outcome="Bonded", outcome_color="Black", enc_Black="Bonded!",
|
||||
enc_Orange=None, goal="Black", scream="Investigate & help", resolution="Killed the bullies yourself",
|
||||
post_path="Forest", combat_first="Assess the situation", combat_second="Engage the smaller cadet")
|
||||
bad = dict(good, enc_Black=None, enc_Blue="Incinerated", outcome_color="Green", goal="Any (for fun)")
|
||||
T = model.count_tables([model.prepare_run(good), model.prepare_run(bad)])
|
||||
self.assertEqual(T["encounter"]["shadow-Black"]["outcomes"], {"Black": 1})
|
||||
self.assertEqual(T["encounter"]["shadow-Blue"]["outcomes"], {}) # a Green at the Blue: not counted
|
||||
self.assertTrue(model.can_bond("tree-Greens", "Brown"))
|
||||
Reference in New Issue
Block a user