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
@@ -41,7 +41,17 @@ _MODULE_HEADER_ALIASES: dict[str, dict[str, frozenset[str]]] = {
|
||||
"duration_min": frozenset({"dauer", "duration", "min"}),
|
||||
"distance_km": frozenset({"strecke", "distance", "km", "distanz"}),
|
||||
"kcal_active": frozenset({"kcal", "kalorie", "energie", "active"}),
|
||||
"hr_avg": frozenset({"puls", "heart", "hr", "bpm", "herzfrequenz"}),
|
||||
"kcal_resting": frozenset({"ruhe", "resting"}),
|
||||
"hr_avg": frozenset({"puls", "heart", "hr", "bpm", "herzfrequenz", "durchschn"}),
|
||||
"hr_max": frozenset({"max", "peak"}),
|
||||
},
|
||||
"vitals_baseline": {
|
||||
"date": frozenset({"datum", "date", "tag", "start", "zeit"}),
|
||||
"resting_hr": frozenset({"ruhepuls", "resting", "rhr"}),
|
||||
"hrv": frozenset({"hrv", "variabilit", "vfc"}),
|
||||
"vo2_max": frozenset({"vo2"}),
|
||||
"spo2": frozenset({"sauerstoff", "spo2", "oxygen"}),
|
||||
"respiratory_rate": frozenset({"atem", "respiratory"}),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -73,7 +83,22 @@ _DEFAULT_TYPE_CONVERSIONS: dict[str, dict[str, dict[str, Any]]] = {
|
||||
"duration_min": {"type": "duration", "format": "HH:MM:SS", "target_unit": "minutes", "flexible": True},
|
||||
"distance_km": {"type": "float", "decimal_separator": "auto", "flexible": True},
|
||||
"kcal_active": {"type": "float", "decimal_separator": "auto", "flexible": True},
|
||||
"kcal_resting": {"type": "float", "decimal_separator": "auto", "flexible": True},
|
||||
"hr_avg": {"type": "int", "flexible": True},
|
||||
"hr_max": {"type": "int", "flexible": True},
|
||||
},
|
||||
"vitals_baseline": {
|
||||
"date": {
|
||||
"type": "datetime",
|
||||
"format": "yyyy-mm-dd HH:MM:SS",
|
||||
"extract": "date_only",
|
||||
"flexible": True,
|
||||
},
|
||||
"resting_hr": {"type": "int", "flexible": True},
|
||||
"hrv": {"type": "int", "flexible": True},
|
||||
"vo2_max": {"type": "float", "decimal_separator": "auto", "flexible": True},
|
||||
"spo2": {"type": "int", "flexible": True},
|
||||
"respiratory_rate": {"type": "float", "decimal_separator": "auto", "flexible": True},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -131,6 +156,9 @@ def suggest_field_mappings(
|
||||
Mappt jede CSV-Spalte (Roh-Header als Key) auf DB-Feld oder '-'.
|
||||
Nutzt zuerst eine passende Seed-Vorlage, dann Alias-Heuristik.
|
||||
"""
|
||||
if module == "sleep":
|
||||
return {h: "-" for h in headers}
|
||||
|
||||
mod = get_module_definition(module)
|
||||
if not mod:
|
||||
return {h: "-" for h in headers}
|
||||
@@ -163,6 +191,9 @@ def build_type_conversions_for_mapping(
|
||||
seed_tc: Mapping[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""type_conversions nur für zugewiesene Zielfelder; Seed überschreibt Defaults."""
|
||||
if module == "sleep":
|
||||
return {}
|
||||
|
||||
defaults = _DEFAULT_TYPE_CONVERSIONS.get(module, {})
|
||||
out: dict[str, Any] = {}
|
||||
targets = {v for v in field_mappings.values() if v and v not in ("-", "_skip")}
|
||||
|
||||
Reference in new issue
Block a user