Alpha108 commited on
Commit
81ac99d
Β·
verified Β·
1 Parent(s): b1ba05d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -45
app.py CHANGED
@@ -15,6 +15,10 @@ total_marks_list = [60, 60, 60, 60, 60, 80]
15
  # Streamlit UI
16
  st.set_page_config(page_title="Quiz Result Calculator", layout="centered")
17
  st.title("🎯 Hacking Page – Quiz Marks Weighted Percentage Calculator")
 
 
 
 
18
  st.markdown("**Enter only the marks obtained below.**<br>Total marks are fixed: 60 for quizzes and 80 for the Grand Quiz.", unsafe_allow_html=True)
19
 
20
  marks_obtained = []
@@ -29,13 +33,15 @@ for i in range(6):
29
  marks_obtained.append(obtained)
30
 
31
  # Function to create PDF
32
- def generate_result_card_pdf(data, final_percentage):
33
  pdf_path = "result_card.pdf"
34
  doc = SimpleDocTemplate(pdf_path, pagesize=A4)
35
  elements = []
36
  styles = getSampleStyleSheet()
37
 
38
  elements.append(Paragraph("πŸŽ“ Quiz Result Card", styles['Title']))
 
 
39
  elements.append(Spacer(1, 12))
40
 
41
  table_data = [["Quiz", "Marks Obtained", "Total Marks", "Weightage (%)", "Section %", "Contribution (%)"]]
@@ -69,47 +75,50 @@ def generate_result_card_pdf(data, final_percentage):
69
 
70
  # On button click
71
  if st.button("πŸ” Calculate Result"):
72
- data = []
73
- total_weighted_percentage = 0
74
- section_percentages = []
75
-
76
- for i in range(6):
77
- total = total_marks_list[i]
78
- percent = (marks_obtained[i] / total) * 100
79
- contribution = percent * (weightages[i] / 100)
80
- total_weighted_percentage += contribution
81
- section_percentages.append(percent)
82
-
83
- data.append({
84
- "Quiz": quiz_labels[i],
85
- "Marks Obtained": marks_obtained[i],
86
- "Total Marks": total,
87
- "Weightage (%)": weightages[i],
88
- "Section %": round(percent, 2),
89
- "Contribution (%)": round(contribution, 2)
90
- })
91
-
92
- df = pd.DataFrame(data)
93
- df.set_index("Quiz", inplace=True)
94
-
95
- st.markdown("### πŸ“Š Results Table")
96
- st.dataframe(df)
97
-
98
- st.success(f"βœ… Final Weighted Percentage: **{total_weighted_percentage:.2f}%**")
99
-
100
- # Plotting
101
- fig, ax = plt.subplots()
102
- ax.barh(quiz_labels, section_percentages, color='skyblue')
103
- ax.set_xlabel("Percentage %")
104
- ax.set_title("Marks Percentage per Quiz")
105
- st.pyplot(fig)
106
-
107
- # Generate PDF
108
- pdf_path = generate_result_card_pdf(data, total_weighted_percentage)
109
- with open(pdf_path, "rb") as f:
110
- st.download_button(
111
- label="πŸ“„ Download Result Card (PDF)",
112
- data=f,
113
- file_name="result_card.pdf",
114
- mime="application/pdf"
115
- )
 
 
 
 
15
  # Streamlit UI
16
  st.set_page_config(page_title="Quiz Result Calculator", layout="centered")
17
  st.title("🎯 Hacking Page – Quiz Marks Weighted Percentage Calculator")
18
+
19
+ # Input for name
20
+ student_name = st.text_input("Enter your name:", max_chars=50)
21
+
22
  st.markdown("**Enter only the marks obtained below.**<br>Total marks are fixed: 60 for quizzes and 80 for the Grand Quiz.", unsafe_allow_html=True)
23
 
24
  marks_obtained = []
 
33
  marks_obtained.append(obtained)
34
 
35
  # Function to create PDF
36
+ def generate_result_card_pdf(data, final_percentage, student_name):
37
  pdf_path = "result_card.pdf"
38
  doc = SimpleDocTemplate(pdf_path, pagesize=A4)
39
  elements = []
40
  styles = getSampleStyleSheet()
41
 
42
  elements.append(Paragraph("πŸŽ“ Quiz Result Card", styles['Title']))
43
+ elements.append(Spacer(1, 8))
44
+ elements.append(Paragraph(f"<b>Name:</b> {student_name}", styles['Heading3']))
45
  elements.append(Spacer(1, 12))
46
 
47
  table_data = [["Quiz", "Marks Obtained", "Total Marks", "Weightage (%)", "Section %", "Contribution (%)"]]
 
75
 
76
  # On button click
77
  if st.button("πŸ” Calculate Result"):
78
+ if not student_name.strip():
79
+ st.error("Please enter your name to generate the result card.")
80
+ else:
81
+ data = []
82
+ total_weighted_percentage = 0
83
+ section_percentages = []
84
+
85
+ for i in range(6):
86
+ total = total_marks_list[i]
87
+ percent = (marks_obtained[i] / total) * 100
88
+ contribution = percent * (weightages[i] / 100)
89
+ total_weighted_percentage += contribution
90
+ section_percentages.append(percent)
91
+
92
+ data.append({
93
+ "Quiz": quiz_labels[i],
94
+ "Marks Obtained": marks_obtained[i],
95
+ "Total Marks": total,
96
+ "Weightage (%)": weightages[i],
97
+ "Section %": round(percent, 2),
98
+ "Contribution (%)": round(contribution, 2)
99
+ })
100
+
101
+ df = pd.DataFrame(data)
102
+ df.set_index("Quiz", inplace=True)
103
+
104
+ st.markdown("### πŸ“Š Results Table")
105
+ st.dataframe(df)
106
+
107
+ st.success(f"βœ… Final Weighted Percentage: **{total_weighted_percentage:.2f}%**")
108
+
109
+ # Plotting
110
+ fig, ax = plt.subplots()
111
+ ax.barh(quiz_labels, section_percentages, color='skyblue')
112
+ ax.set_xlabel("Percentage %")
113
+ ax.set_title("Marks Percentage per Quiz")
114
+ st.pyplot(fig)
115
+
116
+ # Generate PDF with student name
117
+ pdf_path = generate_result_card_pdf(data, total_weighted_percentage, student_name)
118
+ with open(pdf_path, "rb") as f:
119
+ st.download_button(
120
+ label="πŸ“„ Download Result Card (PDF)",
121
+ data=f,
122
+ file_name=f"{student_name.replace(' ', '_')}_result_card.pdf",
123
+ mime="application/pdf"
124
+ )