Add policy_eval.py/src/policy_eval/cli.py

This commit is contained in:
Mika 2026-02-09 16:01:11 +00:00
parent 626a8abff8
commit 1d9540ae92

View file

@ -0,0 +1,71 @@
import argparse
import json
import sys
from pathlib import Path
import logging
from datetime import datetime
from policy_eval import core
def main() -> None:
"""CLI entrypoint to evaluate policy changes and run backtests."""
parser = argparse.ArgumentParser(
description="Policy Change Audit CLI prüft Policy-Konstanten und führt Backtests aus."
)
parser.add_argument(
"--constants",
required=True,
help="Pfad zur policy_constants.json"
)
parser.add_argument(
"--audit",
required=True,
help="Pfad zum fixierten Audit-Set (Verzeichnis)"
)
args = parser.parse_args()
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
constants_path = Path(args.constants)
audit_path = Path(args.audit)
if not constants_path.is_file():
logging.error(f"Policy-Konstanten-Datei nicht gefunden: {constants_path}")
sys.exit(1)
if not audit_path.exists():
logging.error(f"Audit-Set-Verzeichnis nicht gefunden: {audit_path}")
sys.exit(1)
try:
with constants_path.open('r', encoding='utf-8') as f:
policy_constants = json.load(f)
except json.JSONDecodeError as e:
logging.error(f"Fehler beim Lesen der Policy-Konfiguration: {e}")
sys.exit(1)
logging.info("Prüfe Policy-Änderungen...")
changed = core.check_policy_changes(policy_constants)
if changed:
logging.info("Änderungen erkannt. Starte Backtest...")
result = core.run_backtest(str(audit_path))
summary_path = result.get("delta_summary")
cases_path = result.get("delta_cases")
logging.info("Backtest abgeschlossen.")
logging.info(f"Delta Summary: {summary_path}")
logging.info(f"Delta Cases: {cases_path}")
else:
logging.info("Keine Änderungen festgestellt. Kein Backtest erforderlich.")
logging.info(f"Audit abgeschlossen um {datetime.now().isoformat(timespec='seconds')}")
if __name__ == "__main__":
main()