[split-required] Split final 43 files (500-668 LOC) to complete refactoring
klausur-service (11 files): - cv_gutter_repair, ocr_pipeline_regression, upload_api - ocr_pipeline_sessions, smart_spell, nru_worksheet_generator - ocr_pipeline_overlays, mail/aggregator, zeugnis_api - cv_syllable_detect, self_rag backend-lehrer (17 files): - classroom_engine/suggestions, generators/quiz_generator - worksheets_api, llm_gateway/comparison, state_engine_api - classroom/models (→ 4 submodules), services/file_processor - alerts_agent/api/wizard+digests+routes, content_generators/pdf - classroom/routes/sessions, llm_gateway/inference - classroom_engine/analytics, auth/keycloak_auth - alerts_agent/processing/rule_engine, ai_processor/print_versions agent-core (5 files): - brain/memory_store, brain/knowledge_graph, brain/context_manager - orchestrator/supervisor, sessions/session_manager admin-lehrer (5 components): - GridOverlay, StepGridReview, DevOpsPipelineSidebar - DataFlowDiagram, sbom/wizard/page website (2 files): - DependencyMap, lehrer/abitur-archiv Other: nibis_ingestion, grid_detection_service, export-doclayout-onnx Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,252 +12,9 @@ Structure:
|
||||
6. Reflection Questions
|
||||
"""
|
||||
|
||||
import io
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Optional, Union
|
||||
|
||||
# Note: In production, use reportlab or weasyprint for actual PDF generation
|
||||
# This module generates an intermediate format that can be converted to PDF
|
||||
|
||||
|
||||
@dataclass
|
||||
class WorksheetSection:
|
||||
"""A section of the worksheet"""
|
||||
title: str
|
||||
content_type: str # "text", "table", "exercises", "blanks"
|
||||
content: Any
|
||||
difficulty: int = 1 # 1-4
|
||||
|
||||
|
||||
@dataclass
|
||||
class Worksheet:
|
||||
"""Complete worksheet structure"""
|
||||
title: str
|
||||
subtitle: str
|
||||
unit_id: str
|
||||
locale: str
|
||||
sections: list[WorksheetSection]
|
||||
footer: str = ""
|
||||
|
||||
def to_html(self) -> str:
|
||||
"""Convert worksheet to HTML (for PDF conversion via weasyprint)"""
|
||||
html_parts = [
|
||||
"<!DOCTYPE html>",
|
||||
"<html lang='de'>",
|
||||
"<head>",
|
||||
"<meta charset='UTF-8'>",
|
||||
"<style>",
|
||||
self._get_styles(),
|
||||
"</style>",
|
||||
"</head>",
|
||||
"<body>",
|
||||
f"<header><h1>{self.title}</h1>",
|
||||
f"<p class='subtitle'>{self.subtitle}</p></header>",
|
||||
]
|
||||
|
||||
for section in self.sections:
|
||||
html_parts.append(self._render_section(section))
|
||||
|
||||
html_parts.extend([
|
||||
f"<footer>{self.footer}</footer>",
|
||||
"</body>",
|
||||
"</html>"
|
||||
])
|
||||
|
||||
return "\n".join(html_parts)
|
||||
|
||||
def _get_styles(self) -> str:
|
||||
return """
|
||||
@page {
|
||||
size: A4;
|
||||
margin: 2cm;
|
||||
}
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
font-size: 11pt;
|
||||
line-height: 1.5;
|
||||
color: #333;
|
||||
}
|
||||
header {
|
||||
text-align: center;
|
||||
margin-bottom: 1.5em;
|
||||
border-bottom: 2px solid #2c5282;
|
||||
padding-bottom: 1em;
|
||||
}
|
||||
h1 {
|
||||
color: #2c5282;
|
||||
margin-bottom: 0.25em;
|
||||
font-size: 20pt;
|
||||
}
|
||||
.subtitle {
|
||||
color: #666;
|
||||
font-style: italic;
|
||||
}
|
||||
h2 {
|
||||
color: #2c5282;
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
padding-bottom: 0.25em;
|
||||
margin-top: 1.5em;
|
||||
font-size: 14pt;
|
||||
}
|
||||
h3 {
|
||||
color: #4a5568;
|
||||
font-size: 12pt;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 1em 0;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #e2e8f0;
|
||||
padding: 0.5em;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #edf2f7;
|
||||
font-weight: bold;
|
||||
}
|
||||
.exercise {
|
||||
margin: 1em 0;
|
||||
padding: 1em;
|
||||
background-color: #f7fafc;
|
||||
border-left: 4px solid #4299e1;
|
||||
}
|
||||
.exercise-number {
|
||||
font-weight: bold;
|
||||
color: #2c5282;
|
||||
}
|
||||
.blank {
|
||||
display: inline-block;
|
||||
min-width: 100px;
|
||||
border-bottom: 1px solid #333;
|
||||
margin: 0 0.25em;
|
||||
}
|
||||
.difficulty {
|
||||
font-size: 9pt;
|
||||
color: #718096;
|
||||
}
|
||||
.difficulty-1 { color: #48bb78; }
|
||||
.difficulty-2 { color: #4299e1; }
|
||||
.difficulty-3 { color: #ed8936; }
|
||||
.difficulty-4 { color: #f56565; }
|
||||
.reflection {
|
||||
margin-top: 2em;
|
||||
padding: 1em;
|
||||
background-color: #fffaf0;
|
||||
border: 1px dashed #ed8936;
|
||||
}
|
||||
.write-area {
|
||||
min-height: 80px;
|
||||
border: 1px solid #e2e8f0;
|
||||
margin: 0.5em 0;
|
||||
background-color: #fff;
|
||||
}
|
||||
footer {
|
||||
margin-top: 2em;
|
||||
padding-top: 1em;
|
||||
border-top: 1px solid #e2e8f0;
|
||||
font-size: 9pt;
|
||||
color: #718096;
|
||||
text-align: center;
|
||||
}
|
||||
ul, ol {
|
||||
margin: 0.5em 0;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
.objectives {
|
||||
background-color: #ebf8ff;
|
||||
padding: 1em;
|
||||
border-radius: 4px;
|
||||
}
|
||||
"""
|
||||
|
||||
def _render_section(self, section: WorksheetSection) -> str:
|
||||
parts = [f"<section><h2>{section.title}</h2>"]
|
||||
|
||||
if section.content_type == "text":
|
||||
parts.append(f"<p>{section.content}</p>")
|
||||
|
||||
elif section.content_type == "objectives":
|
||||
parts.append("<div class='objectives'><ul>")
|
||||
for obj in section.content:
|
||||
parts.append(f"<li>{obj}</li>")
|
||||
parts.append("</ul></div>")
|
||||
|
||||
elif section.content_type == "table":
|
||||
parts.append("<table><thead><tr>")
|
||||
for header in section.content.get("headers", []):
|
||||
parts.append(f"<th>{header}</th>")
|
||||
parts.append("</tr></thead><tbody>")
|
||||
for row in section.content.get("rows", []):
|
||||
parts.append("<tr>")
|
||||
for cell in row:
|
||||
parts.append(f"<td>{cell}</td>")
|
||||
parts.append("</tr>")
|
||||
parts.append("</tbody></table>")
|
||||
|
||||
elif section.content_type == "exercises":
|
||||
for i, ex in enumerate(section.content, 1):
|
||||
diff_class = f"difficulty-{ex.get('difficulty', 1)}"
|
||||
diff_stars = "*" * ex.get("difficulty", 1)
|
||||
parts.append(f"""
|
||||
<div class='exercise'>
|
||||
<span class='exercise-number'>Aufgabe {i}</span>
|
||||
<span class='difficulty {diff_class}'>({diff_stars})</span>
|
||||
<p>{ex.get('question', '')}</p>
|
||||
{self._render_exercise_input(ex)}
|
||||
</div>
|
||||
""")
|
||||
|
||||
elif section.content_type == "blanks":
|
||||
text = section.content
|
||||
# Replace *word* with blank
|
||||
import re
|
||||
text = re.sub(r'\*([^*]+)\*', r"<span class='blank'></span>", text)
|
||||
parts.append(f"<p>{text}</p>")
|
||||
|
||||
elif section.content_type == "reflection":
|
||||
parts.append("<div class='reflection'>")
|
||||
parts.append(f"<p><strong>{section.content.get('prompt', '')}</strong></p>")
|
||||
parts.append("<div class='write-area'></div>")
|
||||
parts.append("</div>")
|
||||
|
||||
parts.append("</section>")
|
||||
return "\n".join(parts)
|
||||
|
||||
def _render_exercise_input(self, exercise: dict) -> str:
|
||||
ex_type = exercise.get("type", "text")
|
||||
|
||||
if ex_type == "multiple_choice":
|
||||
options = exercise.get("options", [])
|
||||
parts = ["<ul style='list-style-type: none;'>"]
|
||||
for opt in options:
|
||||
parts.append(f"<li>□ {opt}</li>")
|
||||
parts.append("</ul>")
|
||||
return "\n".join(parts)
|
||||
|
||||
elif ex_type == "matching":
|
||||
left = exercise.get("left", [])
|
||||
right = exercise.get("right", [])
|
||||
parts = ["<table><tr><th>Begriff</th><th>Zuordnung</th></tr>"]
|
||||
for i, item in enumerate(left):
|
||||
right_item = right[i] if i < len(right) else ""
|
||||
parts.append(f"<tr><td>{item}</td><td class='blank' style='width:200px'></td></tr>")
|
||||
parts.append("</table>")
|
||||
return "\n".join(parts)
|
||||
|
||||
elif ex_type == "sequence":
|
||||
items = exercise.get("items", [])
|
||||
parts = ["<p>Bringe in die richtige Reihenfolge:</p><ol>"]
|
||||
for item in items:
|
||||
parts.append(f"<li class='blank' style='min-width:200px'></li>")
|
||||
parts.append("</ol>")
|
||||
parts.append(f"<p style='font-size:9pt;color:#718096'>Begriffe: {', '.join(items)}</p>")
|
||||
return "\n".join(parts)
|
||||
|
||||
else:
|
||||
return "<div class='write-area'></div>"
|
||||
from .worksheet_models import Worksheet, WorksheetSection
|
||||
|
||||
|
||||
class PDFGenerator:
|
||||
@@ -267,15 +24,7 @@ class PDFGenerator:
|
||||
self.locale = locale
|
||||
|
||||
def generate_from_unit(self, unit: dict) -> Worksheet:
|
||||
"""
|
||||
Generate a worksheet from a unit definition.
|
||||
|
||||
Args:
|
||||
unit: Unit definition dictionary
|
||||
|
||||
Returns:
|
||||
Worksheet object
|
||||
"""
|
||||
"""Generate a worksheet from a unit definition."""
|
||||
unit_id = unit.get("unit_id", "unknown")
|
||||
title = self._get_localized(unit.get("title"), "Arbeitsblatt")
|
||||
objectives = unit.get("learning_objectives", [])
|
||||
@@ -283,51 +32,36 @@ class PDFGenerator:
|
||||
|
||||
sections = []
|
||||
|
||||
# Learning Objectives
|
||||
if objectives:
|
||||
sections.append(WorksheetSection(
|
||||
title="Lernziele",
|
||||
content_type="objectives",
|
||||
content=objectives
|
||||
title="Lernziele", content_type="objectives", content=objectives
|
||||
))
|
||||
|
||||
# Vocabulary Table
|
||||
vocab_section = self._create_vocabulary_section(stops)
|
||||
if vocab_section:
|
||||
sections.append(vocab_section)
|
||||
|
||||
# Key Concepts Summary
|
||||
concepts_section = self._create_concepts_section(stops)
|
||||
if concepts_section:
|
||||
sections.append(concepts_section)
|
||||
|
||||
# Basic Exercises
|
||||
basic_exercises = self._create_basic_exercises(stops)
|
||||
if basic_exercises:
|
||||
sections.append(WorksheetSection(
|
||||
title="Ubungen - Basis",
|
||||
content_type="exercises",
|
||||
content=basic_exercises,
|
||||
difficulty=1
|
||||
title="Ubungen - Basis", content_type="exercises",
|
||||
content=basic_exercises, difficulty=1
|
||||
))
|
||||
|
||||
# Challenge Exercises
|
||||
challenge_exercises = self._create_challenge_exercises(stops, unit)
|
||||
if challenge_exercises:
|
||||
sections.append(WorksheetSection(
|
||||
title="Ubungen - Herausforderung",
|
||||
content_type="exercises",
|
||||
content=challenge_exercises,
|
||||
difficulty=3
|
||||
title="Ubungen - Herausforderung", content_type="exercises",
|
||||
content=challenge_exercises, difficulty=3
|
||||
))
|
||||
|
||||
# Reflection
|
||||
sections.append(WorksheetSection(
|
||||
title="Reflexion",
|
||||
content_type="reflection",
|
||||
content={
|
||||
"prompt": "Erklaere in eigenen Worten, was du heute gelernt hast:"
|
||||
}
|
||||
title="Reflexion", content_type="reflection",
|
||||
content={"prompt": "Erklaere in eigenen Worten, was du heute gelernt hast:"}
|
||||
))
|
||||
|
||||
return Worksheet(
|
||||
@@ -370,12 +104,8 @@ class PDFGenerator:
|
||||
return None
|
||||
|
||||
return WorksheetSection(
|
||||
title="Wichtige Begriffe",
|
||||
content_type="table",
|
||||
content={
|
||||
"headers": ["Begriff", "Erklarung"],
|
||||
"rows": rows
|
||||
}
|
||||
title="Wichtige Begriffe", content_type="table",
|
||||
content={"headers": ["Begriff", "Erklarung"], "rows": rows}
|
||||
)
|
||||
|
||||
def _create_concepts_section(self, stops: list) -> Optional[WorksheetSection]:
|
||||
@@ -392,19 +122,14 @@ class PDFGenerator:
|
||||
return None
|
||||
|
||||
return WorksheetSection(
|
||||
title="Zusammenfassung",
|
||||
content_type="table",
|
||||
content={
|
||||
"headers": ["Station", "Was hast du gelernt?"],
|
||||
"rows": rows
|
||||
}
|
||||
title="Zusammenfassung", content_type="table",
|
||||
content={"headers": ["Station", "Was hast du gelernt?"], "rows": rows}
|
||||
)
|
||||
|
||||
def _create_basic_exercises(self, stops: list) -> list[dict]:
|
||||
"""Create basic difficulty exercises"""
|
||||
exercises = []
|
||||
|
||||
# Vocabulary matching
|
||||
vocab_items = []
|
||||
for stop in stops:
|
||||
for v in stop.get("vocab", []):
|
||||
@@ -422,7 +147,6 @@ class PDFGenerator:
|
||||
"difficulty": 1
|
||||
})
|
||||
|
||||
# True/False from concepts
|
||||
for stop in stops[:3]:
|
||||
concept = stop.get("concept", {})
|
||||
why = self._get_localized(concept.get("why"))
|
||||
@@ -435,7 +159,6 @@ class PDFGenerator:
|
||||
})
|
||||
break
|
||||
|
||||
# Sequence ordering (for FlightPath)
|
||||
if len(stops) >= 4:
|
||||
labels = [self._get_localized(s.get("label")) for s in stops[:6] if self._get_localized(s.get("label"))]
|
||||
if len(labels) >= 4:
|
||||
@@ -455,7 +178,6 @@ class PDFGenerator:
|
||||
"""Create challenging exercises"""
|
||||
exercises = []
|
||||
|
||||
# Misconception identification
|
||||
for stop in stops:
|
||||
concept = stop.get("concept", {})
|
||||
misconception = self._get_localized(concept.get("common_misconception"))
|
||||
@@ -472,14 +194,12 @@ class PDFGenerator:
|
||||
if len(exercises) >= 2:
|
||||
break
|
||||
|
||||
# Transfer/Application question
|
||||
exercises.append({
|
||||
"type": "text",
|
||||
"question": "Erklaere einem Freund in 2-3 Satzen, was du gelernt hast:",
|
||||
"difficulty": 3
|
||||
})
|
||||
|
||||
# Critical thinking
|
||||
exercises.append({
|
||||
"type": "text",
|
||||
"question": "Was moechtest du noch mehr uber dieses Thema erfahren?",
|
||||
@@ -490,35 +210,14 @@ class PDFGenerator:
|
||||
|
||||
|
||||
def generate_worksheet_html(unit_definition: dict, locale: str = "de-DE") -> str:
|
||||
"""
|
||||
Generate HTML worksheet from unit definition.
|
||||
|
||||
Args:
|
||||
unit_definition: The unit JSON definition
|
||||
locale: Target locale for content
|
||||
|
||||
Returns:
|
||||
HTML string ready for PDF conversion
|
||||
"""
|
||||
"""Generate HTML worksheet from unit definition."""
|
||||
generator = PDFGenerator(locale=locale)
|
||||
worksheet = generator.generate_from_unit(unit_definition)
|
||||
return worksheet.to_html()
|
||||
|
||||
|
||||
def generate_worksheet_pdf(unit_definition: dict, locale: str = "de-DE") -> bytes:
|
||||
"""
|
||||
Generate PDF worksheet from unit definition.
|
||||
|
||||
Requires weasyprint to be installed:
|
||||
pip install weasyprint
|
||||
|
||||
Args:
|
||||
unit_definition: The unit JSON definition
|
||||
locale: Target locale for content
|
||||
|
||||
Returns:
|
||||
PDF bytes
|
||||
"""
|
||||
"""Generate PDF worksheet from unit definition."""
|
||||
try:
|
||||
from weasyprint import HTML
|
||||
except ImportError:
|
||||
|
||||
Reference in New Issue
Block a user