#!/usr/bin/env python3 """The project's judge: every candidate (*.json with "heights") in the route's folder, checked exactly by autocorrelation.py. Both are in checks/judge/, which a check runs at the project's approved version. One line per candidate, then the best upper bound, which it also writes to metrics.json here; fails when a candidate is unreadable or not admissible.""" import json import pathlib import sys from autocorrelation import CandidateError, decimal_up, ratio root = pathlib.Path(sys.argv[1]) best, bad = None, 0 for path in sorted(root.rglob("*.json")) if root.exists() else []: name = path.relative_to(root) try: candidate = json.loads(path.read_text()) except Exception as exc: print(f"{name}: unreadable ({exc})") bad += 1 continue if not isinstance(candidate, dict) or "heights" not in candidate: continue try: n, r = ratio(candidate) except CandidateError as exc: print(f"{name}: invalid: {exc}") bad += 1 continue print(f"{name}: {n} steps, C <= {decimal_up(r)}") if best is None or r < best[0]: best = (r, name) if best: pathlib.Path("metrics.json").write_text(json.dumps({"score": float(best[0]), "score_exact": decimal_up(best[0], 25)}) + "\n") print(f"best upper bound C <= {decimal_up(best[0])} ({best[1]})") else: print(f"no valid candidates: {bad} failed" if bad else "no candidates to check") sys.exit(1 if bad else 0)