Sina Media Lab
commited on
Commit
·
8aa4295
1
Parent(s):
e79a4a1
Updates
Browse files
app.py
CHANGED
|
@@ -35,49 +35,64 @@ def reset_pdf_cache():
|
|
| 35 |
def generate_pdf_report():
|
| 36 |
pdf = FPDF()
|
| 37 |
pdf.add_page()
|
| 38 |
-
pdf.set_font("Arial", size=
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
pdf.ln(10)
|
| 42 |
|
| 43 |
-
for
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
pdf.
|
| 47 |
-
pdf.ln
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
pdf.ln(5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
pdf.set_text_color(0, 0, 0) # Default color for others
|
| 71 |
-
pdf.multi_cell(0, 10, f" {option}")
|
| 72 |
-
pdf.set_text_color(0, 0, 0) # Reset color
|
| 73 |
-
pdf.multi_cell(0, 10, f"Explanation: {explanation}")
|
| 74 |
-
pdf.ln(5)
|
| 75 |
-
pdf.multi_cell(0, 10, "Step-by-Step Solution:")
|
| 76 |
-
for step in step_by_step_solution:
|
| 77 |
-
pdf.multi_cell(0, 10, step)
|
| 78 |
-
pdf.ln(10)
|
| 79 |
-
|
| 80 |
-
pdf.ln(10) # Add space after each module
|
| 81 |
|
| 82 |
return pdf.output(dest='S').encode('latin1', 'replace')
|
| 83 |
|
|
|
|
| 35 |
def generate_pdf_report():
|
| 36 |
pdf = FPDF()
|
| 37 |
pdf.add_page()
|
| 38 |
+
pdf.set_font("Arial", style='B', size=14)
|
| 39 |
|
| 40 |
+
# Title of the report
|
| 41 |
+
pdf.cell(0, 10, txt="Magic Math Quiz", ln=True, align="C")
|
| 42 |
+
pdf.set_font("Arial", size=10)
|
| 43 |
+
pdf.cell(0, 10, txt="by Ghassem Tofighi", ln=True, align="C", link="https://ghassem.com")
|
| 44 |
pdf.ln(10)
|
| 45 |
|
| 46 |
+
for i, entry in enumerate(st.session_state.questions):
|
| 47 |
+
pdf.set_fill_color(0, 0, 0) # Black background
|
| 48 |
+
pdf.set_text_color(255, 255, 255) # White text
|
| 49 |
+
pdf.set_font("Arial", style='B', size=12)
|
| 50 |
+
pdf.cell(0, 10, f"Category: {entry['category']} > Module: {entry['module_title']}", ln=True, align="L", fill=True)
|
| 51 |
+
|
| 52 |
+
pdf.set_text_color(0, 0, 0) # Reset text color to black
|
| 53 |
+
pdf.set_font("Arial", size=12)
|
| 54 |
pdf.ln(5)
|
| 55 |
+
|
| 56 |
+
# Question number and text
|
| 57 |
+
pdf.set_font("Arial", style='B', size=12)
|
| 58 |
+
pdf.multi_cell(0, 10, f"Q{i+1}: {entry['question']}")
|
| 59 |
+
pdf.ln(3)
|
| 60 |
+
|
| 61 |
+
# Time taken
|
| 62 |
+
pdf.set_font("Arial", size=10)
|
| 63 |
+
pdf.multi_cell(0, 10, f"Time Taken: {entry['time_taken']} seconds")
|
| 64 |
+
pdf.ln(3)
|
| 65 |
+
|
| 66 |
+
# Options and correct/incorrect answer
|
| 67 |
+
pdf.set_font("Arial", size=10)
|
| 68 |
+
options = ['a', 'b', 'c', 'd']
|
| 69 |
+
for j, option in enumerate(entry['options']):
|
| 70 |
+
if option == entry['correct_answer']:
|
| 71 |
+
pdf.set_text_color(0, 128, 0) # Green for correct
|
| 72 |
+
elif option == entry['selected']:
|
| 73 |
+
pdf.set_text_color(255, 0, 0) # Red for incorrect
|
| 74 |
+
else:
|
| 75 |
+
pdf.set_text_color(0, 0, 0) # Default color
|
| 76 |
|
| 77 |
+
pdf.multi_cell(0, 10, f"{options[j]}. {option}")
|
| 78 |
+
|
| 79 |
+
pdf.set_text_color(0, 0, 0) # Reset color
|
| 80 |
+
pdf.ln(5)
|
| 81 |
+
|
| 82 |
+
# Explanation and Step-by-Step Solution
|
| 83 |
+
pdf.set_font("Arial", style='B', size=10)
|
| 84 |
+
pdf.multi_cell(0, 10, "Explanation:")
|
| 85 |
+
pdf.set_font("Arial", size=10)
|
| 86 |
+
pdf.multi_cell(0, 10, entry['explanation'])
|
| 87 |
+
pdf.ln(3)
|
| 88 |
+
|
| 89 |
+
pdf.set_font("Arial", style='B', size=10)
|
| 90 |
+
pdf.multi_cell(0, 10, "Step-by-Step Solution:")
|
| 91 |
+
pdf.set_font("Arial", size=10)
|
| 92 |
+
for step in entry['step_by_step_solution']:
|
| 93 |
+
pdf.multi_cell(0, 10, step)
|
| 94 |
+
|
| 95 |
+
pdf.ln(10) # Add space after each question
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
return pdf.output(dest='S').encode('latin1', 'replace')
|
| 98 |
|