feat(schema, csv_parser): Update activity log schema and parsing logic
Deploy Development / deploy (push) Successful in 48s
Build Test / pytest-backend (push) Successful in 3s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 16s

- Increased precision for `kcal_active`, `kcal_resting`, `hr_avg`, and `hr_max` fields in the activity log schema.
- Added a new function `_activity_hr_bpm` to validate heart rate values during CSV import, ensuring they fall within plausible ranges.
- Updated the CSV parser to utilize the new heart rate validation function for improved data integrity.
- Enhanced the type converter to accommodate additional aliases for energy fields in CSV imports.
- Added a test to verify conversion of active energy from kJ to kcal, ensuring accurate data handling.
This commit is contained in:
Lars committed 2026-04-11 06:41:23 +02:00
1 parent 08a2485f43
commit 6945b748cb
7 files changed
+70 -11

No files matched your search

@@ -145,7 +145,7 @@ INSERT INTO csv_field_mappings (
SELECT
NULL, true, 'activity', 'Apple Health Workout Export (Deutsch)',
'Apple Health CSV-Export für Workouts (Deutsch). Automatisches Training-Type-Mapping.',
ARRAY['Aktive Energie (kcal)', 'Dauer', 'Durchschnittliche Herzfrequenz (bpm)', 'Ende', 'Start', 'Strecke (km)', 'Trainingsart']::TEXT[],
ARRAY['Aktive Energie (kJ)', 'Aktive Energie (kcal)', 'Dauer', 'Durchschnittliche Herzfrequenz (bpm)', 'Ende', 'Ruheeinträge (kJ)', 'Start', 'Strecke (km)', 'Trainingsart']::TEXT[],
',', 'utf-8', true,
'{
"Trainingsart": "activity_type",
@@ -154,15 +154,18 @@ SELECT
"Dauer": "duration_min",
"Strecke (km)": "distance_km",
"Aktive Energie (kcal)": "kcal_active",
"Aktive Energie (kJ)": "kcal_active",
"Ruheeinträge (kJ)": "kcal_resting",
"Durchschnittliche Herzfrequenz (bpm)": "hr_avg"
}'::JSONB,
'{
"start_time": {"type": "datetime", "format": "yyyy-mm-dd HH:MM:SS", "extract": "date_and_time", "flexible": true},
"end_time": {"type": "datetime", "format": "yyyy-mm-dd HH:MM:SS", "flexible": true},
"duration_min": {"type": "duration", "format": "HH:MM:SS", "target_unit": "minutes"},
"distance_km": {"type": "float", "decimal_separator": ","},
"kcal_active": {"type": "float", "decimal_separator": ","},
"hr_avg": {"type": "int"}
"distance_km": {"type": "float", "decimal_separator": ",", "flexible": true},
"kcal_active": {"type": "float", "decimal_separator": ".", "flexible": true, "source_unit": "kj"},
"kcal_resting": {"type": "float", "decimal_separator": ".", "flexible": true, "source_unit": "kj"},
"hr_avg": {"type": "int", "flexible": true}
}'::JSONB
WHERE NOT EXISTS (
SELECT 1 FROM csv_field_mappings f