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

+12 -2
View File
@@ -776,6 +776,16 @@ def _sf_act(val: Any) -> float | None:
return None
def _activity_hr_bpm(val: Any) -> float | None:
"""Plausible Herzfrequenz (Import); größere Werte oft Fehlzuordnung (z. B. Schrittzahl) → NUMERIC-Overflow."""
v = _sf_act(val)
if v is None:
return None
if v < 20 or v > 280:
return None
return v
def _looks_like_time_only(s: str) -> bool:
t = s.strip()
if not t or " " in t:
@@ -867,8 +877,8 @@ def _import_activity(
kcal_a = _sf_act(mapped.get("kcal_active"))
kcal_r = _sf_act(mapped.get("kcal_resting"))
hr_a = _sf_act(mapped.get("hr_avg"))
hr_m = _sf_act(mapped.get("hr_max"))
hr_a = _activity_hr_bpm(mapped.get("hr_avg"))
hr_m = _activity_hr_bpm(mapped.get("hr_max"))
dist = _sf_act(mapped.get("distance_km"))
wtype = str(activity_type).strip()
+1 -1
View File
@@ -526,7 +526,7 @@ def _activity_alias_db_field(csv_col: str) -> str | None:
return "distance_km"
if "aktive_energie" in n or "active_energy" in n:
return "kcal_active"
if "ruheenergie" in n or "resting_energy" in n:
if "ruheeintr" in n or "ruheenergie" in n or "resting_energy" in n:
return "kcal_resting"
if ("herzfrequenz" in n or "heart_rate" in n) and ("max" in low or "max" in n):
return "hr_max"