This commit is contained in:
team3
2026-06-23 11:12:31 +02:00
parent 8fe0e8581f
commit c07e1e9e30
3 changed files with 103 additions and 29 deletions

View File

@@ -124,12 +124,13 @@ CREATE TABLE IF NOT EXISTS frage_muster (
)
"""
# Crawl-Seiten-Abdeckung: treibt den Recherche-Loop (welche Quelle wurde zitiert?).
# Crawl-Seiten je Thema: inhalt (1=Content/0=Noise, von der Sichtung) + gelesen (von der Recherche).
CREATE_RECHERCHE_COVERAGE = """
CREATE TABLE IF NOT EXISTS recherche_coverage (
topic TEXT NOT NULL,
quelle TEXT NOT NULL,
gelesen INTEGER NOT NULL DEFAULT 0,
inhalt INTEGER,
updated_at TEXT NOT NULL,
PRIMARY KEY (topic, quelle)
)
@@ -202,6 +203,10 @@ async def init_db():
await db.execute("ALTER TABLE guides ADD COLUMN step INTEGER")
except aiosqlite.OperationalError:
pass
try: # Migration: recherche_coverage.inhalt (Content/Noise aus der Sichtung)
await db.execute("ALTER TABLE recherche_coverage ADD COLUMN inhalt 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:
@@ -739,6 +744,30 @@ async def list_coverage(topic: str) -> dict[str, int]:
return {q: g for q, g in rows}
async def mark_inhalt(topic: str, content: list[str], noise: list[str]) -> None:
"""Sichtungs-Ergebnis je Crawl-Seite ablegen: inhalt=1 (Content) bzw. 0 (Noise)."""
db = await get_db()
now = _now()
rows = [(topic, q, 1, now) for q in content] + [(topic, q, 0, now) for q in noise]
if not rows:
return
await db.executemany(
"""INSERT INTO recherche_coverage (topic, quelle, inhalt, updated_at) VALUES (?, ?, ?, ?)
ON CONFLICT(topic, quelle) DO UPDATE SET inhalt = excluded.inhalt, updated_at = excluded.updated_at""",
rows,
)
await db.commit()
async def list_content(topic: str) -> list[str]:
"""Crawl-Seiten, die die Sichtung als Content markiert hat (inhalt=1)."""
db = await get_db()
cursor = await db.execute(
"SELECT quelle FROM recherche_coverage WHERE topic = ? AND inhalt = 1 ORDER BY quelle", (topic,)
)
return [r[0] for r in await cursor.fetchall()]
async def delete_coverage(topic: str) -> None:
db = await get_db()
await db.execute("DELETE FROM recherche_coverage WHERE topic = ?", (topic,))