fix: Phase 0b - score functions use English focus area keys
Deploy Development / deploy (push) Successful in 50s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 14s

Root cause: All 3 score functions returned None because they queried
German focus area keys that don't exist in database (migration 031
uses English keys).

Changes:
- body_progress_score: körpergewicht/körperfett/muskelmasse
  → weight_loss/muscle_gain/body_recomposition
- nutrition_score: ernährung_basis/proteinzufuhr/kalorienbilanz
  → protein_intake/calorie_balance/macro_consistency/meal_timing/hydration
- activity_score: kraftaufbau/cardio/bewegungsumfang/trainingsqualität
  → strength/aerobic_endurance/flexibility/rhythm/coordination (grouped)

Result: Scores now calculate correctly with existing focus area weights.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 4.6 committed 2026-03-28 10:59:37 +01:00
1 parent 63bd103b2c
commit cc76ae677b
3 files changed
+85 -73

No files matched your search

+24 -25
View File
@@ -341,45 +341,44 @@ def calculate_nutrition_score(profile_id: str, focus_weights: Optional[Dict] = N
from calculations.scores import get_user_focus_weights
focus_weights = get_user_focus_weights(profile_id)
# Nutrition-related focus areas
nutrition_focus = {
'ernährung_basis': focus_weights.get('ernährung_basis', 0),
'ernährung_makros': focus_weights.get('ernährung_makros', 0),
'proteinzufuhr': focus_weights.get('proteinzufuhr', 0),
'kalorienbilanz': focus_weights.get('kalorienbilanz', 0),
}
# Nutrition-related focus areas (English keys from DB)
protein_intake = focus_weights.get('protein_intake', 0)
calorie_balance = focus_weights.get('calorie_balance', 0)
macro_consistency = focus_weights.get('macro_consistency', 0)
meal_timing = focus_weights.get('meal_timing', 0)
hydration = focus_weights.get('hydration', 0)
total_nutrition_weight = sum(nutrition_focus.values())
total_nutrition_weight = protein_intake + calorie_balance + macro_consistency + meal_timing + hydration
if total_nutrition_weight == 0:
return None # No nutrition goals
components = []
# 1. Calorie target adherence (if kalorienbilanz goal active)
if nutrition_focus['kalorienbilanz'] > 0:
# 1. Calorie target adherence (if calorie_balance goal active)
if calorie_balance > 0:
calorie_score = _score_calorie_adherence(profile_id)
if calorie_score is not None:
components.append(('calories', calorie_score, nutrition_focus['kalorienbilanz']))
components.append(('calories', calorie_score, calorie_balance))
# 2. Protein target adherence (always important if any nutrition goal)
protein_score = calculate_protein_adequacy_28d(profile_id)
if protein_score is not None:
# Higher weight if protein-specific goal
protein_weight = nutrition_focus['proteinzufuhr'] or (total_nutrition_weight * 0.3)
components.append(('protein', protein_score, protein_weight))
# 2. Protein target adherence (if protein_intake goal active)
if protein_intake > 0:
protein_score = calculate_protein_adequacy_28d(profile_id)
if protein_score is not None:
components.append(('protein', protein_score, protein_intake))
# 3. Intake consistency (always relevant)
consistency_score = calculate_macro_consistency_score(profile_id)
if consistency_score is not None:
consistency_weight = total_nutrition_weight * 0.2
components.append(('consistency', consistency_score, consistency_weight))
# 3. Intake consistency (if macro_consistency goal active)
if macro_consistency > 0:
consistency_score = calculate_macro_consistency_score(profile_id)
if consistency_score is not None:
components.append(('consistency', consistency_score, macro_consistency))
# 4. Macro balance (if makros goal active)
if nutrition_focus['ernährung_makros'] > 0:
# 4. Macro balance (always relevant if any nutrition goal)
if total_nutrition_weight > 0:
macro_score = _score_macro_balance(profile_id)
if macro_score is not None:
components.append(('macros', macro_score, nutrition_focus['ernährung_makros']))
# Use 20% of total weight for macro balance
components.append(('macros', macro_score, total_nutrition_weight * 0.2))
if not components:
return None