Add kiesel_temperature_logging/src/kiesel_temperature_logging/cli.py
This commit is contained in:
parent
fe129bcc7b
commit
a5abca36ac
1 changed files with 53 additions and 0 deletions
|
|
@ -0,0 +1,53 @@
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Dict
|
||||||
|
|
||||||
|
from kiesel_temperature_logging import core
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""CLI entrypoint for Kiesel Temperature Logging and Analysis."""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="CLI zur Analyse von Kieseltemperaturdaten."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--input",
|
||||||
|
required=True,
|
||||||
|
help="Pfad zur Eingabedatei mit Temperatur-Logs (JSON).",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
required=False,
|
||||||
|
help="Pfad zur Ausgabedatei mit Analysedaten (JSON).",
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_path = Path(args.input)
|
||||||
|
output_path = Path(args.output) if args.output else Path("output/temperature_analysis.json")
|
||||||
|
|
||||||
|
if not input_path.exists():
|
||||||
|
raise FileNotFoundError(f"Eingabedatei {input_path} wurde nicht gefunden.")
|
||||||
|
|
||||||
|
with input_path.open("r", encoding="utf-8") as f:
|
||||||
|
try:
|
||||||
|
data: List[Dict] = json.load(f)
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
raise ValueError(f"Ungültiges JSON-Eingabeformat: {e}") from e
|
||||||
|
|
||||||
|
if not isinstance(data, list):
|
||||||
|
raise ValueError("Eingabedaten müssen eine Liste von Temperatur-Logs sein.")
|
||||||
|
|
||||||
|
# Analyse aufrufen
|
||||||
|
analysis_result = core.analyze_temperature_pulses(data)
|
||||||
|
|
||||||
|
# Output speichern
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with output_path.open("w", encoding="utf-8") as f_out:
|
||||||
|
json.dump(analysis_result, f_out, indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
|
print(f"Analyse abgeschlossen. Ergebnis gespeichert in: {output_path}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue