From 43e6c3e7f4091c351d237d00a52bec809a64d10e Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 28 Mar 2026 10:13:10 +0100 Subject: [PATCH] fix: Phase 0b - map German to English category names --- backend/calculations/scores.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/calculations/scores.py b/backend/calculations/scores.py index b4eb571..6580757 100644 --- a/backend/calculations/scores.py +++ b/backend/calculations/scores.py @@ -104,11 +104,31 @@ def map_focus_to_score_components() -> Dict[str, str]: } +def map_category_de_to_en(category_de: str) -> str: + """ + Map German category names to English database names + """ + mapping = { + 'körper': 'body_composition', + 'ernährung': 'nutrition', # Note: no nutrition category in DB, returns empty + 'aktivität': 'training', + 'recovery': 'recovery', + 'vitalwerte': 'health', + 'mental': 'mental', + 'lebensstil': 'health', # Maps to general health + } + return mapping.get(category_de, category_de) + + def calculate_category_weight(profile_id: str, category: str) -> float: """ Calculate total weight for a category + Accepts German or English category names Returns sum of all focus area weights in this category """ + # Map German to English if needed + category_en = map_category_de_to_en(category) + focus_weights = get_user_focus_weights(profile_id) with get_db() as conn: @@ -117,7 +137,7 @@ def calculate_category_weight(profile_id: str, category: str) -> float: SELECT key FROM focus_area_definitions WHERE category = %s - """, (category,)) + """, (category_en,)) focus_areas = [row['key'] for row in cur.fetchall()]