Add artifact.1/src/artifact_1/cli.py
This commit is contained in:
parent
52abc3d326
commit
45ab201043
1 changed files with 52 additions and 0 deletions
52
artifact.1/src/artifact_1/cli.py
Normal file
52
artifact.1/src/artifact_1/cli.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from artifact_1 import core
|
||||
|
||||
|
||||
def _load_run_data(file_paths: List[str]):
|
||||
run_data_list = []
|
||||
for path_str in file_paths:
|
||||
path = Path(path_str)
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(f"Run data file not found: {path_str}")
|
||||
with path.open('r', encoding='utf-8') as f:
|
||||
try:
|
||||
data = json.load(f)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f"Invalid JSON content in {path_str}: {e}") from e
|
||||
required_fields = {"run_id", "healing_rate", "overhead_ms", "warn_rate", "unknown_rate"}
|
||||
if not required_fields.issubset(data.keys()):
|
||||
raise ValueError(f"Missing required fields in {path_str}. Required: {required_fields}")
|
||||
run_data_list.append(data)
|
||||
return run_data_list
|
||||
|
||||
|
||||
def _save_results(output_path: str, results):
|
||||
path = Path(output_path)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with path.open('w', encoding='utf-8') as f:
|
||||
json.dump(results, f, indent=2)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Analyse und Aggregation von Run-Daten (15 und 16)")
|
||||
parser.add_argument('--input', nargs='+', required=True, help='Pfade zu Run-Daten JSON-Dateien')
|
||||
parser.add_argument('--output', required=True, help='Pfad für die Ausgabedatei mit Ergebnissen')
|
||||
args = parser.parse_args()
|
||||
|
||||
run_data_list = _load_run_data(args.input)
|
||||
results = core.analyze_runs(run_data_list)
|
||||
|
||||
if isinstance(results, dict):
|
||||
_save_results(args.output, results)
|
||||
elif hasattr(results, '__dict__'):
|
||||
_save_results(args.output, results.__dict__)
|
||||
else:
|
||||
raise TypeError("Unexpected result type from analyze_runs")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in a new issue