Add auto-progression engine (ProgressionService) with rep increase, weight increase, deload, and felt-easy acceleration rules. Add AnalyticsService for user stats, exercise progress charts, and volume-by-day data. New dashboard and schedule routes with Chart.js visualizations. Progression badges shown inline on workout day view. Navigation updated with Dashboard and Schedule links. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
103 lines
3.1 KiB
Python
103 lines
3.1 KiB
Python
"""Progress dashboard routes.
|
|
|
|
Displays summary statistics, volume charts, and per-exercise progress.
|
|
"""
|
|
|
|
import json
|
|
|
|
import structlog
|
|
from fastapi import APIRouter, Depends, Request
|
|
from fastapi.responses import HTMLResponse
|
|
from sqlmodel import Session
|
|
|
|
from app.database import get_db_session
|
|
from app.models.user import User
|
|
from app.services.analytics_service import AnalyticsService
|
|
from app.services.exercise_service import ExerciseService
|
|
from app.services.progression_service import ProgressionService
|
|
from app.utils.auth import get_current_admin_user, get_active_profile_id
|
|
|
|
logger = structlog.get_logger(__name__)
|
|
|
|
router = APIRouter(prefix="/dashboard", tags=["dashboard"])
|
|
|
|
|
|
@router.get("", response_class=HTMLResponse)
|
|
async def dashboard(
|
|
request: Request,
|
|
session: Session = Depends(get_db_session),
|
|
admin: User = Depends(get_current_admin_user),
|
|
):
|
|
"""Render the progress dashboard for the active profile.
|
|
|
|
Shows: summary stats, volume by day chart, exercise progress links.
|
|
"""
|
|
active_profile_id = get_active_profile_id(request)
|
|
active_profile = (
|
|
session.get(User, active_profile_id)
|
|
if active_profile_id
|
|
else None
|
|
)
|
|
|
|
stats = {}
|
|
volume_data = {}
|
|
if active_profile_id:
|
|
analytics = AnalyticsService(session)
|
|
stats = analytics.get_user_stats(active_profile_id)
|
|
volume_data = analytics.get_volume_by_day(active_profile_id)
|
|
|
|
exercise_service = ExerciseService(session)
|
|
exercises = exercise_service.list_exercises()
|
|
|
|
templates = request.app.state.templates
|
|
return templates.TemplateResponse("pages/dashboard.html", {
|
|
"request": request,
|
|
"stats": stats,
|
|
"volume_data_json": json.dumps(volume_data),
|
|
"exercises": exercises,
|
|
"active_profile": active_profile,
|
|
"admin": admin,
|
|
})
|
|
|
|
|
|
@router.get("/exercise/{exercise_id}", response_class=HTMLResponse)
|
|
async def exercise_progress(
|
|
exercise_id: int,
|
|
request: Request,
|
|
session: Session = Depends(get_db_session),
|
|
admin: User = Depends(get_current_admin_user),
|
|
):
|
|
"""Render per-exercise progress page with charts and suggestions."""
|
|
active_profile_id = get_active_profile_id(request)
|
|
active_profile = (
|
|
session.get(User, active_profile_id)
|
|
if active_profile_id
|
|
else None
|
|
)
|
|
|
|
exercise_service = ExerciseService(session)
|
|
exercise = exercise_service.get_exercise_by_id(exercise_id)
|
|
|
|
progress_data = {}
|
|
suggestion = {}
|
|
if active_profile_id:
|
|
analytics = AnalyticsService(session)
|
|
progress_data = analytics.get_exercise_progress(
|
|
active_profile_id, exercise_id,
|
|
)
|
|
|
|
progression = ProgressionService(session)
|
|
suggestion = progression.get_suggestion(
|
|
active_profile_id, exercise_id,
|
|
)
|
|
|
|
templates = request.app.state.templates
|
|
return templates.TemplateResponse("pages/exercise_progress.html", {
|
|
"request": request,
|
|
"exercise": exercise,
|
|
"progress_data_json": json.dumps(progress_data),
|
|
"suggestion": suggestion,
|
|
"active_profile": active_profile,
|
|
"admin": admin,
|
|
})
|