mitai-jinkendo/backend/migrations/053_csv_activity_apple_de_kj_energy.sql
Lars 6945b748cb
All checks were successful
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
feat(schema, csv_parser): Update activity log schema and parsing logic
- 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.
2026-04-11 06:41:23 +02:00

27 lines
1.0 KiB
SQL

-- Apple Health Workout (Deutsch): „Aktive Energie (kJ)“ / „Ruheeinträge (kJ)“ → DB speichert kcal.
-- type_conversions.source_unit „kj“ nutzt field_units (1/4.184).
UPDATE csv_field_mappings
SET
field_mappings = COALESCE(field_mappings, '{}'::jsonb)
|| '{"Aktive Energie (kJ)": "kcal_active", "Ruheeinträge (kJ)": "kcal_resting"}'::jsonb,
type_conversions = jsonb_set(
jsonb_set(
COALESCE(type_conversions, '{}'::jsonb),
'{kcal_active}',
COALESCE(type_conversions->'kcal_active', '{}'::jsonb) || '{"source_unit": "kj"}'::jsonb,
true
),
'{kcal_resting}',
COALESCE(
type_conversions->'kcal_resting',
'{"type": "float", "decimal_separator": ",", "flexible": true}'::jsonb
) || '{"source_unit": "kj"}'::jsonb,
true
)
WHERE is_system = true
AND profile_id IS NULL
AND module = 'activity'
AND mapping_name = 'Apple Health Workout Export (Deutsch)'
AND type_conversions IS NOT NULL;