Sina Media Lab commited on
Commit
8aa4295
·
1 Parent(s): e79a4a1
Files changed (1) hide show
  1. app.py +53 -38
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=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
 
 
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