fix: Phase 0c - update all in-function imports to use data_layer
Critical bug fix: In-function imports were still referencing calculations/ module. This caused all calculated placeholders to fail silently. Fixed imports in: - activity_metrics.py: calculate_activity_score (scores import) - recovery_metrics.py: calculate_recent_load_balance_3d (activity_metrics import) - scores.py: 12 function imports (body/nutrition/activity/recovery metrics) - correlations.py: 11 function imports (scores, body, nutrition, activity, recovery metrics) All data_layer modules now reference each other correctly. Placeholders should resolve properly now. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
befa060671
commit
5b7d7ec3bb
|
|
@ -597,7 +597,7 @@ def calculate_activity_score(profile_id: str, focus_weights: Optional[Dict] = No
|
||||||
Weighted by user's activity-related focus areas
|
Weighted by user's activity-related focus areas
|
||||||
"""
|
"""
|
||||||
if focus_weights is None:
|
if focus_weights is None:
|
||||||
from calculations.scores import get_user_focus_weights
|
from data_layer.scores import get_user_focus_weights
|
||||||
focus_weights = get_user_focus_weights(profile_id)
|
focus_weights = get_user_focus_weights(profile_id)
|
||||||
|
|
||||||
# Activity-related focus areas (English keys from DB)
|
# Activity-related focus areas (English keys from DB)
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ def calculate_plateau_detected(profile_id: str) -> Optional[Dict]:
|
||||||
'top_factors': [list of potential causes]
|
'top_factors': [list of potential causes]
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
from calculations.scores import get_user_focus_weights
|
from data_layer.scores import get_user_focus_weights
|
||||||
|
|
||||||
focus_weights = get_user_focus_weights(profile_id)
|
focus_weights = get_user_focus_weights(profile_id)
|
||||||
|
|
||||||
|
|
@ -187,8 +187,8 @@ def calculate_plateau_detected(profile_id: str) -> Optional[Dict]:
|
||||||
|
|
||||||
def _detect_weight_plateau(profile_id: str) -> Dict:
|
def _detect_weight_plateau(profile_id: str) -> Dict:
|
||||||
"""Detect weight loss plateau"""
|
"""Detect weight loss plateau"""
|
||||||
from calculations.body_metrics import calculate_weight_28d_slope
|
from data_layer.body_metrics import calculate_weight_28d_slope
|
||||||
from calculations.nutrition_metrics import calculate_nutrition_score
|
from data_layer.nutrition_metrics import calculate_nutrition_score
|
||||||
|
|
||||||
slope = calculate_weight_28d_slope(profile_id)
|
slope = calculate_weight_28d_slope(profile_id)
|
||||||
nutrition_score = calculate_nutrition_score(profile_id)
|
nutrition_score = calculate_nutrition_score(profile_id)
|
||||||
|
|
@ -207,13 +207,13 @@ def _detect_weight_plateau(profile_id: str) -> Dict:
|
||||||
factors.append('Hohe Adhärenz trotz Stagnation → mögliche Anpassung des Stoffwechsels')
|
factors.append('Hohe Adhärenz trotz Stagnation → mögliche Anpassung des Stoffwechsels')
|
||||||
|
|
||||||
# Check if deficit is too small
|
# Check if deficit is too small
|
||||||
from calculations.nutrition_metrics import calculate_energy_balance_7d
|
from data_layer.nutrition_metrics import calculate_energy_balance_7d
|
||||||
balance = calculate_energy_balance_7d(profile_id)
|
balance = calculate_energy_balance_7d(profile_id)
|
||||||
if balance and balance > -200:
|
if balance and balance > -200:
|
||||||
factors.append('Energiedefizit zu gering (<200 kcal/Tag)')
|
factors.append('Energiedefizit zu gering (<200 kcal/Tag)')
|
||||||
|
|
||||||
# Check water retention (if waist is shrinking but weight stable)
|
# Check water retention (if waist is shrinking but weight stable)
|
||||||
from calculations.body_metrics import calculate_waist_28d_delta
|
from data_layer.body_metrics import calculate_waist_28d_delta
|
||||||
waist_delta = calculate_waist_28d_delta(profile_id)
|
waist_delta = calculate_waist_28d_delta(profile_id)
|
||||||
if waist_delta and waist_delta < -1:
|
if waist_delta and waist_delta < -1:
|
||||||
factors.append('Taillenumfang sinkt → mögliche Wasserretention maskiert Fettabbau')
|
factors.append('Taillenumfang sinkt → mögliche Wasserretention maskiert Fettabbau')
|
||||||
|
|
@ -231,9 +231,9 @@ def _detect_weight_plateau(profile_id: str) -> Dict:
|
||||||
|
|
||||||
def _detect_strength_plateau(profile_id: str) -> Dict:
|
def _detect_strength_plateau(profile_id: str) -> Dict:
|
||||||
"""Detect strength training plateau"""
|
"""Detect strength training plateau"""
|
||||||
from calculations.body_metrics import calculate_lbm_28d_change
|
from data_layer.body_metrics import calculate_lbm_28d_change
|
||||||
from calculations.activity_metrics import calculate_activity_score
|
from data_layer.activity_metrics import calculate_activity_score
|
||||||
from calculations.recovery_metrics import calculate_recovery_score_v2
|
from data_layer.recovery_metrics import calculate_recovery_score_v2
|
||||||
|
|
||||||
lbm_change = calculate_lbm_28d_change(profile_id)
|
lbm_change = calculate_lbm_28d_change(profile_id)
|
||||||
activity_score = calculate_activity_score(profile_id)
|
activity_score = calculate_activity_score(profile_id)
|
||||||
|
|
@ -251,12 +251,12 @@ def _detect_strength_plateau(profile_id: str) -> Dict:
|
||||||
if recovery_score and recovery_score < 60:
|
if recovery_score and recovery_score < 60:
|
||||||
factors.append('Recovery Score niedrig → möglicherweise Übertraining')
|
factors.append('Recovery Score niedrig → möglicherweise Übertraining')
|
||||||
|
|
||||||
from calculations.nutrition_metrics import calculate_protein_adequacy_28d
|
from data_layer.nutrition_metrics import calculate_protein_adequacy_28d
|
||||||
protein_score = calculate_protein_adequacy_28d(profile_id)
|
protein_score = calculate_protein_adequacy_28d(profile_id)
|
||||||
if protein_score and protein_score < 70:
|
if protein_score and protein_score < 70:
|
||||||
factors.append('Proteinzufuhr unter Zielbereich')
|
factors.append('Proteinzufuhr unter Zielbereich')
|
||||||
|
|
||||||
from calculations.activity_metrics import calculate_monotony_score
|
from data_layer.activity_metrics import calculate_monotony_score
|
||||||
monotony = calculate_monotony_score(profile_id)
|
monotony = calculate_monotony_score(profile_id)
|
||||||
if monotony and monotony > 2.0:
|
if monotony and monotony > 2.0:
|
||||||
factors.append('Hohe Trainingsmonotonie → Stimulus-Anpassung')
|
factors.append('Hohe Trainingsmonotonie → Stimulus-Anpassung')
|
||||||
|
|
@ -274,8 +274,8 @@ def _detect_strength_plateau(profile_id: str) -> Dict:
|
||||||
|
|
||||||
def _detect_endurance_plateau(profile_id: str) -> Dict:
|
def _detect_endurance_plateau(profile_id: str) -> Dict:
|
||||||
"""Detect endurance plateau"""
|
"""Detect endurance plateau"""
|
||||||
from calculations.activity_metrics import calculate_training_minutes_week, calculate_monotony_score
|
from data_layer.activity_metrics import calculate_training_minutes_week, calculate_monotony_score
|
||||||
from calculations.recovery_metrics import calculate_vo2max_trend_28d
|
from data_layer.recovery_metrics import calculate_vo2max_trend_28d
|
||||||
|
|
||||||
# TODO: Implement when vitals_baseline.vo2_max is populated
|
# TODO: Implement when vitals_baseline.vo2_max is populated
|
||||||
return {'plateau_detected': False, 'reason': 'VO2max tracking not yet implemented'}
|
return {'plateau_detected': False, 'reason': 'VO2max tracking not yet implemented'}
|
||||||
|
|
@ -303,7 +303,7 @@ def calculate_top_drivers(profile_id: str) -> Optional[List[Dict]]:
|
||||||
drivers = []
|
drivers = []
|
||||||
|
|
||||||
# 1. Energy balance
|
# 1. Energy balance
|
||||||
from calculations.nutrition_metrics import calculate_energy_balance_7d
|
from data_layer.nutrition_metrics import calculate_energy_balance_7d
|
||||||
balance = calculate_energy_balance_7d(profile_id)
|
balance = calculate_energy_balance_7d(profile_id)
|
||||||
if balance is not None:
|
if balance is not None:
|
||||||
if -500 <= balance <= -200:
|
if -500 <= balance <= -200:
|
||||||
|
|
@ -327,7 +327,7 @@ def calculate_top_drivers(profile_id: str) -> Optional[List[Dict]]:
|
||||||
})
|
})
|
||||||
|
|
||||||
# 2. Protein adequacy
|
# 2. Protein adequacy
|
||||||
from calculations.nutrition_metrics import calculate_protein_adequacy_28d
|
from data_layer.nutrition_metrics import calculate_protein_adequacy_28d
|
||||||
protein_score = calculate_protein_adequacy_28d(profile_id)
|
protein_score = calculate_protein_adequacy_28d(profile_id)
|
||||||
if protein_score is not None:
|
if protein_score is not None:
|
||||||
if protein_score >= 80:
|
if protein_score >= 80:
|
||||||
|
|
@ -348,7 +348,7 @@ def calculate_top_drivers(profile_id: str) -> Optional[List[Dict]]:
|
||||||
})
|
})
|
||||||
|
|
||||||
# 3. Sleep duration
|
# 3. Sleep duration
|
||||||
from calculations.recovery_metrics import calculate_sleep_avg_duration_7d
|
from data_layer.recovery_metrics import calculate_sleep_avg_duration_7d
|
||||||
sleep_hours = calculate_sleep_avg_duration_7d(profile_id)
|
sleep_hours = calculate_sleep_avg_duration_7d(profile_id)
|
||||||
if sleep_hours is not None:
|
if sleep_hours is not None:
|
||||||
if sleep_hours >= 7:
|
if sleep_hours >= 7:
|
||||||
|
|
@ -369,7 +369,7 @@ def calculate_top_drivers(profile_id: str) -> Optional[List[Dict]]:
|
||||||
})
|
})
|
||||||
|
|
||||||
# 4. Sleep regularity
|
# 4. Sleep regularity
|
||||||
from calculations.recovery_metrics import calculate_sleep_regularity_proxy
|
from data_layer.recovery_metrics import calculate_sleep_regularity_proxy
|
||||||
regularity = calculate_sleep_regularity_proxy(profile_id)
|
regularity = calculate_sleep_regularity_proxy(profile_id)
|
||||||
if regularity is not None:
|
if regularity is not None:
|
||||||
if regularity <= 45:
|
if regularity <= 45:
|
||||||
|
|
@ -390,7 +390,7 @@ def calculate_top_drivers(profile_id: str) -> Optional[List[Dict]]:
|
||||||
})
|
})
|
||||||
|
|
||||||
# 5. Training consistency
|
# 5. Training consistency
|
||||||
from calculations.activity_metrics import calculate_training_frequency_7d
|
from data_layer.activity_metrics import calculate_training_frequency_7d
|
||||||
frequency = calculate_training_frequency_7d(profile_id)
|
frequency = calculate_training_frequency_7d(profile_id)
|
||||||
if frequency is not None:
|
if frequency is not None:
|
||||||
if 3 <= frequency <= 6:
|
if 3 <= frequency <= 6:
|
||||||
|
|
@ -411,7 +411,7 @@ def calculate_top_drivers(profile_id: str) -> Optional[List[Dict]]:
|
||||||
})
|
})
|
||||||
|
|
||||||
# 6. Quality sessions
|
# 6. Quality sessions
|
||||||
from calculations.activity_metrics import calculate_quality_sessions_pct
|
from data_layer.activity_metrics import calculate_quality_sessions_pct
|
||||||
quality_pct = calculate_quality_sessions_pct(profile_id)
|
quality_pct = calculate_quality_sessions_pct(profile_id)
|
||||||
if quality_pct is not None:
|
if quality_pct is not None:
|
||||||
if quality_pct >= 75:
|
if quality_pct >= 75:
|
||||||
|
|
@ -432,7 +432,7 @@ def calculate_top_drivers(profile_id: str) -> Optional[List[Dict]]:
|
||||||
})
|
})
|
||||||
|
|
||||||
# 7. Recovery score
|
# 7. Recovery score
|
||||||
from calculations.recovery_metrics import calculate_recovery_score_v2
|
from data_layer.recovery_metrics import calculate_recovery_score_v2
|
||||||
recovery = calculate_recovery_score_v2(profile_id)
|
recovery = calculate_recovery_score_v2(profile_id)
|
||||||
if recovery is not None:
|
if recovery is not None:
|
||||||
if recovery >= 70:
|
if recovery >= 70:
|
||||||
|
|
@ -453,7 +453,7 @@ def calculate_top_drivers(profile_id: str) -> Optional[List[Dict]]:
|
||||||
})
|
})
|
||||||
|
|
||||||
# 8. Rest day compliance
|
# 8. Rest day compliance
|
||||||
from calculations.activity_metrics import calculate_rest_day_compliance
|
from data_layer.activity_metrics import calculate_rest_day_compliance
|
||||||
compliance = calculate_rest_day_compliance(profile_id)
|
compliance = calculate_rest_day_compliance(profile_id)
|
||||||
if compliance is not None:
|
if compliance is not None:
|
||||||
if compliance >= 80:
|
if compliance >= 80:
|
||||||
|
|
|
||||||
|
|
@ -742,7 +742,7 @@ def calculate_sleep_regularity_proxy(profile_id: str) -> Optional[float]:
|
||||||
|
|
||||||
def calculate_recent_load_balance_3d(profile_id: str) -> Optional[int]:
|
def calculate_recent_load_balance_3d(profile_id: str) -> Optional[int]:
|
||||||
"""Calculate proxy internal load last 3 days"""
|
"""Calculate proxy internal load last 3 days"""
|
||||||
from calculations.activity_metrics import calculate_proxy_internal_load_7d
|
from data_layer.activity_metrics import calculate_proxy_internal_load_7d
|
||||||
|
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
cur = get_cursor(conn)
|
cur = get_cursor(conn)
|
||||||
|
|
|
||||||
|
|
@ -183,10 +183,10 @@ def calculate_goal_progress_score(profile_id: str) -> Optional[int]:
|
||||||
return None # No goals/focus areas configured
|
return None # No goals/focus areas configured
|
||||||
|
|
||||||
# Calculate sub-scores
|
# Calculate sub-scores
|
||||||
from calculations.body_metrics import calculate_body_progress_score
|
from data_layer.body_metrics import calculate_body_progress_score
|
||||||
from calculations.nutrition_metrics import calculate_nutrition_score
|
from data_layer.nutrition_metrics import calculate_nutrition_score
|
||||||
from calculations.activity_metrics import calculate_activity_score
|
from data_layer.activity_metrics import calculate_activity_score
|
||||||
from calculations.recovery_metrics import calculate_recovery_score_v2
|
from data_layer.recovery_metrics import calculate_recovery_score_v2
|
||||||
|
|
||||||
body_score = calculate_body_progress_score(profile_id, focus_weights)
|
body_score = calculate_body_progress_score(profile_id, focus_weights)
|
||||||
nutrition_score = calculate_nutrition_score(profile_id, focus_weights)
|
nutrition_score = calculate_nutrition_score(profile_id, focus_weights)
|
||||||
|
|
@ -404,10 +404,10 @@ def calculate_data_quality_score(profile_id: str) -> int:
|
||||||
Overall data quality score (0-100)
|
Overall data quality score (0-100)
|
||||||
Combines quality from all modules
|
Combines quality from all modules
|
||||||
"""
|
"""
|
||||||
from calculations.body_metrics import calculate_body_data_quality
|
from data_layer.body_metrics import calculate_body_data_quality
|
||||||
from calculations.nutrition_metrics import calculate_nutrition_data_quality
|
from data_layer.nutrition_metrics import calculate_nutrition_data_quality
|
||||||
from calculations.activity_metrics import calculate_activity_data_quality
|
from data_layer.activity_metrics import calculate_activity_data_quality
|
||||||
from calculations.recovery_metrics import calculate_recovery_data_quality
|
from data_layer.recovery_metrics import calculate_recovery_data_quality
|
||||||
|
|
||||||
body_quality = calculate_body_data_quality(profile_id)
|
body_quality = calculate_body_data_quality(profile_id)
|
||||||
nutrition_quality = calculate_nutrition_data_quality(profile_id)
|
nutrition_quality = calculate_nutrition_data_quality(profile_id)
|
||||||
|
|
@ -566,16 +566,16 @@ def calculate_category_progress(profile_id: str, category: str) -> Optional[int]
|
||||||
|
|
||||||
# Call the appropriate score function
|
# Call the appropriate score function
|
||||||
if score_func_name == 'body_progress_score':
|
if score_func_name == 'body_progress_score':
|
||||||
from calculations.body_metrics import calculate_body_progress_score
|
from data_layer.body_metrics import calculate_body_progress_score
|
||||||
return calculate_body_progress_score(profile_id)
|
return calculate_body_progress_score(profile_id)
|
||||||
elif score_func_name == 'nutrition_score':
|
elif score_func_name == 'nutrition_score':
|
||||||
from calculations.nutrition_metrics import calculate_nutrition_score
|
from data_layer.nutrition_metrics import calculate_nutrition_score
|
||||||
return calculate_nutrition_score(profile_id)
|
return calculate_nutrition_score(profile_id)
|
||||||
elif score_func_name == 'activity_score':
|
elif score_func_name == 'activity_score':
|
||||||
from calculations.activity_metrics import calculate_activity_score
|
from data_layer.activity_metrics import calculate_activity_score
|
||||||
return calculate_activity_score(profile_id)
|
return calculate_activity_score(profile_id)
|
||||||
elif score_func_name == 'recovery_score':
|
elif score_func_name == 'recovery_score':
|
||||||
from calculations.recovery_metrics import calculate_recovery_score_v2
|
from data_layer.recovery_metrics import calculate_recovery_score_v2
|
||||||
return calculate_recovery_score_v2(profile_id)
|
return calculate_recovery_score_v2(profile_id)
|
||||||
elif score_func_name == 'data_quality_score':
|
elif score_func_name == 'data_quality_score':
|
||||||
return calculate_data_quality_score(profile_id)
|
return calculate_data_quality_score(profile_id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user