Update stats
Build Backend / build (push) Successful in 1m59s
Build Frontend / build (push) Failing after 2m55s

This commit is contained in:
2026-05-31 09:23:50 +02:00
parent 7d9c22d5d3
commit 7061e78305
9 changed files with 173 additions and 17 deletions
+21
View File
@@ -111,3 +111,24 @@ async def update_session(
await session.commit()
await session.refresh(sleep_session)
return sleep_session
async def get_all_time_stats(session: AsyncSession) -> tuple[int, float]:
statement = select(func.count(), func.min(SleepSession.start_time))
result = await session.exec(statement)
total_sessions, first_session_time = result.one()
if total_sessions == 0 or first_session_time is None:
return 0, 0.0
# DB has naive datetimes
first_session_time_naive = first_session_time.replace(tzinfo=None)
# Get current date (naive for comparison)
today_date = datetime.now().date()
first_date = first_session_time_naive.date()
num_days = (today_date - first_date).days + 1
avg_sleeps = total_sessions / num_days if num_days > 0 else 0.0
return total_sessions, avg_sleeps