From 202c36fad719b16ebc4a5031cf77fbb072a76ed0 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 28 Mar 2026 11:04:28 +0100 Subject: [PATCH] fix: Phase 0b - replace non-existent get_goals_by_type import ImportError: cannot import name 'get_goals_by_type' from 'goal_utils' Changes: - body_metrics.py: Use get_active_goals() + filter by type_key - nutrition_metrics.py: Remove unused import (dead code) Result: Score functions no longer crash on import error. Co-Authored-By: Claude Opus 4.6 --- backend/calculations/body_metrics.py | 9 +++++---- backend/calculations/nutrition_metrics.py | 3 --- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/backend/calculations/body_metrics.py b/backend/calculations/body_metrics.py index 837ab62..830dd1f 100644 --- a/backend/calculations/body_metrics.py +++ b/backend/calculations/body_metrics.py @@ -383,14 +383,15 @@ def calculate_body_progress_score(profile_id: str, focus_weights: Optional[Dict] def _score_weight_trend(profile_id: str) -> Optional[int]: """Score weight trend alignment with goals (0-100)""" - from goal_utils import get_goals_by_type + from goal_utils import get_active_goals - goals = get_goals_by_type(profile_id, 'weight') - if not goals: + goals = get_active_goals(profile_id) + weight_goals = [g for g in goals if g.get('type_key') == 'weight'] + if not weight_goals: return None # Use primary or first active goal - goal = next((g for g in goals if g.get('is_primary')), goals[0]) + goal = next((g for g in weight_goals if g.get('is_primary')), weight_goals[0]) current = goal.get('current_value') target = goal.get('target_value') diff --git a/backend/calculations/nutrition_metrics.py b/backend/calculations/nutrition_metrics.py index 9406e0a..84735a8 100644 --- a/backend/calculations/nutrition_metrics.py +++ b/backend/calculations/nutrition_metrics.py @@ -392,9 +392,6 @@ def calculate_nutrition_score(profile_id: str, focus_weights: Optional[Dict] = N def _score_calorie_adherence(profile_id: str) -> Optional[int]: """Score calorie target adherence (0-100)""" - # Get goal (if exists) - from goal_utils import get_goals_by_type - # Check for energy balance goal # For now, use energy balance calculation balance = calculate_energy_balance_7d(profile_id)