Add python_analysis_script/src/python_analysis_script/cli.py
This commit is contained in:
parent
8defa11f88
commit
1af3ebbf6c
1 changed files with 52 additions and 0 deletions
52
python_analysis_script/src/python_analysis_script/cli.py
Normal file
52
python_analysis_script/src/python_analysis_script/cli.py
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Any
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
from python_analysis_script import core
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""CLI-Einstiegspunkt für die Analyse von Backtest-CSV-Daten."""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Analysiert Backtest-Ergebnisse gemäß CI-Policy und schreibt Entscheidungsresultate in eine JSON-Datei."
|
||||||
|
)
|
||||||
|
parser.add_argument("--input", required=True, help="Pfad zur Eingabe-CSV-Datei mit Backtest-Daten")
|
||||||
|
parser.add_argument("--output", required=True, help="Pfad zur Ausgabe-JSON-Datei")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_path = Path(args.input)
|
||||||
|
output_path = Path(args.output)
|
||||||
|
|
||||||
|
# Überprüfen, dass Eingabedatei existiert
|
||||||
|
if not input_path.exists() or not input_path.is_file():
|
||||||
|
raise FileNotFoundError(f"Die Eingabedatei '{input_path}' wurde nicht gefunden.")
|
||||||
|
|
||||||
|
# Analyse ausführen
|
||||||
|
results = core.analyze_backtest(str(input_path))
|
||||||
|
|
||||||
|
# Ergebnis validieren und serialisieren
|
||||||
|
def to_serializable(obj: Any) -> Any:
|
||||||
|
if isinstance(obj, datetime):
|
||||||
|
return obj.isoformat()
|
||||||
|
return obj
|
||||||
|
|
||||||
|
serialized_results = [
|
||||||
|
{k: to_serializable(v) for k, v in r.__dict__.items()} for r in results
|
||||||
|
]
|
||||||
|
|
||||||
|
# Ausgabe-Verzeichnis sicherstellen
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
# JSON-Datei schreiben
|
||||||
|
with output_path.open("w", encoding="utf-8") as f:
|
||||||
|
json.dump(serialized_results, f, indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
|
# Kurze Erfolgsrückmeldung mit Anzahl Ergebnisse
|
||||||
|
print(f"Analyse abgeschlossen: {len(serialized_results)} Resultate -> {output_path}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue