From 1d9540ae92dbac00694f8798a0e5939c2aeaa7ac Mon Sep 17 00:00:00 2001 From: Mika Date: Mon, 9 Feb 2026 16:01:11 +0000 Subject: [PATCH] Add policy_eval.py/src/policy_eval/cli.py --- policy_eval.py/src/policy_eval/cli.py | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 policy_eval.py/src/policy_eval/cli.py diff --git a/policy_eval.py/src/policy_eval/cli.py b/policy_eval.py/src/policy_eval/cli.py new file mode 100644 index 0000000..b2674ea --- /dev/null +++ b/policy_eval.py/src/policy_eval/cli.py @@ -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() \ No newline at end of file