feat: live-ticking In Session timer using active session start times

SidebarStatsBar now computes active session elapsed time client-side
from started_at timestamps, ticking every 60s. Backend only returns
completed session minutes to avoid double-counting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-03-15 15:50:59 -04:00
parent 5faa654b7b
commit d0af8357a6
3 changed files with 35 additions and 7 deletions

View File

@@ -65,16 +65,17 @@ async def get_sidebar_stats(
)
active_count = active_result.scalar() or 0
# --- Total session minutes today ---
# --- Completed session minutes today (active session time computed client-side) ---
duration_expr = func.extract(
"epoch",
func.coalesce(Session.completed_at, now_utc) - Session.started_at,
Session.completed_at - Session.started_at,
) / 60.0
duration_result = await db.execute(
select(func.coalesce(func.sum(duration_expr), 0)).where(
and_(
user_filter,
Session.started_at.isnot(None),
Session.completed_at.isnot(None),
Session.started_at >= today_start_utc,
)
)