update
This commit is contained in:
@@ -12,26 +12,29 @@ Query-Schleifen mehr pro Guide.
|
||||
|
||||
import json
|
||||
|
||||
from database import list_baustein_absolviert_all, list_guides, list_progress_all
|
||||
from database import list_baustein_levels_all, list_guides, list_progress_all
|
||||
from guide import guide_slot_dateien
|
||||
from paths import bausteine_path, guide_content_path
|
||||
from textkit import _norm_titel
|
||||
|
||||
MAX_OFFENE_GUIDES = 3
|
||||
VORSTUFE = {"Guide": "MiniGuide", "FullGuide": "Guide"}
|
||||
# Welches Niveau die Vorstufe erreichen muss, um das Format freizuschalten.
|
||||
FREISCHALT_LEVEL = {"Guide": "absolviert", "FullGuide": "verstanden"}
|
||||
FORMATE = ("MiniGuide", "Guide", "FullGuide")
|
||||
|
||||
|
||||
async def lade_lernstand() -> tuple[list[dict], dict[str, set[str]], dict[str, set[str]]]:
|
||||
"""Guides + Kapitel-Fortschritt + absolvierte Bausteine in drei Queries.
|
||||
async def lade_lernstand() -> tuple[list[dict], dict[str, set[str]], dict[str, dict[str, set[str]]]]:
|
||||
"""Guides + Kapitel-Fortschritt + Bausteine je Meilenstein.
|
||||
|
||||
bausteine_done: topic → normalisierte Titel der Bausteine mit bestandener Prüfung.
|
||||
levels: {"absolviert"/"verstanden"/"gemeistert": {topic → normalisierte Titel}}.
|
||||
"""
|
||||
bausteine_done = {
|
||||
topic: {_norm_titel(b) for b in titel}
|
||||
for topic, titel in (await list_baustein_absolviert_all()).items()
|
||||
roh = await list_baustein_levels_all()
|
||||
levels = {
|
||||
stufe: {topic: {_norm_titel(b) for b in titel} for topic, titel in pro_topic.items()}
|
||||
for stufe, pro_topic in roh.items()
|
||||
}
|
||||
return await list_guides(), await list_progress_all(), bausteine_done
|
||||
return await list_guides(), await list_progress_all(), levels
|
||||
|
||||
|
||||
def _content_json(topic: str, fmt: str) -> dict | None:
|
||||
@@ -73,31 +76,42 @@ def _neueste_done(guides: list[dict], fmt: str) -> dict[str, dict]:
|
||||
return neueste
|
||||
|
||||
|
||||
def _guide_absolviert(g: dict, progress: dict[str, set[str]], bausteine_done: dict[str, set[str]]) -> bool:
|
||||
def _guide_alle(g: dict, progress: dict[str, set[str]], levelset: dict[str, set[str]]) -> bool:
|
||||
"""Sind ALLE Bausteine (bzw. OnePager-Kapitel) des Guides auf dem geforderten Niveau?"""
|
||||
if g["format"] == "OnePager":
|
||||
titles = _kapitel_titel(g["topic"], g["format"])
|
||||
return bool(titles) and titles <= progress.get(g["id"], set())
|
||||
sections = _section_titel(g["topic"], g["format"])
|
||||
return bool(sections) and sections <= bausteine_done.get(g["topic"], set())
|
||||
return bool(sections) and sections <= levelset.get(g["topic"], set())
|
||||
|
||||
|
||||
def ist_absolviert(topic: str, fmt: str, guides: list[dict], progress: dict[str, set[str]], bausteine_done: dict[str, set[str]]) -> bool:
|
||||
"""Alle Bausteine des neuesten fertigen Guides (Thema+Format) per Prüfung absolviert?"""
|
||||
def ist_level(topic: str, fmt: str, guides: list[dict], progress: dict[str, set[str]], levelset: dict[str, set[str]]) -> bool:
|
||||
"""Neuester fertiger Guide (Thema+Format): alle Bausteine auf dem Niveau von levelset?"""
|
||||
g = _neueste_done(guides, fmt).get(topic)
|
||||
return g is not None and _guide_absolviert(g, progress, bausteine_done)
|
||||
return g is not None and _guide_alle(g, progress, levelset)
|
||||
|
||||
|
||||
def formate_stats(guides: list[dict], progress: dict[str, set[str]], bausteine_done: dict[str, set[str]]) -> dict:
|
||||
def ist_absolviert(topic: str, fmt: str, guides: list[dict], progress: dict[str, set[str]], levels: dict[str, dict[str, set[str]]]) -> bool:
|
||||
"""Alle Bausteine des neuesten fertigen Guides absolviert (≥3)?"""
|
||||
return ist_level(topic, fmt, guides, progress, levels["absolviert"])
|
||||
|
||||
|
||||
def thema_abgeschlossen(topic: str, guides: list[dict], progress: dict[str, set[str]], levels: dict[str, dict[str, set[str]]]) -> bool:
|
||||
"""Thema fertig: neuester fertiger FullGuide, alle Bausteine gemeistert (25)?"""
|
||||
return ist_level(topic, "FullGuide", guides, progress, levels["gemeistert"])
|
||||
|
||||
|
||||
def formate_stats(guides: list[dict], progress: dict[str, set[str]], levels: dict[str, dict[str, set[str]]]) -> dict:
|
||||
"""Pro Format erstellt/absolviert — pro Thema zählt nur der neueste fertige Guide."""
|
||||
formate = {}
|
||||
for fmt in FORMATE:
|
||||
neueste = _neueste_done(guides, fmt)
|
||||
absolviert = sum(1 for g in neueste.values() if _guide_absolviert(g, progress, bausteine_done))
|
||||
absolviert = sum(1 for g in neueste.values() if _guide_alle(g, progress, levels["absolviert"]))
|
||||
formate[fmt] = {"erstellt": len(neueste), "absolviert": absolviert}
|
||||
return formate
|
||||
|
||||
|
||||
def guide_lock(topic: str, fmt: str, guides: list[dict], progress: dict[str, set[str]], bausteine_done: dict[str, set[str]]) -> str | None:
|
||||
def guide_lock(topic: str, fmt: str, guides: list[dict], progress: dict[str, set[str]], levels: dict[str, dict[str, set[str]]]) -> str | None:
|
||||
"""Grund, warum ein Neu-Start für Thema+Format gesperrt ist — None = erlaubt.
|
||||
|
||||
Exakt die Regeln aus POST /guides: Bausteine nötig, kein Duplikat-Start,
|
||||
@@ -111,9 +125,12 @@ def guide_lock(topic: str, fmt: str, guides: list[dict], progress: dict[str, set
|
||||
content = guide_content_path(topic, fmt)
|
||||
if fmt != "OnePager" and not content.exists() and not guide_slot_dateien(content):
|
||||
vorstufe = VORSTUFE.get(fmt)
|
||||
if vorstufe and not ist_absolviert(topic, vorstufe, guides, progress, bausteine_done):
|
||||
return f"Erst den {vorstufe} dieses Themas absolvieren (alle Bausteine prüfen)"
|
||||
stat = formate_stats(guides, progress, bausteine_done).get(fmt, {"erstellt": 0, "absolviert": 0})
|
||||
if vorstufe:
|
||||
stufe = FREISCHALT_LEVEL[fmt] # "absolviert" (alle 3) oder "verstanden" (alle 10)
|
||||
if not ist_level(topic, vorstufe, guides, progress, levels[stufe]):
|
||||
wort = "verstehen (alle Bausteine auf 10)" if stufe == "verstanden" else "absolvieren (alle Bausteine prüfen)"
|
||||
return f"Erst den {vorstufe} dieses Themas {wort}"
|
||||
stat = formate_stats(guides, progress, levels).get(fmt, {"erstellt": 0, "absolviert": 0})
|
||||
offen = stat["erstellt"] - stat["absolviert"]
|
||||
if offen >= MAX_OFFENE_GUIDES:
|
||||
return f"Erst {fmt}s absolvieren — maximal {MAX_OFFENE_GUIDES} offene erlaubt ({offen} offen)"
|
||||
|
||||
Reference in New Issue
Block a user