feat: introduce fitness dashboard overview and enhance activity metrics
- Added new functions to build fitness dashboard visualizations, including weekly training volume and training type distribution charts. - Updated the `charts.py` router to include a new endpoint for the fitness dashboard, integrating data from activity metrics. - Refactored existing activity-related functions to improve modularity and maintainability. - Updated frontend components to reflect the new fitness terminology and integrate the fitness dashboard overview, enhancing user experience.
This commit is contained in:
1 parent
d7304c1a44
commit
b5c5f2f612
11 files changed
+739
-124
No files matched your search
+26
-108
@@ -33,6 +33,7 @@ from data_layer.body_metrics import (
|
||||
)
|
||||
from data_layer.body_viz import get_body_history_viz_bundle
|
||||
from data_layer.nutrition_viz import get_nutrition_history_viz_bundle
|
||||
from data_layer.fitness_viz import get_fitness_dashboard_viz_bundle
|
||||
from data_layer.nutrition_metrics import (
|
||||
get_nutrition_average_data,
|
||||
get_protein_targets_data,
|
||||
@@ -44,13 +45,14 @@ from data_layer.nutrition_metrics import (
|
||||
)
|
||||
from data_layer.activity_metrics import (
|
||||
get_activity_summary_data,
|
||||
get_training_type_distribution_data,
|
||||
calculate_training_minutes_week,
|
||||
calculate_quality_sessions_pct,
|
||||
calculate_proxy_internal_load_7d,
|
||||
calculate_monotony_score,
|
||||
calculate_strain_score,
|
||||
calculate_ability_balance
|
||||
calculate_ability_balance,
|
||||
build_training_volume_chart_payload,
|
||||
build_training_type_distribution_chart_payload,
|
||||
)
|
||||
from data_layer.recovery_metrics import (
|
||||
get_sleep_duration_data,
|
||||
@@ -288,6 +290,26 @@ def get_nutrition_history_viz(
|
||||
return serialize_dates(bundle)
|
||||
|
||||
|
||||
@router.get("/fitness-dashboard-viz")
|
||||
def get_fitness_dashboard_viz(
|
||||
days: int = Query(
|
||||
default=28,
|
||||
ge=7,
|
||||
le=9999,
|
||||
description="Analysefenster in Tagen (9999 = lange Historie)",
|
||||
),
|
||||
session: dict = Depends(require_auth),
|
||||
) -> Dict:
|
||||
"""
|
||||
Layer 2b: Fitness-Übersicht — KPI-Kacheln + Volumen- und Typ-Verteilungs-Charts.
|
||||
|
||||
Daten aus activity_metrics (gleiche Payloads wie training-volume / training-type-distribution).
|
||||
"""
|
||||
profile_id = session["profile_id"]
|
||||
bundle = get_fitness_dashboard_viz_bundle(profile_id, days)
|
||||
return serialize_dates(bundle)
|
||||
|
||||
|
||||
@router.get("/circumferences")
|
||||
def get_circumferences_chart(
|
||||
max_age_days: int = Query(default=90, ge=7, le=365),
|
||||
@@ -1051,66 +1073,7 @@ def get_training_volume_chart(
|
||||
Chart.js bar chart with weekly training minutes
|
||||
"""
|
||||
profile_id = session['profile_id']
|
||||
|
||||
from db import get_db, get_cursor
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cutoff = (datetime.now() - timedelta(weeks=weeks)).strftime('%Y-%m-%d')
|
||||
|
||||
# Get weekly aggregates
|
||||
cur.execute(
|
||||
"""SELECT
|
||||
DATE_TRUNC('week', date) as week_start,
|
||||
SUM(duration_min) as total_minutes,
|
||||
COUNT(*) as session_count
|
||||
FROM activity_log
|
||||
WHERE profile_id=%s AND date >= %s
|
||||
GROUP BY week_start
|
||||
ORDER BY week_start""",
|
||||
(profile_id, cutoff)
|
||||
)
|
||||
rows = cur.fetchall()
|
||||
|
||||
if not rows:
|
||||
return {
|
||||
"chart_type": "bar",
|
||||
"data": {
|
||||
"labels": [],
|
||||
"datasets": []
|
||||
},
|
||||
"metadata": {
|
||||
"confidence": "insufficient",
|
||||
"data_points": 0,
|
||||
"message": "Keine Aktivitätsdaten vorhanden"
|
||||
}
|
||||
}
|
||||
|
||||
labels = [row['week_start'].strftime('KW %V') for row in rows]
|
||||
values = [safe_float(row['total_minutes']) for row in rows]
|
||||
|
||||
confidence = calculate_confidence(len(rows), weeks * 7, "general")
|
||||
|
||||
return {
|
||||
"chart_type": "bar",
|
||||
"data": {
|
||||
"labels": labels,
|
||||
"datasets": [
|
||||
{
|
||||
"label": "Trainingsminuten",
|
||||
"data": values,
|
||||
"backgroundColor": "#1D9E75",
|
||||
"borderColor": "#085041",
|
||||
"borderWidth": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": serialize_dates({
|
||||
"confidence": confidence,
|
||||
"data_points": len(rows),
|
||||
"avg_minutes_week": round(sum(values) / len(values), 1) if values else 0,
|
||||
"total_sessions": sum(row['session_count'] for row in rows)
|
||||
})
|
||||
}
|
||||
return build_training_volume_chart_payload(profile_id, weeks)
|
||||
|
||||
|
||||
@router.get("/training-type-distribution")
|
||||
@@ -1131,52 +1094,7 @@ def get_training_type_distribution_chart(
|
||||
Chart.js pie chart with training categories
|
||||
"""
|
||||
profile_id = session['profile_id']
|
||||
|
||||
dist_data = get_training_type_distribution_data(profile_id, days)
|
||||
|
||||
if dist_data['confidence'] == 'insufficient':
|
||||
return {
|
||||
"chart_type": "pie",
|
||||
"data": {
|
||||
"labels": [],
|
||||
"datasets": []
|
||||
},
|
||||
"metadata": {
|
||||
"confidence": "insufficient",
|
||||
"data_points": 0,
|
||||
"message": "Keine Trainingstypen-Daten"
|
||||
}
|
||||
}
|
||||
|
||||
labels = [item['category'] for item in dist_data['distribution']]
|
||||
values = [item['count'] for item in dist_data['distribution']]
|
||||
|
||||
# Color palette for training categories
|
||||
colors = [
|
||||
"#1D9E75", "#3B82F6", "#F59E0B", "#EF4444",
|
||||
"#8B5CF6", "#10B981", "#F97316", "#06B6D4"
|
||||
]
|
||||
|
||||
return {
|
||||
"chart_type": "pie",
|
||||
"data": {
|
||||
"labels": labels,
|
||||
"datasets": [
|
||||
{
|
||||
"data": values,
|
||||
"backgroundColor": colors[:len(values)],
|
||||
"borderWidth": 2,
|
||||
"borderColor": "#fff"
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"confidence": dist_data['confidence'],
|
||||
"total_sessions": dist_data['total_sessions'],
|
||||
"categorized_sessions": dist_data['categorized_sessions'],
|
||||
"uncategorized_sessions": dist_data['uncategorized_sessions']
|
||||
}
|
||||
}
|
||||
return build_training_type_distribution_chart_payload(profile_id, days)
|
||||
|
||||
|
||||
@router.get("/quality-sessions")
|
||||
|
||||
Reference in new issue
Block a user