Add data_analysis_tool/src/data_analysis_tool/cli.py
This commit is contained in:
parent
02866790e1
commit
00cb20f47f
1 changed files with 51 additions and 0 deletions
51
data_analysis_tool/src/data_analysis_tool/cli.py
Normal file
51
data_analysis_tool/src/data_analysis_tool/cli.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from data_analysis_tool.core import analyze_data
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Command-line entry point for Magnetometer Data Analysis Tool."""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Analysiert Magnetometerdaten aus einer CSV-Datei und erzeugt eine JSON-Ausgabedatei."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--input",
|
||||||
|
required=True,
|
||||||
|
help="Pfad zur CSV-Eingabedatei mit Magnetometerdaten."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
required=False,
|
||||||
|
default="output/analysis_results.json",
|
||||||
|
help="Pfad zur Ausgabe-JSON-Datei mit Analyseergebnissen."
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_path = Path(args.input)
|
||||||
|
output_path = Path(args.output)
|
||||||
|
|
||||||
|
# Input validation
|
||||||
|
if not input_path.exists() or not input_path.is_file():
|
||||||
|
raise FileNotFoundError(f"Eingabedatei nicht gefunden: {input_path}")
|
||||||
|
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
# Perform analysis
|
||||||
|
try:
|
||||||
|
results = analyze_data(str(input_path))
|
||||||
|
except Exception as e:
|
||||||
|
raise RuntimeError(f"Analysefehler: {e}") from e
|
||||||
|
|
||||||
|
# Write results to JSON file
|
||||||
|
try:
|
||||||
|
with open(output_path, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(json.loads(results.to_json()), f, indent=2)
|
||||||
|
print(f"Analyse abgeschlossen. Ergebnisse gespeichert in: {output_path}")
|
||||||
|
except Exception as e:
|
||||||
|
raise RuntimeError(f"Fehler beim Schreiben der Ausgabedatei: {e}") from e
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue