This commit is contained in:
team3
2026-07-13 06:07:09 +02:00
parent 8926f87185
commit 32d7ad9ea1
15 changed files with 552 additions and 115 deletions

View File

@@ -39,6 +39,8 @@ def export(topic: str) -> dict:
" JOIN atome a ON a.id=ar.atom_id WHERE a.topic=?", (topic,)),
"sections": q("SELECT s.* FROM sections s JOIN bausteine b ON b.id=s.baustein_id"
" WHERE b.topic=?", (topic,)),
"auftraege": q("SELECT au.* FROM auftraege au JOIN bausteine b"
" ON b.id=au.baustein_id WHERE b.topic=?", (topic,)),
"runs": q("SELECT * FROM runs WHERE topic=? ORDER BY id", (topic,)),
"befunde": q("SELECT b.* FROM befunde b JOIN runs r ON r.id=b.run_id"
" WHERE r.topic=?", (topic,)),
@@ -143,12 +145,24 @@ def importieren(d: dict) -> None:
if z.get(feld):
z[feld] = re.sub(r"<!--\s*atom:\s*(\d+)\s*\|", marker_remap, z[feld])
z[feld] = re.sub(r"<!--\s*beispiel:\s*(\d+)\s*-->", beispiel_remap, z[feld])
# offene Fix-Aufträge nennen Atom-IDs im Klartext („Marker für Atom 123
# fehlt") — mitremappen, sonst fixt der Prüfer gegen tote IDs
if z.get("befunde"):
z["befunde"] = db.j([re.sub(r"(Atom |Marker )(\d+)", auftrag_remap, str(a))
for a in db.uj(z["befunde"])])
# Alt-Exporte tragen Freitext-Aufträge in der (gedroppten) befunde-Spalte —
# KRITISCH-Arten in auftraege-Zeilen wandeln, Rest verwerfen (wie Migration)
for alt in db.uj(z.pop("befunde", None) or "[]"):
p = db.alt_auftrag(re.sub(r"(Atom |Marker )(\d+)", auftrag_remap, str(alt)))
if p and z["baustein_id"] is not None:
db.insert("auftraege", baustein_id=z["baustein_id"],
art=p[0], detail=p[1], quelle=p[2])
db.insert("sections", **z)
# Aufträge nennen Atom-IDs im Klartext („Atom 123") — mitremappen, sonst
# urteilt der Prüfer gegen tote IDs
for z in d.get("auftraege", []):
z = dict(z)
z.pop("id", None)
z["baustein_id"] = b_map.get(z["baustein_id"])
if z["baustein_id"] is None:
continue
z["detail"] = re.sub(r"(Atom |Marker )(\d+)", auftrag_remap, z["detail"])
db.insert("auftraege", **z)
r_map = _einfuegen("runs", d["runs"])
_einfuegen("befunde", d["befunde"], run_id=r_map)
e_map = _einfuegen("events", d["events"], run_id=r_map)