This commit is contained in:
team3
2026-06-17 14:25:05 +02:00
parent 5268c77fde
commit a503285b6f
5 changed files with 50 additions and 21 deletions

View File

@@ -64,6 +64,7 @@ CREATE TABLE IF NOT EXISTS baustein_progress (
topic TEXT NOT NULL,
baustein TEXT NOT NULL,
gute_antworten INTEGER NOT NULL DEFAULT 0,
streak INTEGER NOT NULL DEFAULT 0,
absolviert TEXT,
verstanden TEXT,
gemeistert TEXT,
@@ -106,6 +107,10 @@ async def init_db():
await db.execute("ALTER TABLE baustein_progress ADD COLUMN gemeistert TEXT")
except aiosqlite.OperationalError:
pass
try: # Migration für Bestands-DBs ohne streak-Spalte (persistente Streak-Bonus-Folge)
await db.execute("ALTER TABLE baustein_progress ADD COLUMN streak INTEGER NOT NULL DEFAULT 0")
except aiosqlite.OperationalError:
pass
# Migration: alte vertiefungen-Tabelle → baustein_texte (Bestand = lange Form, art 'deepdive')
cursor = await db.execute("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'vertiefungen'")
if await cursor.fetchone():
@@ -343,10 +348,10 @@ async def list_vertiefungen(topic: str) -> dict[str, set[str]]:
async def list_baustein_progress(topic: str) -> list[dict]:
db = await get_db()
cursor = await db.execute(
"SELECT baustein, gute_antworten, absolviert, verstanden, gemeistert FROM baustein_progress WHERE topic = ?", (topic,)
"SELECT baustein, gute_antworten, streak, absolviert, verstanden, gemeistert FROM baustein_progress WHERE topic = ?", (topic,)
)
rows = await cursor.fetchall()
return [{"baustein": b, "gute_antworten": n, "absolviert": a, "verstanden": v, "gemeistert": m} for b, n, a, v, m in rows]
return [{"baustein": b, "gute_antworten": n, "streak": s, "absolviert": a, "verstanden": v, "gemeistert": m} for b, n, s, a, v, m in rows]
async def set_baustein_score(topic: str, baustein: str, score: int) -> int:
@@ -363,6 +368,19 @@ async def set_baustein_score(topic: str, baustein: str, score: int) -> int:
return score
async def set_baustein_streak(topic: str, baustein: str, streak: int) -> None:
"""Persistiert die Streak-Folge (Bonus) absolut — überlebt Reload/Session-Wechsel."""
db = await get_db()
await db.execute(
"""INSERT INTO baustein_progress (topic, baustein, streak, updated_at)
VALUES (?, ?, ?, ?)
ON CONFLICT(topic, baustein) DO UPDATE SET
streak = excluded.streak, updated_at = excluded.updated_at""",
(topic, baustein, streak, _now()),
)
await db.commit()
async def set_baustein_verstanden(topic: str, baustein: str) -> bool:
"""Markiert verstanden (Mastery); True nur beim ersten Mal. Sticky wie absolviert."""
db = await get_db()