This commit is contained in:
team3
2026-06-14 14:55:44 +02:00
parent 2b89e21cd3
commit 143e6d6f7c
7 changed files with 108 additions and 41 deletions

View File

@@ -65,6 +65,7 @@ CREATE TABLE IF NOT EXISTS baustein_progress (
baustein TEXT NOT NULL,
gute_antworten INTEGER NOT NULL DEFAULT 0,
absolviert TEXT,
verstanden TEXT,
updated_at TEXT NOT NULL,
PRIMARY KEY (topic, baustein)
)
@@ -96,6 +97,10 @@ async def init_db():
await db.execute("ALTER TABLE guides ADD COLUMN step INTEGER")
except aiosqlite.OperationalError:
pass
try: # Migration für Bestands-DBs ohne verstanden-Spalte (Mastery-Stufe)
await db.execute("ALTER TABLE baustein_progress ADD COLUMN verstanden TEXT")
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():
@@ -333,29 +338,41 @@ 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 FROM baustein_progress WHERE topic = ?", (topic,)
"SELECT baustein, gute_antworten, absolviert, verstanden FROM baustein_progress WHERE topic = ?", (topic,)
)
rows = await cursor.fetchall()
return [{"baustein": b, "gute_antworten": n, "absolviert": a} for b, n, a in rows]
return [{"baustein": b, "gute_antworten": n, "absolviert": a, "verstanden": v} for b, n, a, v in rows]
async def add_gute_antwort(topic: str, baustein: str) -> int:
"""Zählt eine gut bewertete Antwort und liefert den neuen Stand."""
async def set_baustein_score(topic: str, baustein: str, score: int) -> int:
"""Setzt den Score absolut (vom Aufrufer geclampt) und liefert ihn zurück."""
db = await get_db()
await db.execute(
"""INSERT INTO baustein_progress (topic, baustein, gute_antworten, updated_at)
VALUES (?, ?, 1, ?)
VALUES (?, ?, ?, ?)
ON CONFLICT(topic, baustein) DO UPDATE SET
gute_antworten = gute_antworten + 1, updated_at = excluded.updated_at""",
(topic, baustein, _now()),
gute_antworten = excluded.gute_antworten, updated_at = excluded.updated_at""",
(topic, baustein, score, _now()),
)
await db.commit()
cursor = await db.execute(
"SELECT gute_antworten FROM baustein_progress WHERE topic = ? AND baustein = ?",
(topic, baustein),
return score
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()
now = _now()
await db.execute(
"INSERT OR IGNORE INTO baustein_progress (topic, baustein, gute_antworten, updated_at) VALUES (?, ?, 0, ?)",
(topic, baustein, now),
)
row = await cursor.fetchone()
return row[0] if row else 0
cursor = await db.execute(
"UPDATE baustein_progress SET verstanden = ?, updated_at = ? "
"WHERE topic = ? AND baustein = ? AND verstanden IS NULL",
(now, now, topic, baustein),
)
await db.commit()
return cursor.rowcount > 0
async def set_baustein_absolviert(topic: str, baustein: str) -> bool: