Sina Media Lab
commited on
Commit
·
d719d03
1
Parent(s):
3111cc8
Updates
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ if 'module_correct_count' not in st.session_state:
|
|
21 |
if 'module_question_count' not in st.session_state:
|
22 |
st.session_state.module_question_count = {}
|
23 |
if 'pdf_data' not in st.session_state:
|
24 |
-
st.session_state.pdf_data =
|
25 |
if 'selected_answer' not in st.session_state:
|
26 |
st.session_state.selected_answer = None
|
27 |
if 'button_label' not in st.session_state:
|
@@ -30,57 +30,54 @@ if 'start_time' not in st.session_state:
|
|
30 |
st.session_state.start_time = time.time()
|
31 |
|
32 |
def reset_pdf_cache():
|
33 |
-
st.session_state.pdf_data =
|
34 |
|
35 |
def generate_pdf_report():
|
36 |
pdf = FPDF()
|
37 |
pdf.add_page()
|
38 |
-
pdf.set_font("Arial",
|
39 |
|
40 |
-
|
41 |
-
pdf.set_fill_color(211, 211, 211) # Light gray
|
42 |
-
pdf.cell(0, 10, txt="🪄 Magic Math Quiz!", ln=True, align="C", fill=True)
|
43 |
-
pdf.ln(5)
|
44 |
-
pdf.set_font("Arial", size=8)
|
45 |
-
pdf.cell(0, 10, txt="by Ghassem Tofighi", ln=True, align="C", link="https://ghassem.com")
|
46 |
pdf.ln(10)
|
47 |
|
48 |
-
for
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
84 |
|
85 |
return pdf.output(dest='S').encode('latin1', 'replace')
|
86 |
|
|
|
21 |
if 'module_question_count' not in st.session_state:
|
22 |
st.session_state.module_question_count = {}
|
23 |
if 'pdf_data' not in st.session_state:
|
24 |
+
st.session_state.pdf_data = None
|
25 |
if 'selected_answer' not in st.session_state:
|
26 |
st.session_state.selected_answer = None
|
27 |
if 'button_label' not in st.session_state:
|
|
|
30 |
st.session_state.start_time = time.time()
|
31 |
|
32 |
def reset_pdf_cache():
|
33 |
+
st.session_state.pdf_data = None
|
34 |
|
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 |
|