feat(csv-import): Add CSV import diagnosis endpoint and related functionality
- Implemented a new endpoint for diagnosing CSV imports without writing to the database, allowing users to validate mappings and type conversions. - Introduced the `diagnose_vitals_row` function to analyze vital metrics and provide detailed feedback on data validity. - Enhanced the CSV import logic to include alias handling for vital fields, improving compatibility with different CSV formats. - Updated the frontend to support the new diagnosis feature, including UI elements for displaying diagnosis results and error details. - Added tests to ensure the correctness of the new diagnosis functionality and its integration with existing import processes.
This commit is contained in:
1 parent
1855f6e57a
commit
c5b0540b11
6 files changed
+394
-18
No files matched your search
@@ -524,6 +524,36 @@ def _v_safe_float(value: Any) -> float | None:
|
||||
return None
|
||||
|
||||
|
||||
def diagnose_vitals_row(mapped_typed: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Erklärt Vital-Baseline-Zeile nach Typkonvertierung (ohne DB)."""
|
||||
d = coerce_date(mapped_typed.get("date"))
|
||||
rhr = _v_safe_int(mapped_typed.get("resting_hr"))
|
||||
hrv = _v_safe_int(mapped_typed.get("hrv"))
|
||||
vo2 = _v_safe_float(mapped_typed.get("vo2_max"))
|
||||
spo2 = _v_safe_int(mapped_typed.get("spo2"))
|
||||
resp = _v_safe_float(mapped_typed.get("respiratory_rate"))
|
||||
has_metric = any(x is not None for x in (rhr, hrv, vo2, spo2, resp))
|
||||
date_raw = mapped_typed.get("date")
|
||||
return {
|
||||
"date_coerced_iso": d.isoformat() if d else None,
|
||||
"date_after_convert_repr": repr(date_raw),
|
||||
"date_after_convert_type": type(date_raw).__name__,
|
||||
"metrics": {
|
||||
"resting_hr": rhr,
|
||||
"hrv": hrv,
|
||||
"vo2_max": vo2,
|
||||
"spo2": spo2,
|
||||
"respiratory_rate": resp,
|
||||
},
|
||||
"would_pass_prefilter": d is not None and has_metric,
|
||||
"prefilter_fail_reason": (
|
||||
"datum_fehlt"
|
||||
if d is None
|
||||
else ("keine_baseline_metrik" if not has_metric else None)
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def _import_vitals_baseline(
|
||||
cur,
|
||||
profile_id: str,
|
||||
|
||||
Reference in new issue
Block a user