#!/usr/bin/env python3 """The project's judge: every certificate (*.json with "values") in the route's folder, verified exactly by verify_overlap.py. Both are in checks/judge/, which a check runs at the project's approved version. One line per certificate, then the best bound; metrics.json in the working directory gets the best bound as the score (lower is better). Fails when a certificate is unreadable or not admissible.""" import json import os import pathlib import sys from verify_overlap import CertificateError, certify, decimal_up 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: cert = json.loads(path.read_text()) except Exception as exc: print(f"{name}: unreadable ({exc})") bad += 1 continue if not isinstance(cert, dict) or "values" not in cert: continue try: result = certify(cert) except CertificateError as exc: print(f"{name}: not admissible: {exc}") bad += 1 continue print(f"{name}: n={result['n']}, mu <= {decimal_up(result['bound'])}") if best is None or result["bound"] < best[0]: best = (result["bound"], name) if best: pathlib.Path(os.getcwd(), "metrics.json").write_text(json.dumps({"score": float(best[0]), "score_exact": decimal_up(best[0])})) print(f"best upper bound {decimal_up(best[0])} ({best[1]})" if best else "no certificates to check") sys.exit(1 if bad else 0)