ProfessorLeVesseur commited on
Commit
1ce8e69
·
verified ·
1 Parent(s): fb3ba27

Rename Report.py to report.py

Browse files
Files changed (2) hide show
  1. Report.py +0 -35
  2. report.py +46 -0
Report.py DELETED
@@ -1,35 +0,0 @@
1
- import io
2
- from reportlab.lib.pagesizes import letter
3
- from reportlab.platypus import SimpleDocTemplate, Image, Paragraph, Spacer
4
- from reportlab.lib.styles import getSampleStyleSheet
5
-
6
- def create_combined_pdf(intervention_fig, student_metrics_fig, recommendations):
7
- buffer = io.BytesIO()
8
- doc = SimpleDocTemplate(buffer, pagesize=letter)
9
- styles = getSampleStyleSheet()
10
-
11
- # Create a list to hold the PDF elements
12
- elements = []
13
-
14
- # Add the intervention statistics chart
15
- img_buffer = io.BytesIO()
16
- intervention_fig.write_image(img_buffer, format="png")
17
- img_buffer.seek(0)
18
- elements.append(Image(img_buffer, width=500, height=300))
19
- elements.append(Spacer(1, 12))
20
-
21
- # Add the student metrics chart
22
- img_buffer = io.BytesIO()
23
- student_metrics_fig.write_image(img_buffer, format="png")
24
- img_buffer.seek(0)
25
- elements.append(Image(img_buffer, width=500, height=300))
26
- elements.append(Spacer(1, 12))
27
-
28
- # Add the AI recommendations
29
- elements.append(Paragraph("AI Recommendations", styles['Heading1']))
30
- elements.append(Paragraph(recommendations, styles['BodyText']))
31
-
32
- # Build the PDF
33
- doc.build(elements)
34
- buffer.seek(0)
35
- return buffer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
report.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # report.py
2
+
3
+ import io
4
+ from reportlab.lib.pagesizes import letter
5
+ from reportlab.platypus import SimpleDocTemplate, Image, Paragraph, Spacer
6
+ from reportlab.lib.styles import getSampleStyleSheet
7
+
8
+ class ReportGenerator:
9
+ def __init__(self):
10
+ self.styles = getSampleStyleSheet()
11
+
12
+ def create_combined_pdf(self, intervention_fig, student_metrics_fig, recommendations):
13
+ buffer = io.BytesIO()
14
+ doc = SimpleDocTemplate(buffer, pagesize=letter)
15
+
16
+ elements = []
17
+
18
+ # Add the intervention statistics chart
19
+ elements.extend(self._add_chart(intervention_fig, "Intervention Statistics"))
20
+
21
+ # Add the student metrics chart
22
+ elements.extend(self._add_chart(student_metrics_fig, "Student Metrics"))
23
+
24
+ # Add the AI recommendations
25
+ elements.extend(self._add_recommendations(recommendations))
26
+
27
+ # Build the PDF
28
+ doc.build(elements)
29
+ buffer.seek(0)
30
+ return buffer
31
+
32
+ def _add_chart(self, fig, title):
33
+ elements = []
34
+ elements.append(Paragraph(title, self.styles['Heading2']))
35
+ img_buffer = io.BytesIO()
36
+ fig.write_image(img_buffer, format="png")
37
+ img_buffer.seek(0)
38
+ elements.append(Image(img_buffer, width=500, height=300))
39
+ elements.append(Spacer(1, 12))
40
+ return elements
41
+
42
+ def _add_recommendations(self, recommendations):
43
+ elements = []
44
+ elements.append(Paragraph("AI Recommendations", self.styles['Heading1']))
45
+ elements.append(Paragraph(recommendations, self.styles['BodyText']))
46
+ return elements