From 27a8af7008dc505ab81064ac5fdcd8c091c25e94 Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 27 Mar 2026 06:24:40 +0100 Subject: [PATCH] debug: Add logging and warnings for Goal System issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on test feedback - 3 issues addressed: 1. Primary Toggle (Frontend Debug): - Add console.log in handleSaveGoal - Shows what data is sent to backend - Helps debug if checkbox state is correct 2. Lean Mass Display (Backend Debug): - Add error handling in lean_mass calculation - Log why calculation fails (missing weight/bf data) - Try-catch for value conversion errors 3. BP/Strength/Flexibility Warning (UI): - Yellow warning box for incomplete goal types - BP: "benötigt 2 Werte (geplant für v2.0)" - Strength/Flexibility: "Keine Datenquelle" - Transparent about limitations Next: User re-tests with debug output to identify root cause. Co-Authored-By: Claude Opus 4.6 --- backend/routers/goals.py | 15 +++++++++++---- frontend/src/pages/GoalsPage.jsx | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/backend/routers/goals.py b/backend/routers/goals.py index 9f172b9..a8239ce 100644 --- a/backend/routers/goals.py +++ b/backend/routers/goals.py @@ -444,10 +444,17 @@ def _get_current_value_for_goal_type(conn, profile_id: str, goal_type: str) -> O bf_row = cur.fetchone() if weight_row and bf_row: - weight = float(weight_row['weight']) - bf_pct = float(bf_row['body_fat_pct']) - lean_mass = weight - (weight * bf_pct / 100.0) - return round(lean_mass, 2) + try: + weight = float(weight_row['weight']) + bf_pct = float(bf_row['body_fat_pct']) + lean_mass = weight - (weight * bf_pct / 100.0) + return round(lean_mass, 2) + except (ValueError, TypeError) as e: + print(f"[DEBUG] lean_mass calculation error: {e}, weight={weight_row}, bf={bf_row}") + return None + + # Debug: Log why calculation failed + print(f"[DEBUG] lean_mass calc failed - weight_row: {weight_row is not None}, bf_row: {bf_row is not None}") return None elif goal_type == 'vo2max': diff --git a/frontend/src/pages/GoalsPage.jsx b/frontend/src/pages/GoalsPage.jsx index 84f091f..817e438 100644 --- a/frontend/src/pages/GoalsPage.jsx +++ b/frontend/src/pages/GoalsPage.jsx @@ -167,6 +167,8 @@ export default function GoalsPage() { description: formData.description || null } + console.log('[DEBUG] Saving goal:', { editingGoal, data }) + if (editingGoal) { await api.updateGoal(editingGoal, data) showToast('✓ Ziel aktualisiert') @@ -493,6 +495,24 @@ export default function GoalsPage() { ))} + + {/* Warning for incomplete goal types */} + {['bp', 'strength', 'flexibility'].includes(formData.goal_type) && ( +
+ ⚠️ Dieser Zieltyp ist aktuell eingeschränkt: + {formData.goal_type === 'bp' && ' Blutdruck benötigt 2 Werte (geplant für v2.0)'} + {formData.goal_type === 'strength' && ' Keine Datenquelle vorhanden (geplant für v2.0)'} + {formData.goal_type === 'flexibility' && ' Keine Datenquelle vorhanden (geplant für v2.0)'} +
+ )} {/* Name */}