#!/usr/bin/env python3 """The project's judge (the check `verify`): every candidate (*.json with "transitions") in the route's folder, checked exactly by snake.py; on the default branch, whose route folder is routes/, constructions/ too. Both files are in checks/judge/, which a check runs at the project's approved version. One line per candidate, then the score and the new records; metrics.json in the working directory gets the score (a float and its exact value), each dimension's longest snake and the dimensions above their records. Fails when a candidate is unreadable, malformed or not a snake.""" import json import os import pathlib import sys from snake import INSTANCES, RECORD, best_of, is_record, scan, score root = pathlib.Path(sys.argv[1]) roots = [root] + ([root.parent / "constructions"] if os.environ.get("SS_ROUTE_DIR") == "routes" else []) found, bad = [], 0 for name, instance, length in scan(roots): if instance is None: print(f"{name}: {length}") bad += 1 continue found.append((name, instance, length)) d = length - RECORD[instance] print(f"{instance}: {length} edges ({name}), {d:+d} against the record{'; a new record' if is_record(instance, length) else ''}") best = best_of(found) if best: s = score({k: v for k, (v, _) in best.items()}) new = [k for k in INSTANCES if k in best and is_record(k, best[k][0])] metrics = {"score": float(s), "score_exact": str(s), "subtasks": {k: best[k][0] for k in INSTANCES if k in best}, "new_records": new} pathlib.Path("metrics.json").write_text(json.dumps(metrics) + "\n") print(f"score {float(s):.9f}; " + (f"new records: {', '.join(new)}" if new else "no new record")) else: print(f"no valid candidates: {bad} failed" if bad else "no candidates to check") sys.exit(1 if bad else 0)