54 lines
1.6 KiB
Python
Executable file
54 lines
1.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""batch-summary.py — concise per-game summary for any apricot batch dir.
|
|
|
|
Usage: python3 tools/batch-summary.py <batch-dir>
|
|
|
|
Prints one line per game:
|
|
<game_name>: T<turn> outcome=<outcome> winner=<personality> max_tier=<n> wonders=<n>
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def main(argv: list[str]) -> int:
|
|
if len(argv) != 2:
|
|
print(f"Usage: {argv[0]} <batch-dir>", file=sys.stderr)
|
|
return 2
|
|
root = Path(argv[1])
|
|
if not root.is_dir():
|
|
print(f"Not a directory: {root}", file=sys.stderr)
|
|
return 2
|
|
|
|
for game in sorted(root.glob("game_*")):
|
|
if not game.is_dir():
|
|
continue
|
|
ts = game / "turn_stats.jsonl"
|
|
if not ts.exists():
|
|
print(f"{game.name}: NO_STATS")
|
|
continue
|
|
try:
|
|
lines = [json.loads(line) for line in ts.read_text().splitlines() if line.strip()]
|
|
except Exception as e:
|
|
print(f"{game.name}: PARSE_ERR {e}")
|
|
continue
|
|
if not lines:
|
|
print(f"{game.name}: EMPTY")
|
|
continue
|
|
final = lines[-1]
|
|
ps = final.get("player_stats") or {}
|
|
max_tp = max((p.get("tier_peak", 0) for p in ps.values()), default=0)
|
|
wonders = sum(p.get("wonder_count", 0) for p in ps.values())
|
|
print(
|
|
f"{game.name}: T{final.get('turn')} "
|
|
f"outcome={final.get('outcome')} "
|
|
f"winner={final.get('winner_personality')} "
|
|
f"max_tier={max_tp} wonders={wonders}"
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv))
|