Add data_analysis_script/src/data_analysis_script/cli.py
This commit is contained in:
parent
61cfd4fdd7
commit
d1c13ecae8
1 changed files with 50 additions and 0 deletions
50
data_analysis_script/src/data_analysis_script/cli.py
Normal file
50
data_analysis_script/src/data_analysis_script/cli.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
import argparse
|
||||||
|
import csv
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Dict
|
||||||
|
|
||||||
|
from data_analysis_script import core
|
||||||
|
|
||||||
|
def _read_csv_data(file_path: Path) -> List[Dict[str, float]]:
|
||||||
|
data = []
|
||||||
|
with file_path.open(newline='', encoding='utf-8') as f:
|
||||||
|
reader = csv.DictReader(f)
|
||||||
|
for row in reader:
|
||||||
|
try:
|
||||||
|
data.append({
|
||||||
|
'condition_name': row['condition_name'],
|
||||||
|
'amplitude': float(row['amplitude']),
|
||||||
|
'timestamp': float(row['timestamp'])
|
||||||
|
})
|
||||||
|
except (KeyError, ValueError):
|
||||||
|
continue
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(description='Analyze measurement data for electric coupling.')
|
||||||
|
parser.add_argument('--input', required=True, help='Pfad zur CSV-Datei mit Messdaten.')
|
||||||
|
parser.add_argument('--output', required=True, help='Pfad zur JSON-Ausgabedatei für 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}')
|
||||||
|
|
||||||
|
data = _read_csv_data(input_path)
|
||||||
|
if not data:
|
||||||
|
raise ValueError('Keine gültigen Messdaten gefunden.')
|
||||||
|
|
||||||
|
result = core.analyze_data(data)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue