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:
parent
b2175b9018
commit
8fc7d9c1c4
|
|
@ -231,7 +231,7 @@ def get_body_history_viz_bundle(profile_id: str, days: int) -> Dict[str, Any]:
|
||||||
FROM circumference_log
|
FROM circumference_log
|
||||||
WHERE profile_id = %s AND date >= %s
|
WHERE profile_id = %s AND date >= %s
|
||||||
ORDER BY date DESC
|
ORDER BY date DESC
|
||||||
LIMIT 1
|
LIMIT 2
|
||||||
""",
|
""",
|
||||||
(profile_id, cutoff),
|
(profile_id, cutoff),
|
||||||
)
|
)
|
||||||
|
|
@ -242,11 +242,13 @@ def get_body_history_viz_bundle(profile_id: str, days: int) -> Dict[str, Any]:
|
||||||
FROM circumference_log
|
FROM circumference_log
|
||||||
WHERE profile_id = %s
|
WHERE profile_id = %s
|
||||||
ORDER BY date DESC
|
ORDER BY date DESC
|
||||||
LIMIT 1
|
LIMIT 2
|
||||||
""",
|
""",
|
||||||
(profile_id,),
|
(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 weight in window
|
||||||
latest_w = w_points[-1] if w_points else None
|
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"))
|
measurement["c_belly"] = safe_float(latest_circ_row.get("c_belly"))
|
||||||
if latest_w:
|
if latest_w:
|
||||||
measurement["weight"] = safe_float(latest_w.get("weight"))
|
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:
|
if prev_cal:
|
||||||
prev_for_interp = {
|
prev_for_interp["date"] = prev_cal.get("date")
|
||||||
"date": prev_cal.get("date"),
|
prev_for_interp["body_fat_pct"] = safe_float(prev_cal.get("body_fat_pct"))
|
||||||
"body_fat_pct": safe_float(prev_cal.get("body_fat_pct")),
|
prev_for_interp["lean_mass"] = safe_float(prev_cal.get("lean_mass"))
|
||||||
"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)
|
tiles = get_body_interpretation_tiles(measurement, profile_ui, prev_for_interp)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -187,10 +187,10 @@ function buildBodyKpiTiles({
|
||||||
const ok = summary.whr < (sex === 'm' ? 0.9 : 0.85)
|
const ok = summary.whr < (sex === 'm' ? 0.9 : 0.85)
|
||||||
tiles.push({
|
tiles.push({
|
||||||
key: 'whr',
|
key: 'whr',
|
||||||
category: 'WHR',
|
category: 'Fettverteilung',
|
||||||
icon: '📐',
|
icon: '📐',
|
||||||
value: String(summary.whr),
|
value: String(summary.whr),
|
||||||
sublabel: 'Taille ÷ Hüfte',
|
sublabel: 'WHR · Taille ÷ Hüfte',
|
||||||
verdict: whrRule ? verdictShort(whrRule.status) : (ok ? 'Gut' : 'Hinweis'),
|
verdict: whrRule ? verdictShort(whrRule.status) : (ok ? 'Gut' : 'Hinweis'),
|
||||||
status: whrRule?.status || (ok ? 'good' : 'warn'),
|
status: whrRule?.status || (ok ? 'good' : 'warn'),
|
||||||
hoverTop: whrRule?.title || 'Waist-Hip-Ratio',
|
hoverTop: whrRule?.title || 'Waist-Hip-Ratio',
|
||||||
|
|
@ -203,10 +203,10 @@ function buildBodyKpiTiles({
|
||||||
const ok = summary.whtr < 0.5
|
const ok = summary.whtr < 0.5
|
||||||
tiles.push({
|
tiles.push({
|
||||||
key: 'whtr',
|
key: 'whtr',
|
||||||
category: 'WHtR',
|
category: 'Taille/Größe',
|
||||||
icon: '📏',
|
icon: '📏',
|
||||||
value: String(summary.whtr),
|
value: String(summary.whtr),
|
||||||
sublabel: 'Taille ÷ Größe',
|
sublabel: 'WHtR · Taille ÷ Größe',
|
||||||
verdict: whtrRule ? verdictShort(whtrRule.status) : (ok ? 'Gut' : 'Hinweis'),
|
verdict: whtrRule ? verdictShort(whtrRule.status) : (ok ? 'Gut' : 'Hinweis'),
|
||||||
status: whtrRule?.status || (ok ? 'good' : 'warn'),
|
status: whtrRule?.status || (ok ? 'good' : 'warn'),
|
||||||
hoverTop: whtrRule?.title || 'Waist-to-Height-Ratio',
|
hoverTop: whtrRule?.title || 'Waist-to-Height-Ratio',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user