Add TRK set preview and refresh draft analysis

Track the TRK preview package and the newest value artifacts for FRA20261007, move the 17lands API notes under data, and ignore downloaded 17lands, card image and live directories.
This commit is contained in:
2026-11-15 11:37:16 +08:00
parent 4984b1f756
commit 58446ec562
1131 changed files with 1430660 additions and 189314 deletions
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env python
"""Build a per-draft "cards that were offered" index from 17lands draftdata.
For each replay in <snapshot>/draftdata/<draft_id>.json we union every entry of
``picks[].available[]`` (the pack contents the seat actually saw) into a set of
card names, then cache ``{draft_id: [names...]}`` to value/<snapshot>/offer_index.json.
This lets the template builder compute a rarity-fair inclusion:
P(card is played | card was offered to this seat)
which removes the bias that rare/mythic cards are simply never passed to you.
"""
from __future__ import annotations
import argparse
import json
from pathlib import Path
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--snapshot", required=True, help="e.g. data/17lands/FRA20261007")
ap.add_argument("--out", required=True, help="e.g. value/FRA20261007")
ap.add_argument("--force", action="store_true")
args = ap.parse_args()
snapshot = Path(args.snapshot)
out = Path(args.out)
dest = out / "offer_index.json"
if dest.exists() and not args.force:
print(f"exists, skip: {dest} (use --force to rebuild)")
return 0
ddir = snapshot / "draftdata"
files = sorted(ddir.glob("*.json"))
index: dict[str, list[str]] = {}
for i, f in enumerate(files, 1):
try:
d = json.loads(f.read_text(encoding="utf-8"))
except Exception as e: # noqa: BLE001
print(f" !! {f.name}: {e}")
continue
seen: set[str] = set()
for pk in d.get("picks") or []:
for c in pk.get("available") or []:
nm = c.get("name")
if nm:
seen.add(nm)
if seen:
index[f.stem] = sorted(seen)
if i % 100 == 0:
print(f" {i}/{len(files)}")
out.mkdir(parents=True, exist_ok=True)
dest.write_text(json.dumps(index, ensure_ascii=False), encoding="utf-8")
avg = (sum(len(v) for v in index.values()) / len(index)) if index else 0
print(f"wrote {len(index)} drafts (avg {avg:.1f} cards offered) -> {dest}")
return 0
if __name__ == "__main__":
raise SystemExit(main())