fix: Phase 1 - Goal System Quick Fixes + Abstraction Layer
Behebt 4 kritische Bugs in Phase 0a und schafft Basis für Phase 0b ohne spätere Doppelarbeit. Backend: - NEW: goal_utils.py mit get_focus_weights() Abstraction Layer → V1: Mappt goal_mode zu Gewichten → V2 (später): Liest aus focus_areas Tabelle → Phase 0b Platzhalter (120+) müssen NICHT umgeschrieben werden - FIX: Primary goal toggle in goals.py (is_primary im GoalUpdate Model) → Beim Update auf primary werden andere Goals korrekt auf false gesetzt - FIX: lean_mass current_value Berechnung implementiert → weight - (weight * body_fat_pct / 100) - FIX: VO2Max Spaltenname vo2_max (statt vo2max) → Internal Server Error behoben CLAUDE.md: - Version Update: Phase 1 Fixes (27.03.2026) Keine Doppelarbeit: - Alle zukünftigen Phase 0b Platzhalter nutzen get_focus_weights() - v2.0 Redesign = nur eine Funktion ändern, nicht 120+ Platzhalter Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
e3f1e399c2
commit
87464ff138
3 files changed
+238
-5
No files matched your search
@@ -43,6 +43,7 @@ class GoalUpdate(BaseModel):
|
||||
target_value: Optional[float] = None
|
||||
target_date: Optional[date] = None
|
||||
status: Optional[str] = None # active, reached, abandoned, expired
|
||||
is_primary: Optional[bool] = None
|
||||
name: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
|
||||
@@ -204,6 +205,13 @@ def update_goal(goal_id: str, data: GoalUpdate, session: dict = Depends(require_
|
||||
if not cur.fetchone():
|
||||
raise HTTPException(status_code=404, detail="Ziel nicht gefunden")
|
||||
|
||||
# If setting this goal as primary, unset all other primary goals
|
||||
if data.is_primary is True:
|
||||
cur.execute(
|
||||
"UPDATE goals SET is_primary = false WHERE profile_id = %s AND id != %s",
|
||||
(pid, goal_id)
|
||||
)
|
||||
|
||||
# Build update query dynamically
|
||||
updates = []
|
||||
params = []
|
||||
@@ -222,6 +230,10 @@ def update_goal(goal_id: str, data: GoalUpdate, session: dict = Depends(require_
|
||||
if data.status == 'reached':
|
||||
updates.append("reached_date = CURRENT_DATE")
|
||||
|
||||
if data.is_primary is not None:
|
||||
updates.append("is_primary = %s")
|
||||
params.append(data.is_primary)
|
||||
|
||||
if data.name is not None:
|
||||
updates.append("name = %s")
|
||||
params.append(data.name)
|
||||
@@ -414,14 +426,38 @@ def _get_current_value_for_goal_type(conn, profile_id: str, goal_type: str) -> O
|
||||
row = cur.fetchone()
|
||||
return float(row['body_fat_pct']) if row else None
|
||||
|
||||
elif goal_type == 'lean_mass':
|
||||
# Calculate lean mass: weight - (weight * body_fat_pct / 100)
|
||||
# Need both latest weight and latest body fat percentage
|
||||
cur.execute("""
|
||||
SELECT weight FROM weight_log
|
||||
WHERE profile_id = %s
|
||||
ORDER BY date DESC LIMIT 1
|
||||
""", (profile_id,))
|
||||
weight_row = cur.fetchone()
|
||||
|
||||
cur.execute("""
|
||||
SELECT body_fat_pct FROM caliper_log
|
||||
WHERE profile_id = %s
|
||||
ORDER BY date DESC LIMIT 1
|
||||
""", (profile_id,))
|
||||
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)
|
||||
return None
|
||||
|
||||
elif goal_type == 'vo2max':
|
||||
cur.execute("""
|
||||
SELECT vo2max FROM vitals_baseline
|
||||
WHERE profile_id = %s AND vo2max IS NOT NULL
|
||||
SELECT vo2_max FROM vitals_baseline
|
||||
WHERE profile_id = %s AND vo2_max IS NOT NULL
|
||||
ORDER BY date DESC LIMIT 1
|
||||
""", (profile_id,))
|
||||
row = cur.fetchone()
|
||||
return float(row['vo2max']) if row else None
|
||||
return float(row['vo2_max']) if row else None
|
||||
|
||||
elif goal_type == 'rhr':
|
||||
cur.execute("""
|
||||
|
||||
Reference in new issue
Block a user