feat(csv-import): Enhance CSV import functionality with new modules and tests
- Added support for new CSV import modules: sleep and vitals_baseline, expanding the import capabilities. - Implemented backend logic for handling CSV imports related to sleep and vitals baseline, including error handling and data processing. - Updated frontend components to include new modules in the CSV import interface, improving user experience. - Introduced unit tests for the new import functionalities to ensure reliability and correctness. - Enhanced existing CSV analysis features to accommodate the new modules, ensuring consistent behavior across the application.
This commit is contained in:
1 parent
b4cc3cb934
commit
26ab11eb7b
14 files changed
+1261
-340
No files matched your search
@@ -27,19 +27,39 @@ MODULE_DEFINITIONS: Dict[str, Dict[str, Any]] = {
|
||||
"activity": {
|
||||
"table": "activity_log",
|
||||
"fields": {
|
||||
"date": {"type": "date", "required": True},
|
||||
"start_time": {"type": "time", "required": False},
|
||||
"end_time": {"type": "time", "required": False},
|
||||
"date": {"type": "date", "required": False},
|
||||
"start_time": {"type": "datetime", "required": False},
|
||||
"end_time": {"type": "datetime", "required": False},
|
||||
"activity_type": {"type": "string", "required": True},
|
||||
"duration_min": {"type": "float", "required": False, "min": 0},
|
||||
"kcal_active": {"type": "float", "required": False},
|
||||
"kcal_resting": {"type": "float", "required": False},
|
||||
"distance_km": {"type": "float", "required": False},
|
||||
"hr_avg": {"type": "float", "required": False, "min": 30, "max": 220},
|
||||
"hr_max": {"type": "float", "required": False, "min": 30, "max": 220},
|
||||
},
|
||||
"derive_date_from_datetime_field": "start_time",
|
||||
"duplicate_key": ["profile_id", "date", "start_time"],
|
||||
"duplicate_strategy": "update",
|
||||
},
|
||||
"sleep": {
|
||||
"table": "sleep_log",
|
||||
"fields": {},
|
||||
"import_mode": "apple_sleep_aggregate",
|
||||
},
|
||||
"vitals_baseline": {
|
||||
"table": "vitals_baseline",
|
||||
"fields": {
|
||||
"date": {"type": "date", "required": True},
|
||||
"resting_hr": {"type": "int", "required": False},
|
||||
"hrv": {"type": "int", "required": False},
|
||||
"vo2_max": {"type": "float", "required": False},
|
||||
"spo2": {"type": "int", "required": False},
|
||||
"respiratory_rate": {"type": "float", "required": False},
|
||||
},
|
||||
"duplicate_key": ["profile_id", "date"],
|
||||
"duplicate_strategy": "update",
|
||||
},
|
||||
"blood_pressure": {
|
||||
"table": "blood_pressure_log",
|
||||
"fields": {
|
||||
@@ -81,6 +101,14 @@ def validate_field_mappings(module: str, field_mappings: dict) -> None:
|
||||
raise ValueError(f"Unbekanntes Modul: {module}")
|
||||
fields = cast(dict, mod["fields"])
|
||||
allowed = set(fields.keys())
|
||||
if not allowed:
|
||||
for _csv_col, db_field in field_mappings.items():
|
||||
if db_field not in ("", None, "-", "_skip"):
|
||||
raise ValueError(
|
||||
f"Modul '{module}' nutzt einen Aggregat-Import ohne Spalten-Mapping; "
|
||||
f"alle Spalten müssen „ignorieren“ sein."
|
||||
)
|
||||
return
|
||||
for _csv_col, db_field in field_mappings.items():
|
||||
if db_field in ("", None, "-", "_skip"):
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user