update
This commit is contained in:
@@ -513,20 +513,6 @@ async def set_offene_frage(topic: str, baustein: str, frage: str, basis: int, st
|
||||
await db.commit()
|
||||
|
||||
|
||||
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 (?, ?, ?, ?)
|
||||
ON CONFLICT(topic, baustein) DO UPDATE SET
|
||||
gute_antworten = excluded.gute_antworten, updated_at = excluded.updated_at""",
|
||||
(topic, baustein, score, _now()),
|
||||
)
|
||||
await db.commit()
|
||||
return score
|
||||
|
||||
|
||||
async def set_baustein_score_and_streak(topic: str, baustein: str, score: int, streak: int) -> tuple[int, int]:
|
||||
"""Setzt Score + Streak atomar (vom Aufrufer geclampt). Liefert (score, streak)."""
|
||||
db = await get_db()
|
||||
@@ -550,40 +536,6 @@ async def delete_baustein_progress(topic: str, baustein: str) -> None:
|
||||
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()
|
||||
now = _now()
|
||||
await db.execute(
|
||||
"INSERT OR IGNORE INTO baustein_progress (topic, baustein, gute_antworten, updated_at) VALUES (?, ?, 0, ?)",
|
||||
(topic, baustein, now),
|
||||
)
|
||||
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_gemeistert(topic: str, baustein: str) -> bool:
|
||||
"""Markiert gemeistert (Meisterpfad, Score 25); True nur beim ersten Mal. Sticky."""
|
||||
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),
|
||||
)
|
||||
cursor = await db.execute(
|
||||
"UPDATE baustein_progress SET gemeistert = ?, updated_at = ? "
|
||||
"WHERE topic = ? AND baustein = ? AND gemeistert IS NULL",
|
||||
(now, now, topic, baustein),
|
||||
)
|
||||
await db.commit()
|
||||
return cursor.rowcount > 0
|
||||
|
||||
|
||||
async def set_baustein_absolviert(topic: str, baustein: str) -> bool:
|
||||
"""Markiert absolviert; True nur beim ersten Mal (steuert den Element-Task)."""
|
||||
db = await get_db()
|
||||
@@ -601,39 +553,6 @@ async def set_baustein_absolviert(topic: str, baustein: str) -> bool:
|
||||
return cursor.rowcount > 0
|
||||
|
||||
|
||||
async def count_relevant_subs(topic: str, baustein: str) -> int:
|
||||
"""Anzahl relevanter Konsens-Subbausteine eines Bausteins (für den cap = 4×Subs)."""
|
||||
from textkit import _norm_titel
|
||||
db = await get_db()
|
||||
cursor = await db.execute(
|
||||
"SELECT COUNT(*) FROM subbausteine WHERE topic = ? AND baustein_norm = ? "
|
||||
"AND status = 'konsens' AND relevanz != 'rand'",
|
||||
(topic, _norm_titel(baustein)),
|
||||
)
|
||||
return (await cursor.fetchone())[0]
|
||||
|
||||
|
||||
async def subs_count_roh(topic: str) -> dict[str, int]:
|
||||
"""Relevante Konsens-Subbausteine je ROHEM Baustein-Titel (= Guide-Section-Titel) eines Themas."""
|
||||
db = await get_db()
|
||||
cursor = await db.execute(
|
||||
"SELECT baustein, COUNT(*) FROM subbausteine WHERE topic = ? "
|
||||
"AND status = 'konsens' AND relevanz != 'rand' GROUP BY baustein",
|
||||
(topic,),
|
||||
)
|
||||
return {b: n for b, n in await cursor.fetchall()}
|
||||
|
||||
|
||||
async def subs_count_alle() -> dict[tuple[str, str], int]:
|
||||
"""Relevante Konsens-Subbausteine je (topic, baustein_norm) — für die Stufen-Ableitung."""
|
||||
db = await get_db()
|
||||
cursor = await db.execute(
|
||||
"SELECT topic, baustein_norm, COUNT(*) FROM subbausteine "
|
||||
"WHERE status = 'konsens' AND relevanz != 'rand' GROUP BY topic, baustein_norm"
|
||||
)
|
||||
return {(t, bn): n for t, bn, n in await cursor.fetchall()}
|
||||
|
||||
|
||||
# Sub-Ebene aus den zwei orthogonalen Spalten: rand → 4 (V), sonst Stufe (Lernpfad-Position):
|
||||
# anfaenger/NULL → 1, fortgeschritten → 2, experte → 3. Alte Werte (einfach/mittel/schwer) werden
|
||||
# abwärtskompatibel mitgemappt. Steuert Guide-Ansicht A/F/E/V + cap (freigeschaltete Subs × 25).
|
||||
|
||||
Reference in New Issue
Block a user