Bugfixes: Vitals Import (German columns + decimal values) #23
|
|
@ -290,6 +290,27 @@ def get_baseline_stats(
|
||||||
# Import: Apple Health CSV
|
# Import: Apple Health CSV
|
||||||
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
|
||||||
|
def safe_int(value):
|
||||||
|
"""Safely parse string to int, handling decimals."""
|
||||||
|
if not value or value == '':
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
# If it has a decimal point, parse as float first then round to int
|
||||||
|
if '.' in str(value):
|
||||||
|
return int(float(value))
|
||||||
|
return int(value)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def safe_float(value):
|
||||||
|
"""Safely parse string to float."""
|
||||||
|
if not value or value == '':
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return float(value)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return None
|
||||||
|
|
||||||
@router.post("/import/apple-health")
|
@router.post("/import/apple-health")
|
||||||
async def import_apple_health_baseline(
|
async def import_apple_health_baseline(
|
||||||
file: UploadFile = File(...),
|
file: UploadFile = File(...),
|
||||||
|
|
@ -361,11 +382,11 @@ async def import_apple_health_baseline(
|
||||||
RETURNING (xmax = 0) AS inserted
|
RETURNING (xmax = 0) AS inserted
|
||||||
""", (
|
""", (
|
||||||
pid, date,
|
pid, date,
|
||||||
int(rhr) if rhr else None,
|
safe_int(rhr),
|
||||||
int(hrv) if hrv else None,
|
safe_int(hrv),
|
||||||
float(vo2) if vo2 else None,
|
safe_float(vo2),
|
||||||
int(spo2) if spo2 else None,
|
safe_int(spo2),
|
||||||
float(resp_rate) if resp_rate else None
|
safe_float(resp_rate)
|
||||||
))
|
))
|
||||||
|
|
||||||
result = cur.fetchone()
|
result = cur.fetchone()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user