Add data_analysis/src/data_analysis/cli.py
This commit is contained in:
parent
b8c0720291
commit
b5a6fbc92a
1 changed files with 57 additions and 0 deletions
57
data_analysis/src/data_analysis/cli.py
Normal file
57
data_analysis/src/data_analysis/cli.py
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
from data_analysis import core
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""CLI entry point for City Breathing Data Analysis.
|
||||||
|
|
||||||
|
Parses input arguments, validates them, and executes the analysis pipeline:
|
||||||
|
loading CSV data and generating plots.
|
||||||
|
"""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Analyse und Visualisierung von City Breathing Messdaten.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--input",
|
||||||
|
required=True,
|
||||||
|
help="Pfad zur Eingabe-CSV-Datei mit Loggerdaten.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
required=False,
|
||||||
|
default="output/plots/overview.png",
|
||||||
|
help="Pfad zur Ausgabedatei der Visualisierung (PNG).",
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_path = Path(args.input)
|
||||||
|
output_path = Path(args.output)
|
||||||
|
|
||||||
|
# Input validation (CI-ready & strict input validation required)
|
||||||
|
if not input_path.exists() or not input_path.is_file():
|
||||||
|
print(f"Fehler: Eingabedatei '{input_path}' existiert nicht oder ist keine Datei.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if not input_path.suffix.lower() == ".csv":
|
||||||
|
print(f"Fehler: Eingabedatei muss eine CSV-Datei sein (gefunden: {input_path.suffix}).", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Ensure output directory exists
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
try:
|
||||||
|
data: pd.DataFrame = core.load_data(str(input_path))
|
||||||
|
core.plot_data(data)
|
||||||
|
print(f"Analyse abgeschlossen. Visualisierung gespeichert unter '{output_path}'.")
|
||||||
|
except Exception as exc: # broad for CLI safety
|
||||||
|
print(f"Fehler bei der Analyse: {exc}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue