- Created NEW data_layer/correlations.py with all 11 correlation functions - Functions: Lag correlation (main + 3 helpers: energy/weight, protein/LBM, load/vitals) - Functions: Sleep-recovery correlation - Functions: Plateau detection (main + 3 detectors: weight, strength, endurance) - Functions: Top drivers analysis - Functions: Correlation confidence helper - Updated data_layer/__init__.py to import correlations module and export 5 main functions - Refactored placeholder_resolver.py to import correlations from data_layer (as correlation_metrics alias) - Removed ALL imports from calculations/ module in placeholder_resolver.py Module 6/6 complete. ALL calculations migrated to data_layer! Phase 0c Multi-Layer Architecture COMPLETE. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
160 lines
4.7 KiB
Python
160 lines
4.7 KiB
Python
"""
|
|
Data Layer - Pure Data Retrieval & Calculation Logic
|
|
|
|
This module provides structured data functions for all metrics.
|
|
NO FORMATTING. NO STRINGS WITH UNITS. Only structured data.
|
|
|
|
Usage:
|
|
from data_layer.body_metrics import get_weight_trend_data
|
|
|
|
data = get_weight_trend_data(profile_id="123", days=28)
|
|
# Returns: {"slope_28d": 0.23, "confidence": "high", ...}
|
|
|
|
Modules:
|
|
- body_metrics: Weight, body fat, lean mass, circumferences
|
|
- nutrition_metrics: Calories, protein, macros, adherence
|
|
- activity_metrics: Training volume, quality, abilities
|
|
- recovery_metrics: Sleep, RHR, HRV, recovery score
|
|
- health_metrics: Blood pressure, VO2Max, health stability
|
|
- goals: Active goals, progress, projections
|
|
- correlations: Lag-analysis, plateau detection
|
|
- utils: Shared functions (confidence, baseline, outliers)
|
|
|
|
Phase 0c: Multi-Layer Architecture
|
|
Version: 1.0
|
|
Created: 2026-03-28
|
|
"""
|
|
|
|
# Core utilities
|
|
from .utils import *
|
|
|
|
# Metric modules
|
|
from .body_metrics import *
|
|
from .nutrition_metrics import *
|
|
from .activity_metrics import *
|
|
from .recovery_metrics import *
|
|
from .health_metrics import *
|
|
from .scores import *
|
|
from .correlations import *
|
|
|
|
# Future imports (will be added as modules are created):
|
|
# from .goals import *
|
|
|
|
__all__ = [
|
|
# Utils
|
|
'calculate_confidence',
|
|
'serialize_dates',
|
|
|
|
# Body Metrics (Basic)
|
|
'get_latest_weight_data',
|
|
'get_weight_trend_data',
|
|
'get_body_composition_data',
|
|
'get_circumference_summary_data',
|
|
|
|
# Body Metrics (Calculated)
|
|
'calculate_weight_7d_median',
|
|
'calculate_weight_28d_slope',
|
|
'calculate_weight_90d_slope',
|
|
'calculate_goal_projection_date',
|
|
'calculate_goal_progress_pct',
|
|
'calculate_fm_28d_change',
|
|
'calculate_lbm_28d_change',
|
|
'calculate_waist_28d_delta',
|
|
'calculate_hip_28d_delta',
|
|
'calculate_chest_28d_delta',
|
|
'calculate_arm_28d_delta',
|
|
'calculate_thigh_28d_delta',
|
|
'calculate_waist_hip_ratio',
|
|
'calculate_recomposition_quadrant',
|
|
'calculate_body_progress_score',
|
|
'calculate_body_data_quality',
|
|
|
|
# Nutrition Metrics (Basic)
|
|
'get_nutrition_average_data',
|
|
'get_nutrition_days_data',
|
|
'get_protein_targets_data',
|
|
'get_energy_balance_data',
|
|
'get_protein_adequacy_data',
|
|
'get_macro_consistency_data',
|
|
|
|
# Nutrition Metrics (Calculated)
|
|
'calculate_energy_balance_7d',
|
|
'calculate_energy_deficit_surplus',
|
|
'calculate_protein_g_per_kg',
|
|
'calculate_protein_days_in_target',
|
|
'calculate_protein_adequacy_28d',
|
|
'calculate_macro_consistency_score',
|
|
'calculate_intake_volatility',
|
|
'calculate_nutrition_score',
|
|
'calculate_energy_availability_warning',
|
|
'calculate_fiber_avg_7d',
|
|
'calculate_sugar_avg_7d',
|
|
'calculate_nutrition_data_quality',
|
|
|
|
# Activity Metrics (Basic)
|
|
'get_activity_summary_data',
|
|
'get_activity_detail_data',
|
|
'get_training_type_distribution_data',
|
|
|
|
# Activity Metrics (Calculated)
|
|
'calculate_training_minutes_week',
|
|
'calculate_training_frequency_7d',
|
|
'calculate_quality_sessions_pct',
|
|
'calculate_intensity_proxy_distribution',
|
|
'calculate_ability_balance',
|
|
'calculate_ability_balance_strength',
|
|
'calculate_ability_balance_endurance',
|
|
'calculate_ability_balance_mental',
|
|
'calculate_ability_balance_coordination',
|
|
'calculate_ability_balance_mobility',
|
|
'calculate_proxy_internal_load_7d',
|
|
'calculate_monotony_score',
|
|
'calculate_strain_score',
|
|
'calculate_activity_score',
|
|
'calculate_rest_day_compliance',
|
|
'calculate_vo2max_trend_28d',
|
|
'calculate_activity_data_quality',
|
|
|
|
# Recovery Metrics (Basic)
|
|
'get_sleep_duration_data',
|
|
'get_sleep_quality_data',
|
|
'get_rest_days_data',
|
|
|
|
# Recovery Metrics (Calculated)
|
|
'calculate_recovery_score_v2',
|
|
'calculate_hrv_vs_baseline_pct',
|
|
'calculate_rhr_vs_baseline_pct',
|
|
'calculate_sleep_avg_duration_7d',
|
|
'calculate_sleep_debt_hours',
|
|
'calculate_sleep_regularity_proxy',
|
|
'calculate_recent_load_balance_3d',
|
|
'calculate_sleep_quality_7d',
|
|
'calculate_recovery_data_quality',
|
|
|
|
# Health Metrics
|
|
'get_resting_heart_rate_data',
|
|
'get_heart_rate_variability_data',
|
|
'get_vo2_max_data',
|
|
|
|
# Scoring Metrics
|
|
'get_user_focus_weights',
|
|
'get_focus_area_category',
|
|
'map_focus_to_score_components',
|
|
'map_category_de_to_en',
|
|
'calculate_category_weight',
|
|
'calculate_goal_progress_score',
|
|
'calculate_health_stability_score',
|
|
'calculate_data_quality_score',
|
|
'get_top_priority_goal',
|
|
'get_top_focus_area',
|
|
'calculate_focus_area_progress',
|
|
'calculate_category_progress',
|
|
|
|
# Correlation Metrics
|
|
'calculate_lag_correlation',
|
|
'calculate_correlation_sleep_recovery',
|
|
'calculate_plateau_detected',
|
|
'calculate_top_drivers',
|
|
'calculate_correlation_confidence',
|
|
]
|