feat: Goal System v2.0 - Focus Areas with weighted priorities
BREAKING: Replaces single 'primary goal' with weighted multi-goal system Migration 027: - New table: focus_areas (6 dimensions with percentages) - Constraint: Sum must equal 100% - Auto-migration: goal_mode → focus_areas for existing users - Unique constraint: One active focus_areas per profile Backend: - get_focus_weights() V2: Reads from focus_areas table - Fallback: Uses goal_mode if focus_areas not set - New endpoints: GET/PUT /api/goals/focus-areas - Validation: Sum=100, range 0-100 API: - getFocusAreas() - Get current weights - updateFocusAreas(data) - Update weights (upsert) Focus dimensions: 1. weight_loss_pct (Fettabbau) 2. muscle_gain_pct (Muskelaufbau) 3. strength_pct (Kraftsteigerung) 4. endurance_pct (Ausdauer) 5. flexibility_pct (Beweglichkeit) 6. health_pct (Allgemeine Gesundheit) Benefits: - Multiple goals with custom priorities - More flexible than single primary goal - KI can use weighted scores - Ready for Phase 0b placeholder integration UI: Coming in next commit (slider interface)
This commit is contained in:
1 parent
2303c04123
commit
4a11d20c4d
4 files changed
+385
-36
No files matched your search
+65
-35
@@ -24,9 +24,8 @@ def get_focus_weights(conn, profile_id: str) -> Dict[str, float]:
|
||||
"""
|
||||
Get focus area weights for a profile.
|
||||
|
||||
This is an abstraction layer that will evolve:
|
||||
- V1 (now): Maps goal_mode → predefined weights
|
||||
- V2 (later): Reads from focus_areas table → custom user weights
|
||||
V2 (Goal System v2.0): Reads from focus_areas table with custom user weights.
|
||||
Falls back to goal_mode mapping if focus_areas not set.
|
||||
|
||||
Args:
|
||||
conn: Database connection
|
||||
@@ -55,7 +54,29 @@ def get_focus_weights(conn, profile_id: str) -> Dict[str, float]:
|
||||
"""
|
||||
cur = get_cursor(conn)
|
||||
|
||||
# Fetch current goal_mode
|
||||
# V2: Try to fetch from focus_areas table
|
||||
cur.execute("""
|
||||
SELECT weight_loss_pct, muscle_gain_pct, strength_pct,
|
||||
endurance_pct, flexibility_pct, health_pct
|
||||
FROM focus_areas
|
||||
WHERE profile_id = %s AND active = true
|
||||
LIMIT 1
|
||||
""", (profile_id,))
|
||||
|
||||
row = cur.fetchone()
|
||||
|
||||
if row:
|
||||
# Convert percentages to weights (0-1 range)
|
||||
return {
|
||||
'weight_loss': row['weight_loss_pct'] / 100.0,
|
||||
'muscle_gain': row['muscle_gain_pct'] / 100.0,
|
||||
'strength': row['strength_pct'] / 100.0,
|
||||
'endurance': row['endurance_pct'] / 100.0,
|
||||
'flexibility': row['flexibility_pct'] / 100.0,
|
||||
'health': row['health_pct'] / 100.0
|
||||
}
|
||||
|
||||
# V1 Fallback: Use goal_mode if focus_areas not set
|
||||
cur.execute(
|
||||
"SELECT goal_mode FROM profiles WHERE id = %s",
|
||||
(profile_id,)
|
||||
@@ -63,59 +84,68 @@ def get_focus_weights(conn, profile_id: str) -> Dict[str, float]:
|
||||
row = cur.fetchone()
|
||||
|
||||
if not row:
|
||||
# Fallback: balanced health focus
|
||||
# Ultimate fallback: balanced health focus
|
||||
return {
|
||||
'weight_loss': 0.0,
|
||||
'muscle_gain': 0.0,
|
||||
'strength': 0.0,
|
||||
'endurance': 0.0,
|
||||
'flexibility': 0.0,
|
||||
'health': 1.0
|
||||
'strength': 0.10,
|
||||
'endurance': 0.20,
|
||||
'flexibility': 0.15,
|
||||
'health': 0.55
|
||||
}
|
||||
|
||||
goal_mode = row['goal_mode'] or 'health'
|
||||
goal_mode = row['goal_mode']
|
||||
|
||||
# V1: Predefined weight mappings per goal_mode
|
||||
# These represent "typical" focus distributions for each mode
|
||||
if not goal_mode:
|
||||
return {
|
||||
'weight_loss': 0.0,
|
||||
'muscle_gain': 0.0,
|
||||
'strength': 0.10,
|
||||
'endurance': 0.20,
|
||||
'flexibility': 0.15,
|
||||
'health': 0.55
|
||||
}
|
||||
|
||||
# V1: Predefined weight mappings per goal_mode (fallback)
|
||||
WEIGHT_MAPPINGS = {
|
||||
'weight_loss': {
|
||||
'weight_loss': 0.60, # Primary: fat loss
|
||||
'endurance': 0.20, # Support: cardio for calorie burn
|
||||
'muscle_gain': 0.0, # Not compatible
|
||||
'strength': 0.10, # Maintain muscle during deficit
|
||||
'flexibility': 0.05, # Minor: mobility work
|
||||
'health': 0.05 # Minor: general wellness
|
||||
'weight_loss': 0.60,
|
||||
'endurance': 0.20,
|
||||
'muscle_gain': 0.0,
|
||||
'strength': 0.10,
|
||||
'flexibility': 0.05,
|
||||
'health': 0.05
|
||||
},
|
||||
'strength': {
|
||||
'strength': 0.50, # Primary: strength gains
|
||||
'muscle_gain': 0.40, # Support: hypertrophy
|
||||
'endurance': 0.10, # Minor: work capacity
|
||||
'weight_loss': 0.0, # Not compatible with strength focus
|
||||
'strength': 0.50,
|
||||
'muscle_gain': 0.40,
|
||||
'endurance': 0.10,
|
||||
'weight_loss': 0.0,
|
||||
'flexibility': 0.0,
|
||||
'health': 0.0
|
||||
},
|
||||
'endurance': {
|
||||
'endurance': 0.70, # Primary: aerobic capacity
|
||||
'health': 0.20, # Support: cardiovascular health
|
||||
'flexibility': 0.10, # Support: mobility for running
|
||||
'endurance': 0.70,
|
||||
'health': 0.20,
|
||||
'flexibility': 0.10,
|
||||
'weight_loss': 0.0,
|
||||
'muscle_gain': 0.0,
|
||||
'strength': 0.0
|
||||
},
|
||||
'recomposition': {
|
||||
'weight_loss': 0.30, # Equal: lose fat
|
||||
'muscle_gain': 0.30, # Equal: gain muscle
|
||||
'strength': 0.25, # Support: progressive overload
|
||||
'endurance': 0.10, # Minor: conditioning
|
||||
'flexibility': 0.05, # Minor: mobility
|
||||
'weight_loss': 0.30,
|
||||
'muscle_gain': 0.30,
|
||||
'strength': 0.25,
|
||||
'endurance': 0.10,
|
||||
'flexibility': 0.05,
|
||||
'health': 0.0
|
||||
},
|
||||
'health': {
|
||||
'health': 0.50, # Primary: general wellness
|
||||
'endurance': 0.20, # Support: cardio health
|
||||
'flexibility': 0.15, # Support: mobility
|
||||
'strength': 0.10, # Support: functional strength
|
||||
'weight_loss': 0.05, # Minor: maintain healthy weight
|
||||
'health': 0.50,
|
||||
'endurance': 0.20,
|
||||
'flexibility': 0.15,
|
||||
'strength': 0.10,
|
||||
'weight_loss': 0.05,
|
||||
'muscle_gain': 0.0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user