feat: Enhance activity session metrics handling and CSV import logic
Deploy Development / deploy (push) Successful in 51s
Build Test / pytest-backend (push) Successful in 9s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 17s

- Updated the `ACTIVITY_SESSION_METRICS_EAV_AGENT_GUIDE` with new details on CSV import processes and EAV handling, improving documentation clarity.
- Refactored the `_import_activity` function to utilize `apply_activity_mapped_column_aliases`, ensuring proper mapping of training parameters and reducing redundancy.
- Introduced validation for numeric bounds in the `activity_csv_registry_updates_from_mapped` function, enhancing data integrity during CSV imports.
- Added new utility functions to manage column aliasing and streamline the upsert process for session metrics, preventing duplicate entries.
- Implemented unit tests to validate the new aliasing logic and ensure correct behavior during session metrics updates.
This commit is contained in:
Lars committed 2026-04-16 07:25:39 +02:00
1 parent ca8cee990b
commit cd29c7d433
7 files changed
+178 -59

No files matched your search

@@ -83,11 +83,20 @@ def activity_csv_registry_updates_from_mapped(mapped: Mapping[str, Any]) -> Dict
except (TypeError, ValueError):
return None
def _hr(v: Any) -> float | None:
x = _sf(v)
if x is None or x < 20 or x > 280:
return None
return x
def _within_num_bounds(v: float | int, spec: dict, *, as_float: bool) -> bool:
mn = spec.get("min")
mx = spec.get("max")
if mn is not None:
if as_float and v < float(mn):
return False
if not as_float and v < int(mn):
return False
if mx is not None:
if as_float and v > float(mx):
return False
if not as_float and v > int(mx):
return False
return True
for key, spec in fields.items():
if key in _ACTIVITY_CSV_REGISTRY_EXCLUDE:
@@ -101,11 +110,15 @@ def activity_csv_registry_updates_from_mapped(mapped: Mapping[str, Any]) -> Dict
continue
typ = spec.get("type", "string")
if typ == "float":
v = _hr(raw) if key in ("hr_avg", "hr_max") else _sf(raw)
v = _sf(raw)
if v is not None and not _within_num_bounds(v, spec, as_float=True):
v = None
if v is not None:
out[key] = v
elif typ == "int":
v = _si(raw)
if v is not None and not _within_num_bounds(v, spec, as_float=False):
v = None
if v is not None:
out[key] = v
elif typ == "datetime":