refactor: enhance body history visualization logic and frontend labels
- Updated the `get_body_history_viz_bundle` function to retrieve the two most recent circumference measurements for improved data accuracy. - Refactored the handling of previous measurement data to ensure comprehensive interpolation for body metrics. - Modified frontend labels in the `buildBodyKpiTiles` function to provide clearer descriptions in German, enhancing user understanding of body metrics.
This commit is contained in:
1 parent
b2175b9018
commit
8fc7d9c1c4
2 files changed
+41
-13
No files matched your search
@@ -231,7 +231,7 @@ def get_body_history_viz_bundle(profile_id: str, days: int) -> Dict[str, Any]:
|
||||
FROM circumference_log
|
||||
WHERE profile_id = %s AND date >= %s
|
||||
ORDER BY date DESC
|
||||
LIMIT 1
|
||||
LIMIT 2
|
||||
""",
|
||||
(profile_id, cutoff),
|
||||
)
|
||||
@@ -242,11 +242,13 @@ def get_body_history_viz_bundle(profile_id: str, days: int) -> Dict[str, Any]:
|
||||
FROM circumference_log
|
||||
WHERE profile_id = %s
|
||||
ORDER BY date DESC
|
||||
LIMIT 1
|
||||
LIMIT 2
|
||||
""",
|
||||
(profile_id,),
|
||||
)
|
||||
latest_circ_row = r2d(cur.fetchone())
|
||||
circ_latest_desc = [r2d(r) for r in cur.fetchall()]
|
||||
latest_circ_row = circ_latest_desc[0] if circ_latest_desc else None
|
||||
prev_circ_row = circ_latest_desc[1] if len(circ_latest_desc) > 1 else None
|
||||
|
||||
# Latest weight in window
|
||||
latest_w = w_points[-1] if w_points else None
|
||||
@@ -334,14 +336,40 @@ def get_body_history_viz_bundle(profile_id: str, days: int) -> Dict[str, Any]:
|
||||
measurement["c_belly"] = safe_float(latest_circ_row.get("c_belly"))
|
||||
if latest_w:
|
||||
measurement["weight"] = safe_float(latest_w.get("weight"))
|
||||
# Referenzdatum für „aktuell“: neueste verfügbare Quelle (Caliper > Umfang > Gewicht)
|
||||
if not measurement.get("date"):
|
||||
if latest_circ_row and latest_circ_row.get("date"):
|
||||
measurement["date"] = latest_circ_row.get("date")
|
||||
elif latest_w and latest_w.get("date"):
|
||||
measurement["date"] = latest_w.get("date")
|
||||
|
||||
prev_for_interp = None
|
||||
# Vorperiode: vorherige Caliper-Zeile + vorherige Umfangsmessung + vorheriges Gewicht (w_points[-2])
|
||||
prev_for_interp: Optional[Dict[str, Any]] = {}
|
||||
if prev_cal:
|
||||
prev_for_interp = {
|
||||
"date": prev_cal.get("date"),
|
||||
"body_fat_pct": safe_float(prev_cal.get("body_fat_pct")),
|
||||
"lean_mass": safe_float(prev_cal.get("lean_mass")),
|
||||
}
|
||||
prev_for_interp["date"] = prev_cal.get("date")
|
||||
prev_for_interp["body_fat_pct"] = safe_float(prev_cal.get("body_fat_pct"))
|
||||
prev_for_interp["lean_mass"] = safe_float(prev_cal.get("lean_mass"))
|
||||
if prev_circ_row:
|
||||
prev_for_interp["c_waist"] = safe_float(prev_circ_row.get("c_waist"))
|
||||
prev_for_interp["c_hip"] = safe_float(prev_circ_row.get("c_hip"))
|
||||
prev_for_interp["c_belly"] = safe_float(prev_circ_row.get("c_belly"))
|
||||
if not prev_for_interp.get("date") and prev_circ_row.get("date"):
|
||||
prev_for_interp["date"] = prev_circ_row.get("date")
|
||||
if len(w_points) >= 2:
|
||||
prev_for_interp["weight"] = safe_float(w_points[-2].get("weight"))
|
||||
if not prev_for_interp.get("date") and w_points[-2].get("date"):
|
||||
prev_for_interp["date"] = w_points[-2].get("date")
|
||||
|
||||
if not prev_for_interp:
|
||||
prev_for_interp = None
|
||||
else:
|
||||
# Mindestens ein vergleichbares Feld zur aktuellen Messung
|
||||
has_cmp = any(
|
||||
prev_for_interp.get(k) is not None
|
||||
for k in ("body_fat_pct", "lean_mass", "weight", "c_waist", "c_belly")
|
||||
)
|
||||
if not has_cmp:
|
||||
prev_for_interp = None
|
||||
|
||||
tiles = get_body_interpretation_tiles(measurement, profile_ui, prev_for_interp)
|
||||
|
||||
|
||||
Reference in new issue
Block a user