feat: enhance fitness dashboard with new metrics and insights
- Refactored the `calculate_proxy_internal_load_7d` function to `calculate_proxy_internal_load_window`, allowing for dynamic day range input. - Introduced new functions for calculating training volume deltas and building fitness progress insights, enhancing user feedback on training metrics. - Updated the fitness dashboard to include new charts for quality sessions and load monitoring, improving data visualization. - Integrated these new metrics into the fitness dashboard overview, providing users with comprehensive insights into their training performance. - Streamlined the router to utilize the new chart-building functions, ensuring consistency and maintainability across the application.
This commit is contained in:
1 parent
22c5f695c9
commit
bf84e3c2a5
7 files changed
+540
-298
No files matched your search
+4
-127
@@ -46,13 +46,13 @@ from data_layer.nutrition_metrics import (
|
||||
from data_layer.activity_metrics import (
|
||||
get_activity_summary_data,
|
||||
calculate_training_minutes_week,
|
||||
calculate_quality_sessions_pct,
|
||||
calculate_proxy_internal_load_7d,
|
||||
calculate_monotony_score,
|
||||
calculate_strain_score,
|
||||
calculate_ability_balance,
|
||||
build_training_volume_chart_payload,
|
||||
build_training_type_distribution_chart_payload,
|
||||
build_quality_sessions_chart_payload,
|
||||
build_load_monitoring_chart_payload,
|
||||
)
|
||||
from data_layer.recovery_metrics import (
|
||||
get_sleep_duration_data,
|
||||
@@ -1115,63 +1115,7 @@ def get_quality_sessions_chart(
|
||||
Chart.js bar chart with quality metrics
|
||||
"""
|
||||
profile_id = session['profile_id']
|
||||
|
||||
# Calculate quality session percentage
|
||||
quality_pct = calculate_quality_sessions_pct(profile_id, days)
|
||||
|
||||
from db import get_db, get_cursor
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cutoff = (datetime.now() - timedelta(days=days)).strftime('%Y-%m-%d')
|
||||
|
||||
cur.execute(
|
||||
"""SELECT COUNT(*) as total
|
||||
FROM activity_log
|
||||
WHERE profile_id=%s AND date >= %s""",
|
||||
(profile_id, cutoff)
|
||||
)
|
||||
row = cur.fetchone()
|
||||
total_sessions = row['total'] if row else 0
|
||||
|
||||
if total_sessions == 0:
|
||||
return {
|
||||
"chart_type": "bar",
|
||||
"data": {
|
||||
"labels": [],
|
||||
"datasets": []
|
||||
},
|
||||
"metadata": {
|
||||
"confidence": "insufficient",
|
||||
"data_points": 0,
|
||||
"message": "Keine Aktivitätsdaten"
|
||||
}
|
||||
}
|
||||
|
||||
quality_count = int(quality_pct / 100 * total_sessions)
|
||||
regular_count = total_sessions - quality_count
|
||||
|
||||
return {
|
||||
"chart_type": "bar",
|
||||
"data": {
|
||||
"labels": ["Qualitäts-Sessions", "Reguläre Sessions"],
|
||||
"datasets": [
|
||||
{
|
||||
"label": "Anzahl",
|
||||
"data": [quality_count, regular_count],
|
||||
"backgroundColor": ["#1D9E75", "#888"],
|
||||
"borderColor": "#085041",
|
||||
"borderWidth": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"confidence": calculate_confidence(total_sessions, days, "general"),
|
||||
"data_points": total_sessions,
|
||||
"quality_pct": round(quality_pct, 1),
|
||||
"quality_count": quality_count,
|
||||
"regular_count": regular_count
|
||||
}
|
||||
}
|
||||
return build_quality_sessions_chart_payload(profile_id, days)
|
||||
|
||||
|
||||
@router.get("/load-monitoring")
|
||||
@@ -1192,74 +1136,7 @@ def get_load_monitoring_chart(
|
||||
Chart.js line chart with load metrics
|
||||
"""
|
||||
profile_id = session['profile_id']
|
||||
|
||||
# Calculate loads
|
||||
acute_load = calculate_proxy_internal_load_7d(profile_id)
|
||||
chronic_load = calculate_proxy_internal_load_7d(profile_id, days=28)
|
||||
|
||||
# ACWR (Acute:Chronic Workload Ratio)
|
||||
acwr = acute_load / chronic_load if chronic_load > 0 else 0
|
||||
|
||||
# Fetch daily loads for timeline
|
||||
from db import get_db, get_cursor
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cutoff = (datetime.now() - timedelta(days=days)).strftime('%Y-%m-%d')
|
||||
|
||||
cur.execute(
|
||||
"""SELECT
|
||||
date,
|
||||
SUM(duration_min * COALESCE(rpe, 5)) as daily_load
|
||||
FROM activity_log
|
||||
WHERE profile_id=%s AND date >= %s
|
||||
GROUP BY date
|
||||
ORDER BY date""",
|
||||
(profile_id, cutoff)
|
||||
)
|
||||
rows = cur.fetchall()
|
||||
|
||||
if not rows:
|
||||
return {
|
||||
"chart_type": "line",
|
||||
"data": {
|
||||
"labels": [],
|
||||
"datasets": []
|
||||
},
|
||||
"metadata": {
|
||||
"confidence": "insufficient",
|
||||
"data_points": 0,
|
||||
"message": "Keine Load-Daten"
|
||||
}
|
||||
}
|
||||
|
||||
labels = [row['date'].isoformat() for row in rows]
|
||||
values = [safe_float(row['daily_load']) for row in rows]
|
||||
|
||||
return {
|
||||
"chart_type": "line",
|
||||
"data": {
|
||||
"labels": labels,
|
||||
"datasets": [
|
||||
{
|
||||
"label": "Tages-Load",
|
||||
"data": values,
|
||||
"borderColor": "#1D9E75",
|
||||
"backgroundColor": "rgba(29, 158, 117, 0.1)",
|
||||
"borderWidth": 2,
|
||||
"tension": 0.3,
|
||||
"fill": True
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": serialize_dates({
|
||||
"confidence": calculate_confidence(len(rows), days, "general"),
|
||||
"data_points": len(rows),
|
||||
"acute_load_7d": round(acute_load, 1),
|
||||
"chronic_load_28d": round(chronic_load, 1),
|
||||
"acwr": round(acwr, 2),
|
||||
"acwr_status": "optimal" if 0.8 <= acwr <= 1.3 else "suboptimal"
|
||||
})
|
||||
}
|
||||
return build_load_monitoring_chart_payload(profile_id, days)
|
||||
|
||||
|
||||
@router.get("/monotony-strain")
|
||||
|
||||
Reference in new issue
Block a user