Add data_analysis_script/src/data_analysis_script/cli.py
This commit is contained in:
parent
d65baef617
commit
6cb3046a27
1 changed files with 57 additions and 0 deletions
57
data_analysis_script/src/data_analysis_script/cli.py
Normal file
57
data_analysis_script/src/data_analysis_script/cli.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
from __future__ import annotations
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import logging
|
||||
|
||||
from data_analysis_script.core import analyze_logs, AnalysisResults
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""CLI entrypoint for the Run 26 Log Analysis."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Analyse Run 26 experiment logs and compute latency metrics."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--log_file",
|
||||
required=True,
|
||||
help="Pfad zur Eingabe-Logdatei im CSV- oder JSON-Format."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
required=False,
|
||||
default="output/run_26_analysis_results.json",
|
||||
help="Pfad zur Ausgabe-JSON-Datei mit Analyseergebnissen."
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
log_path = Path(args.log_file)
|
||||
if not log_path.exists():
|
||||
sys.stderr.write(f"Error: Log file not found: {log_path}\n")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
result: AnalysisResults = analyze_logs(str(log_path))
|
||||
except Exception as exc:
|
||||
logging.exception("Failed to analyze logs: %s", exc)
|
||||
sys.stderr.write(f"Error: {exc}\n")
|
||||
sys.exit(2)
|
||||
|
||||
output_path = Path(args.output)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
try:
|
||||
with output_path.open("w", encoding="utf-8") as f:
|
||||
json.dump(result.to_json(), f, indent=2)
|
||||
except Exception as exc:
|
||||
logging.exception("Failed to write output file: %s", exc)
|
||||
sys.stderr.write(f"Error writing output file: {exc}\n")
|
||||
sys.exit(3)
|
||||
|
||||
print(f"Analysis complete. Results saved to {output_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue