feat: add Phase 5 Progression & Analytics — smart suggestions, dashboard, schedule
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>
This commit is contained in:
86
app/routes/schedule.py
Normal file
86
app/routes/schedule.py
Normal file
@@ -0,0 +1,86 @@
|
||||
"""4-week schedule calendar routes.
|
||||
|
||||
Displays a calendar view showing which workout day maps to which date.
|
||||
"""
|
||||
|
||||
from datetime import date, timedelta
|
||||
|
||||
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.exercise_service import ExerciseService
|
||||
from app.services.workout_session_service import WorkoutSessionService
|
||||
from app.utils.auth import get_current_admin_user, get_active_profile_id
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/schedule", tags=["schedule"])
|
||||
|
||||
|
||||
@router.get("", response_class=HTMLResponse)
|
||||
async def schedule_view(
|
||||
request: Request,
|
||||
session: Session = Depends(get_db_session),
|
||||
admin: User = Depends(get_current_admin_user),
|
||||
):
|
||||
"""Render the 4-week schedule calendar.
|
||||
|
||||
Shows a 4-week grid where each training day is mapped to a
|
||||
calendar date. Days with completed sessions are highlighted.
|
||||
"""
|
||||
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)
|
||||
workout_days = exercise_service.list_workout_days()
|
||||
|
||||
# Build 4-week calendar starting from Monday of current week
|
||||
today = date.today()
|
||||
monday = today - timedelta(days=today.weekday())
|
||||
|
||||
weeks = []
|
||||
completed_dates = set()
|
||||
|
||||
# Get completed sessions for highlighting
|
||||
if active_profile_id:
|
||||
ws_service = WorkoutSessionService(session)
|
||||
sessions_list = ws_service.list_sessions(
|
||||
user_id=active_profile_id, limit=100,
|
||||
)
|
||||
completed_dates = {ws.date for ws in sessions_list}
|
||||
|
||||
# 4 workout days per week, 4 weeks
|
||||
for week_num in range(4):
|
||||
week_start = monday + timedelta(weeks=week_num)
|
||||
week_data = {
|
||||
"week_number": week_num + 1,
|
||||
"days": [],
|
||||
}
|
||||
for day_offset, workout_day in enumerate(workout_days):
|
||||
training_date = week_start + timedelta(days=day_offset)
|
||||
is_today = training_date == today
|
||||
is_completed = training_date in completed_dates
|
||||
|
||||
week_data["days"].append({
|
||||
"workout_day": workout_day,
|
||||
"date": training_date,
|
||||
"is_today": is_today,
|
||||
"is_completed": is_completed,
|
||||
})
|
||||
weeks.append(week_data)
|
||||
|
||||
templates = request.app.state.templates
|
||||
return templates.TemplateResponse("pages/schedule.html", {
|
||||
"request": request,
|
||||
"weeks": weeks,
|
||||
"active_profile": active_profile,
|
||||
"admin": admin,
|
||||
})
|
||||
Reference in New Issue
Block a user