"""Summarise a smoke_pictures.py output: per title, pictures equal to each detector. python scripts/sweep_summary.py tests/runs/m7-sweep-mame-pypy.txt [--failures OUT.tsv] """ import argparse import re from collections import defaultdict from pathlib import Path ROW = re.compile(r"^(.+?) +frame +(\d+) mame +(\S+) gearcoleco +(\S+)(?: mame-vs-gearcoleco +(\S+))?") def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("output", type=Path) parser.add_argument("--failures", type=Path) args = parser.parse_args() titles = defaultdict(list) for line in args.output.read_text(errors="replace").splitlines(): m = ROW.match(line) if m: titles[m.group(1).strip()].append(tuple(m.group(i) for i in range(2, 6))) counts = defaultdict(int) failures = [] for title, rows in titles.items(): mame_ok = all(r[1] == "0" for r in rows) gear_ok = all(r[2] == "0" for r in rows) det_agree = all(r[3] in ("0", None) for r in rows if r[3] is not None) no_gear = all(r[2] == "-" for r in rows) counts["titles"] += 1 counts["all 3 equal MAME"] += mame_ok counts["all 3 equal Gearcoleco"] += gear_ok counts["equal both"] += mame_ok and gear_ok counts["no Gearcoleco picture"] += no_gear counts["detectors disagree somewhere"] += not det_agree counts["equal MAME where detectors disagree"] += mame_ok and not det_agree if not mame_ok: failures.append((title, rows)) counts["pictures"] += len(rows) counts["pictures equal MAME"] += sum(r[1] == "0" for r in rows) counts["pictures equal Gearcoleco"] += sum(r[2] == "0" for r in rows) for k, v in counts.items(): print(f"{k}: {v}") print("differing from MAME:") for title, rows in failures: print(f" {title}: " + ", ".join(f"{r[0]}:{r[1]}/{r[2]}/{r[3]}" for r in rows)) if args.failures: args.failures.write_text( "# M7 sweep failures (pictures differing from MAME): the next smoke list\n" + "".join(f"{t}\t300,900,1500\t\t\n" for t, _ in failures), encoding="utf-8", ) return 0 if __name__ == "__main__": raise SystemExit(main())