| 1 | #!/usr/bin/env python3
|
| 2 | """Evaluate benchmark rows against a Git Baseline Book and target file."""
|
| 3 |
|
| 4 | from __future__ import annotations
|
| 5 |
|
| 6 | import argparse
|
| 7 | import json
|
| 8 | import sys
|
| 9 | from pathlib import Path
|
| 10 |
|
| 11 | ROOT = Path(__file__).resolve().parents[1]
|
| 12 | sys.path.insert(0, str(ROOT / "scripts"))
|
| 13 |
|
| 14 | from oakbench.baseline_book import load_baseline_book, load_targets # noqa: E402
|
| 15 | from oakbench.scorecard import evaluate_targets, load_jsonl # noqa: E402
|
| 16 |
|
| 17 |
|
| 18 | def parse_args() -> argparse.Namespace:
|
| 19 | parser = argparse.ArgumentParser(description=__doc__)
|
| 20 | parser.add_argument("jsonl", nargs="+", type=Path, help="candidate row JSONL")
|
| 21 | parser.add_argument("--baseline-book", required=True, type=Path)
|
| 22 | parser.add_argument("--targets", type=Path, default=ROOT / "config" / "targets.json")
|
| 23 | parser.add_argument("--bootstrap-samples", type=int, default=2000)
|
| 24 | parser.add_argument("--confidence", type=float, default=0.95)
|
| 25 | parser.add_argument("--json", action="store_true")
|
| 26 | return parser.parse_args()
|
| 27 |
|
| 28 |
|
| 29 | def main() -> int:
|
| 30 | args = parse_args()
|
| 31 | rows = load_jsonl(args.jsonl)
|
| 32 | targets = load_targets(args.targets)
|
| 33 | baseline = load_baseline_book(args.baseline_book)
|
| 34 | results = evaluate_targets(
|
| 35 | rows,
|
| 36 | targets,
|
| 37 | baseline,
|
| 38 | bootstrap_samples=args.bootstrap_samples,
|
| 39 | confidence=args.confidence,
|
| 40 | )
|
| 41 | if args.json:
|
| 42 | print(json.dumps(results, sort_keys=True))
|
| 43 | else:
|
| 44 | print("| Target | Verdict | Ratio | Goal | n | Notes |")
|
| 45 | print("| --- | --- | ---: | ---: | ---: | --- |")
|
| 46 | for row in results:
|
| 47 | ratio = row.get("ratio")
|
| 48 | ratio_text = "" if ratio is None else f"{ratio:.3f}"
|
| 49 | notes = "; ".join(str(item) for item in row.get("messages", []))
|
| 50 | print(
|
| 51 | f"| `{row['target_id']}` | {row['verdict']} | {ratio_text} | "
|
| 52 | f"{row['goal_value']:.3f} | {row['n']} | {notes} |"
|
| 53 | )
|
| 54 | return 1 if any(row["verdict"] in {"RED", "INVALID"} for row in results) else 0
|
| 55 |
|
| 56 |
|
| 57 | if __name__ == "__main__":
|
| 58 | raise SystemExit(main())
|