# report.py import io from reportlab.lib.pagesizes import letter from reportlab.platypus import SimpleDocTemplate, Image, Paragraph, Spacer from reportlab.lib.styles import getSampleStyleSheet class ReportGenerator: def __init__(self): self.styles = getSampleStyleSheet() def create_combined_pdf(self, intervention_fig, student_metrics_fig, recommendations): buffer = io.BytesIO() doc = SimpleDocTemplate(buffer, pagesize=letter) elements = [] # Add the intervention statistics chart elements.extend(self._add_chart(intervention_fig, "Intervention Statistics")) # Add the student metrics chart elements.extend(self._add_chart(student_metrics_fig, "Student Metrics")) # Add the AI recommendations elements.extend(self._add_recommendations(recommendations)) # Build the PDF doc.build(elements) buffer.seek(0) return buffer def _add_chart(self, fig, title): elements = [] elements.append(Paragraph(title, self.styles['Heading2'])) img_buffer = io.BytesIO() fig.write_image(img_buffer, format="png") img_buffer.seek(0) elements.append(Image(img_buffer, width=500, height=300)) elements.append(Spacer(1, 12)) return elements def _add_recommendations(self, recommendations): elements = [] elements.append(Paragraph("AI Recommendations", self.styles['Heading1'])) elements.append(Paragraph(recommendations, self.styles['BodyText'])) return elements