fix: Phase 0b - fix remaining calculation errors
Fixes applied: 1. WHERE clause column names (total_sleep_min → duration_minutes, resting_heart_rate → resting_hr) 2. COUNT() column names (avg_heart_rate → hr_avg, quality_label → rpe) 3. Type errors (Decimal * float) - convert to float before multiplication 4. rest_days table (type column removed in migration 010, now uses rest_config JSONB) 5. c_thigh_l → c_thigh (no separate left/right columns) 6. focus_area_definitions queries (focus_area_id → key, label_de → name_de) Missing functions implemented: - goal_utils.get_active_goals() - queries goals table for active goals - goal_utils.get_goal_by_id() - gets single goal - calculations.scores.calculate_category_progress() - maps categories to score functions Changes: - activity_metrics.py: Fixed Decimal/float type errors, rest_config JSONB, data quality query - recovery_metrics.py: Fixed all WHERE clause column names - body_metrics.py: Fixed c_thigh column reference - scores.py: Fixed focus_area queries, added calculate_category_progress() - goal_utils.py: Added get_active_goals(), get_goal_by_id() All calculation functions should now work with correct schema. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
4817fd2b29
commit
dd3a4111fc
6 files changed
+112
-36
No files matched your search
+36
-2
@@ -13,11 +13,11 @@ Version History:
|
||||
Part of Phase 1 + Phase 1.5: Flexible Goal System
|
||||
"""
|
||||
|
||||
from typing import Dict, Optional, Any
|
||||
from typing import Dict, Optional, Any, List
|
||||
from datetime import date, timedelta
|
||||
from decimal import Decimal
|
||||
import json
|
||||
from db import get_cursor
|
||||
from db import get_cursor, get_db
|
||||
|
||||
|
||||
def get_focus_weights(conn, profile_id: str) -> Dict[str, float]:
|
||||
@@ -516,3 +516,37 @@ def get_focus_weights_v2(conn, profile_id: str) -> Dict[str, float]:
|
||||
'health': row['health_pct'] / 100.0
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def get_active_goals(profile_id: str) -> List[Dict]:
|
||||
"""
|
||||
Get all active goals for a profile.
|
||||
Returns list of goal dicts with id, type, target_value, current_value, etc.
|
||||
"""
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("""
|
||||
SELECT id, goal_type, target_value, target_date,
|
||||
current_value, progress_pct, status, is_primary
|
||||
FROM goals
|
||||
WHERE profile_id = %s
|
||||
AND status IN ('active', 'in_progress')
|
||||
ORDER BY is_primary DESC, created_at DESC
|
||||
""", (profile_id,))
|
||||
|
||||
return [dict(row) for row in cur.fetchall()]
|
||||
|
||||
|
||||
def get_goal_by_id(goal_id: str) -> Optional[Dict]:
|
||||
"""Get a single goal by ID"""
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("""
|
||||
SELECT id, profile_id, goal_type, target_value, target_date,
|
||||
current_value, progress_pct, status, is_primary
|
||||
FROM goals
|
||||
WHERE id = %s
|
||||
""", (goal_id,))
|
||||
|
||||
row = cur.fetchone()
|
||||
return dict(row) if row else None
|
||||
Reference in new issue
Block a user