Sina Media Lab
commited on
Commit
·
a58f65d
1
Parent(s):
7f3aa91
Updates
Browse files
app.py
CHANGED
|
@@ -35,55 +35,51 @@ def reset_pdf_cache():
|
|
| 35 |
def generate_pdf_report():
|
| 36 |
pdf = FPDF()
|
| 37 |
pdf.add_page()
|
| 38 |
-
pdf.set_font("Arial",
|
| 39 |
|
| 40 |
-
|
| 41 |
-
pdf.set_fill_color(255, 255, 255) # White background
|
| 42 |
-
pdf.set_text_color(0, 0, 0) # Black text
|
| 43 |
-
pdf.cell(0, 10, txt="Magic Math Quiz!", ln=True, align="C", fill=True)
|
| 44 |
-
pdf.ln(5)
|
| 45 |
-
pdf.set_font("Arial", size=8)
|
| 46 |
-
pdf.cell(0, 10, txt="By Ghassem Tofighi", ln=True, align="C", link="https://ghassem.com")
|
| 47 |
pdf.ln(10)
|
| 48 |
|
| 49 |
-
for
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
# Module Title
|
| 57 |
-
pdf.set_font("Arial", style='B', size=10)
|
| 58 |
-
pdf.multi_cell(0, 8, f"Module: {entry['module_title']}", border=1, fill=True)
|
| 59 |
-
|
| 60 |
-
# Question
|
| 61 |
-
pdf.set_font("Arial", style='B', size=10)
|
| 62 |
-
pdf.multi_cell(0, 8, f"Q{i+1}: {entry['question']}", border=1, fill=True)
|
| 63 |
-
|
| 64 |
-
# Time Taken
|
| 65 |
-
pdf.set_font("Arial", size=10)
|
| 66 |
-
pdf.multi_cell(0, 8, f"Time Taken: {entry['time_taken']} seconds", border=1, fill=True)
|
| 67 |
-
|
| 68 |
-
# Options
|
| 69 |
-
pdf.set_font("Arial", size=10)
|
| 70 |
-
options = ['a', 'b', 'c', 'd']
|
| 71 |
-
for j, option in enumerate(entry['options']):
|
| 72 |
-
if option == entry['correct_answer']:
|
| 73 |
-
pdf.set_text_color(0, 128, 0) # Green for correct
|
| 74 |
-
elif option == entry['selected']:
|
| 75 |
-
pdf.set_text_color(255, 0, 0) # Red for incorrect
|
| 76 |
-
else:
|
| 77 |
-
pdf.set_text_color(0, 0, 0) # Default color for others
|
| 78 |
-
|
| 79 |
-
pdf.multi_cell(0, 6, f"{options[j]}. {option}", border=1, fill=True) # Reduced vertical spacing
|
| 80 |
-
|
| 81 |
-
pdf.set_text_color(0, 0, 0) # Reset color
|
| 82 |
-
pdf.multi_cell(0, 6, f"Explanation: {entry['explanation']}", border=1, fill=True) # Reduced vertical spacing
|
| 83 |
-
pdf.multi_cell(0, 6, f"Step-by-Step Solution: {', '.join(entry['step_by_step_solution'])}", border=1, fill=True) # Reduced vertical spacing
|
| 84 |
pdf.ln(5)
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
def load_modules():
|
| 89 |
modules = {}
|
|
@@ -157,6 +153,7 @@ if selected_category:
|
|
| 157 |
f"""
|
| 158 |
<div style="background-color: #333; padding: 10px; border-radius: 5px; margin-top: 20px;">
|
| 159 |
<span style='font-size: 18px; color: white;'>{selected_category} > {selected_module_data['title']}</span>
|
|
|
|
| 160 |
""",
|
| 161 |
unsafe_allow_html=True
|
| 162 |
)
|
|
@@ -165,7 +162,6 @@ if selected_category:
|
|
| 165 |
st.markdown(
|
| 166 |
f"""
|
| 167 |
<a href='#' download='quiz_report.pdf' style='font-size: 18px; margin-left: 10px; color: white;' onclick='document.getElementById("pdf-link").click();'>📄 Download PDF Report</a>
|
| 168 |
-
</div>
|
| 169 |
""",
|
| 170 |
unsafe_allow_html=True
|
| 171 |
)
|
|
|
|
| 35 |
def generate_pdf_report():
|
| 36 |
pdf = FPDF()
|
| 37 |
pdf.add_page()
|
| 38 |
+
pdf.set_font("Arial", size=12)
|
| 39 |
|
| 40 |
+
pdf.cell(200, 10, txt="Quiz Report", ln=True, align="C")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
pdf.ln(10)
|
| 42 |
|
| 43 |
+
for module, data in st.session_state.module_question_count.items():
|
| 44 |
+
correct_count = st.session_state.module_correct_count.get(module, 0)
|
| 45 |
+
total_count = data
|
| 46 |
+
pdf.cell(200, 10, txt=f"Module: {module}", ln=True, align="L")
|
| 47 |
+
pdf.ln(5)
|
| 48 |
+
pdf.cell(200, 10, txt=f"Correct Answers: {correct_count}/{total_count}", ln=True, align="L")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
pdf.ln(5)
|
| 50 |
|
| 51 |
+
for entry in st.session_state.questions:
|
| 52 |
+
if entry['module'] == module:
|
| 53 |
+
question, options, selected, correct, explanation, step_by_step_solution = (
|
| 54 |
+
entry['question'],
|
| 55 |
+
entry['options'],
|
| 56 |
+
entry['selected'] if entry['selected'] is not None else "Not Answered",
|
| 57 |
+
entry['correct_answer'],
|
| 58 |
+
entry['explanation'],
|
| 59 |
+
entry['step_by_step_solution']
|
| 60 |
+
)
|
| 61 |
+
pdf.multi_cell(0, 10, f"Q: {question}")
|
| 62 |
+
for option in options:
|
| 63 |
+
if option == correct:
|
| 64 |
+
pdf.set_text_color(0, 128, 0) # Green for correct
|
| 65 |
+
pdf.multi_cell(0, 10, f"{option}")
|
| 66 |
+
elif option == selected:
|
| 67 |
+
pdf.set_text_color(255, 0, 0) # Red for incorrect
|
| 68 |
+
pdf.multi_cell(0, 10, f"{option}")
|
| 69 |
+
else:
|
| 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 |
|
| 84 |
def load_modules():
|
| 85 |
modules = {}
|
|
|
|
| 153 |
f"""
|
| 154 |
<div style="background-color: #333; padding: 10px; border-radius: 5px; margin-top: 20px;">
|
| 155 |
<span style='font-size: 18px; color: white;'>{selected_category} > {selected_module_data['title']}</span>
|
| 156 |
+
</div>
|
| 157 |
""",
|
| 158 |
unsafe_allow_html=True
|
| 159 |
)
|
|
|
|
| 162 |
st.markdown(
|
| 163 |
f"""
|
| 164 |
<a href='#' download='quiz_report.pdf' style='font-size: 18px; margin-left: 10px; color: white;' onclick='document.getElementById("pdf-link").click();'>📄 Download PDF Report</a>
|
|
|
|
| 165 |
""",
|
| 166 |
unsafe_allow_html=True
|
| 167 |
)
|