Add run_analysis/src/run_analysis/cli.py
This commit is contained in:
parent
b62cff80a1
commit
29cad48f8b
1 changed files with 44 additions and 0 deletions
44
run_analysis/src/run_analysis/cli.py
Normal file
44
run_analysis/src/run_analysis/cli.py
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any, List
|
||||||
|
|
||||||
|
from run_analysis.core import analyze_run_data
|
||||||
|
|
||||||
|
|
||||||
|
def _load_run_data(path: Path) -> List[dict[str, Any]]:
|
||||||
|
if not path.exists():
|
||||||
|
raise FileNotFoundError(f"Input file not found: {path}")
|
||||||
|
with path.open('r', encoding='utf-8') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
if not isinstance(data, list):
|
||||||
|
raise ValueError("Expected input JSON to contain a list of run data objects.")
|
||||||
|
for item in data:
|
||||||
|
if not all(k in item for k in ("corr_id", "expires_at_dist_hours", "visibility_lag")):
|
||||||
|
raise ValueError(f"Missing required fields in input item: {item}")
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def _write_output(path: Path, result: dict[str, Any]) -> None:
|
||||||
|
with path.open('w', encoding='utf-8') as f:
|
||||||
|
json.dump(result, f, indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description="Analyse Δt<0 Fälle aus Run-Daten und erstelle eine kompakte JSON-Ausgabe.")
|
||||||
|
parser.add_argument("--input", required=True, help="Pfad zur JSON-Datei mit Run-Daten.")
|
||||||
|
parser.add_argument("--output", required=True, help="Pfad zur Ausgabedatei mit den Analyseergebnissen.")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_path = Path(args.input)
|
||||||
|
output_path = Path(args.output)
|
||||||
|
|
||||||
|
run_data = _load_run_data(input_path)
|
||||||
|
result = analyze_run_data(run_data)
|
||||||
|
assert isinstance(result, dict), "analyze_run_data() must return a dict."
|
||||||
|
|
||||||
|
_write_output(output_path, result)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue