Add artifact_1_band_width_analysis/src/artifact_1_band_width_analysis/cli.py
This commit is contained in:
parent
47b5a5b569
commit
ddefcf1dc6
1 changed files with 73 additions and 0 deletions
|
|
@ -0,0 +1,73 @@
|
|||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from artifact_1_band_width_analysis.core import calculate_statistics, compare_runs, RunData
|
||||
|
||||
def main() -> None:
|
||||
"""Command-line entry point for Band Width Analysis."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Analyse von Bandbreiten- und Retry-Kennzahlen für Systemruns."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--input",
|
||||
required=True,
|
||||
help="Pfad zur JSON-Datei mit RunData-Einträgen."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
required=True,
|
||||
help="Pfad für die Ausgabe der Analyseergebnisse."
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
input_path = Path(args.input)
|
||||
output_path = Path(args.output)
|
||||
|
||||
if not input_path.exists():
|
||||
raise FileNotFoundError(f"Eingabedatei nicht gefunden: {input_path}")
|
||||
|
||||
with input_path.open('r', encoding='utf-8') as f:
|
||||
try:
|
||||
raw_data = json.load(f)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f"Ungültiges JSON-Format: {e}")
|
||||
|
||||
if not isinstance(raw_data, list):
|
||||
raise ValueError("Erwartet wird eine Liste von RunData-Objekten im JSON.")
|
||||
|
||||
runs = []
|
||||
for idx, entry in enumerate(raw_data):
|
||||
if not all(k in entry for k in ("band_width", "aux", "near_expiry", "retry_tail_p99")):
|
||||
raise ValueError(f"Eintrag {idx} ist unvollständig: {entry}")
|
||||
try:
|
||||
run = RunData(
|
||||
band_width=float(entry["band_width"]),
|
||||
aux=int(entry["aux"]),
|
||||
near_expiry=float(entry["near_expiry"]),
|
||||
retry_tail_p99=float(entry["retry_tail_p99"])
|
||||
)
|
||||
except (TypeError, ValueError) as e:
|
||||
raise ValueError(f"Ungültige Datentypen in RunData {idx}: {e}")
|
||||
runs.append(run)
|
||||
|
||||
stats = calculate_statistics(runs)
|
||||
comparisons: list[dict[str, Any]] = []
|
||||
for i in range(len(runs) - 1):
|
||||
comp = compare_runs(runs[i], runs[i + 1])
|
||||
comparisons.append(comp)
|
||||
|
||||
result = {
|
||||
"statistics": stats,
|
||||
"comparisons": comparisons
|
||||
}
|
||||
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with output_path.open('w', encoding='utf-8') as f:
|
||||
json.dump(result, f, indent=2, ensure_ascii=False)
|
||||
|
||||
print(f"Analyse abgeschlossen. Ergebnisse gespeichert unter: {output_path}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue