Add data_analysis/src/data_analysis/cli.py
This commit is contained in:
parent
493679d565
commit
f3465d88de
1 changed files with 46 additions and 0 deletions
46
data_analysis/src/data_analysis/cli.py
Normal file
46
data_analysis/src/data_analysis/cli.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from data_analysis import core
|
||||
|
||||
|
||||
def _load_json(path: Path) -> Any:
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(f"Input file not found: {path}")
|
||||
with open(path, '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 idx, entry in enumerate(data):
|
||||
if not isinstance(entry, dict):
|
||||
raise ValueError(f"Entry at index {idx} is not a JSON object.")
|
||||
return data
|
||||
|
||||
|
||||
def _save_json(path: Path, data: Any) -> None:
|
||||
with open(path, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Analyse von Laufdaten zur Stabilitätsbewertung.")
|
||||
parser.add_argument("--input", required=True, help="Pfad zur JSON-Datei mit Run-Daten")
|
||||
parser.add_argument("--output", required=False, help="Dateipfad für das Ausgabeergebnis")
|
||||
args = parser.parse_args()
|
||||
|
||||
input_path = Path(args.input)
|
||||
output_path = Path(args.output) if args.output else Path("output/analysis_results.json")
|
||||
|
||||
run_data_list = _load_json(input_path)
|
||||
|
||||
results = core.analyze_data(run_data_list)
|
||||
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
_save_json(output_path, results)
|
||||
|
||||
print(f"Analyse abgeschlossen. Ergebnis gespeichert unter: {output_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue