I hate this fucking language.
This commit is contained in:
+22
-4
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import date, datetime, timedelta
|
||||
from typing import Any
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
@@ -9,6 +9,15 @@ import aiosqlite
|
||||
from server.config_loader import load_meds_config, today_str
|
||||
from server.db import new_id, utc_now_iso
|
||||
|
||||
|
||||
async def get_first_intake_day(db: aiosqlite.Connection, tz: ZoneInfo) -> str:
|
||||
cur = await db.execute("SELECT MIN(day) FROM intake_log WHERE status = 'taken'")
|
||||
row = await cur.fetchone()
|
||||
await cur.close()
|
||||
if row and row[0]:
|
||||
return str(row[0])
|
||||
return today_str(tz)
|
||||
|
||||
MILESTONE_DEFS: dict[str, str] = {
|
||||
"log_50": "Pharma-Intern: 50 Logs. Dein Arzt wäre stolz. Vielleicht.",
|
||||
"log_100": "Century Club: 100 Logs. Du bist offiziell zuverlässiger als dein WLAN.",
|
||||
@@ -100,12 +109,18 @@ async def compute_stats(db: aiosqlite.Connection) -> dict[str, Any]:
|
||||
slot_ids = [s.id for s in config.slots]
|
||||
streak = await compute_streak(db, tz)
|
||||
|
||||
days = 90
|
||||
first_day = await get_first_intake_day(db, tz)
|
||||
first_date = date.fromisoformat(first_day)
|
||||
today = datetime.now(tz).date()
|
||||
days_active = max(1, (today - first_date).days + 1)
|
||||
compliance_window_days = min(90, days_active)
|
||||
|
||||
taken = 0
|
||||
total = 0
|
||||
today = datetime.now(tz).date()
|
||||
for i in range(days):
|
||||
for i in range(compliance_window_days):
|
||||
d = (today - timedelta(days=i)).isoformat()
|
||||
if d < first_day:
|
||||
break
|
||||
for sid in slot_ids:
|
||||
total += 1
|
||||
cur = await db.execute(
|
||||
@@ -122,6 +137,9 @@ async def compute_stats(db: aiosqlite.Connection) -> dict[str, Any]:
|
||||
return {
|
||||
"streak": streak,
|
||||
"compliance_percent": compliance,
|
||||
"compliance_window_days": compliance_window_days,
|
||||
"days_active": days_active,
|
||||
"first_day": first_day,
|
||||
"total_taken": await count_logs(db),
|
||||
"milestones": milestones,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user