File size: 1,968 Bytes
24f6204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from __future__ import annotations

import argparse
import json
from pathlib import Path
from typing import Any

from .provenance import require_file


def audit_strategy_benchmark(run_dir: str | Path) -> dict[str, Any]:
    root = Path(run_dir)
    summary = json.loads(require_file(root / "metrics" / "strategy_comparison_summary.json", "strategy benchmark summary").read_text(encoding="utf-8"))
    payload = {
        "run_dir": str(root),
        "recommended_strategy_final": summary.get("recommended_strategy_final"),
        "recommended_reason": summary.get("recommended_reason"),
        "reference_mode": summary.get("reference_mode"),
        "reference_sample_docked_once_for_evaluation": summary.get("reference_sample_docked_once_for_evaluation"),
        "strategies": list((summary.get("by_strategy") or {}).keys()),
    }
    (root / "strategy_benchmark_audit.md").write_text(
        "\n".join(
            [
                f"# audit-strategy-benchmark: {root.name}",
                "",
                f"- recommended_strategy_final: `{payload['recommended_strategy_final']}`",
                f"- recommended_reason: `{payload['recommended_reason']}`",
                f"- reference_sample_docked_once_for_evaluation: `{payload['reference_sample_docked_once_for_evaluation']}`",
                f"- strategies: `{payload['strategies']}`",
            ]
        )
        + "\n",
        encoding="utf-8",
    )
    return payload


def build_arg_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(description="Audit a completed independent strategy benchmark run.")
    parser.add_argument("--run-dir", required=True)
    return parser


def run_from_args(args: argparse.Namespace) -> dict[str, Any]:
    return audit_strategy_benchmark(args.run_dir)


def main() -> int:
    print(json.dumps(run_from_args(build_arg_parser().parse_args()), indent=2))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())