update
This commit is contained in:
@@ -10,6 +10,7 @@ Report: storage/qa/<topic>/guide-<ts>.json + Konsolen-Digest.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
@@ -20,8 +21,6 @@ import readability
|
||||
from fsutil import atomic_write_json
|
||||
from textkit import _norm_title
|
||||
|
||||
from config import GUIDE_LAENGE_MAX as LAENGE_MAX, GUIDE_LAENGE_MIN as LAENGE_MIN
|
||||
|
||||
JACCARD_ABSATZ = 0.6 # Wort-Jaccard, ab dem zwei Absätze als Doppel gelten
|
||||
ABSATZ_MIN_CHARS = 200 # kürzere Absätze sind Übergänge — kein Dubletten-Signal
|
||||
LLM_SECTION_CHARS = 2500 # Section-Auszug je Judge-Item
|
||||
@@ -71,13 +70,40 @@ def ziel_ohne_anker(cards: list[dict], ziele: list[dict]) -> list[str]:
|
||||
return out
|
||||
|
||||
|
||||
def laengen_ausreisser(cards: list[dict], subs_rel: dict[str, set]) -> list[dict]:
|
||||
# Längenbudget je Sub aus der Inventar-Substanz — ersetzt den festen Rahmen 150–1200/Sub:
|
||||
# ein dichter Sub (viele key_points, Fakten, Beispiel) trägt mehr Text als ein Einzeiler.
|
||||
# Die Pipeline (Writer-Vorgabe, Prüfer-Trigger, Fix-Ziel) nutzt DIESELBE Formel mit engerem
|
||||
# Band — Messlatte und Fix-Auftrag müssen übereinstimmen, sonst sind Befunde unfixbar.
|
||||
BUDGET_BASIS = 200 # Einstieg/Übergang je Sub
|
||||
BUDGET_KEY_POINT = 160 # ~1–2 Sätze Erklärung je key_point
|
||||
BUDGET_FAKT = 60 # zitierter Fakt, in den Text eingewoben
|
||||
BUDGET_BEISPIEL = 250 # ausgearbeitetes Beispiel
|
||||
LAENGE_BAND = (0.35, 1.5) # QA-Toleranz um das Blockbudget
|
||||
|
||||
|
||||
def sub_budget(facts: dict) -> int:
|
||||
"""Zeichenbudget für den ausführlich-Teil EINES Subs (facts = Inventar-JSON des Subs)."""
|
||||
kp = len(facts.get("key_points") or [])
|
||||
cf = len(facts.get("cited_facts") or [])
|
||||
ex = 1 if str(facts.get("example_idea") or "").strip() else 0
|
||||
return BUDGET_BASIS + BUDGET_KEY_POINT * kp + BUDGET_FAKT * cf + BUDGET_BEISPIEL * ex
|
||||
|
||||
|
||||
def block_budget(subs: list[dict]) -> int:
|
||||
"""Budget einer Section: Summe über die relevanten Subs ({relevance, facts}-Dicts)."""
|
||||
return max(BUDGET_BASIS, sum(sub_budget(s.get("facts") or {}) for s in subs
|
||||
if s.get("relevance") != "peripheral"))
|
||||
|
||||
|
||||
def laengen_ausreisser(cards: list[dict], budget_by_norm: dict[str, int]) -> list[dict]:
|
||||
out = []
|
||||
for c in cards:
|
||||
n = max(len(subs_rel.get(c["block_norm"], set())), 1)
|
||||
pro_sub = len(_ausfuehrlich(c["md"])) / n
|
||||
if not (LAENGE_MIN <= pro_sub <= LAENGE_MAX):
|
||||
out.append({"block": c["block"], "zeichen_pro_sub": round(pro_sub)})
|
||||
budget = budget_by_norm.get(c["block_norm"])
|
||||
if not budget:
|
||||
continue
|
||||
zeichen = len(_ausfuehrlich(c["md"]))
|
||||
if not (LAENGE_BAND[0] * budget <= zeichen <= LAENGE_BAND[1] * budget):
|
||||
out.append({"block": c["block"], "zeichen": zeichen, "budget": budget})
|
||||
return out
|
||||
|
||||
|
||||
@@ -148,14 +174,23 @@ async def guide_qa_report(topic: str, llm: bool = False) -> dict | None:
|
||||
print(f"Keine Guide-Karten für '{topic}' — Guide noch nicht gebaut?")
|
||||
return None
|
||||
subs_rel: dict[str, set] = {}
|
||||
subs_by_norm: dict[str, list[dict]] = {}
|
||||
for r in await db.list_subblocks(topic):
|
||||
if r["status"] == "consensus" and r["relevance"] != "peripheral":
|
||||
if r["status"] != "consensus":
|
||||
continue
|
||||
try:
|
||||
facts = json.loads(r["facts"]) if r["facts"] else {}
|
||||
except (ValueError, TypeError):
|
||||
facts = {}
|
||||
subs_by_norm.setdefault(r["block_norm"], []).append(
|
||||
{"relevance": r["relevance"], "facts": facts if isinstance(facts, dict) else {}})
|
||||
if r["relevance"] != "peripheral":
|
||||
subs_rel.setdefault(r["block_norm"], set()).add(r["sub_norm"])
|
||||
ziele = [dict(r) for r in await db.list_lernziele(topic)]
|
||||
|
||||
mf = marker_fehlend(cards, subs_rel)
|
||||
za = ziel_ohne_anker(cards, ziele)
|
||||
la = laengen_ausreisser(cards, subs_rel)
|
||||
la = laengen_ausreisser(cards, {n: block_budget(s) for n, s in subs_by_norm.items()})
|
||||
rd = redundanz(cards)
|
||||
lb = lesbarkeit(cards)
|
||||
falsch = await _fachlich_falsch(topic, cards) if llm else None
|
||||
|
||||
Reference in New Issue
Block a user