mirror of
https://github.com/sstent/AICyclingCoach.git
synced 2026-02-01 20:12:37 +00:00
sync
This commit is contained in:
52
backend/app/routes/dashboard.py
Normal file
52
backend/app/routes/dashboard.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.database import get_db
|
||||
from app.models.workout import Workout
|
||||
from app.models.plan import Plan
|
||||
from app.models.garmin_sync_log import GarminSyncLog
|
||||
from sqlalchemy import select, desc
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/dashboard")
|
||||
async def get_dashboard_data(db: AsyncSession = Depends(get_db)):
|
||||
"""Get consolidated dashboard data"""
|
||||
try:
|
||||
# Recent workouts (last 7 days)
|
||||
workout_result = await db.execute(
|
||||
select(Workout)
|
||||
.where(Workout.start_time >= datetime.now() - timedelta(days=7))
|
||||
.order_by(desc(Workout.start_time))
|
||||
.limit(5)
|
||||
)
|
||||
recent_workouts = [w.to_dict() for w in workout_result.scalars().all()]
|
||||
|
||||
# Current active plan
|
||||
plan_result = await db.execute(
|
||||
select(Plan)
|
||||
.where(Plan.active == True)
|
||||
.order_by(desc(Plan.created_at))
|
||||
)
|
||||
current_plan = plan_result.scalar_one_or_none()
|
||||
|
||||
# Sync status
|
||||
sync_result = await db.execute(
|
||||
select(GarminSyncLog)
|
||||
.order_by(desc(GarminSyncLog.created_at))
|
||||
.limit(1)
|
||||
)
|
||||
last_sync = sync_result.scalar_one_or_none()
|
||||
|
||||
return {
|
||||
"recent_workouts": recent_workouts,
|
||||
"current_plan": current_plan.to_dict() if current_plan else None,
|
||||
"last_sync": last_sync.to_dict() if last_sync else None,
|
||||
"metrics": {
|
||||
"weekly_volume": sum(w.duration_seconds for w in recent_workouts) / 3600,
|
||||
"plan_progress": current_plan.progress if current_plan else 0
|
||||
}
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Dashboard data error: {str(e)}")
|
||||
9
backend/app/routes/health.py
Normal file
9
backend/app/routes/health.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
from app.services.health_monitor import HealthMonitor
|
||||
|
||||
router = APIRouter()
|
||||
monitor = HealthMonitor()
|
||||
|
||||
@router.get("/health")
|
||||
async def get_health():
|
||||
return monitor.check_system_health()
|
||||
Reference in New Issue
Block a user