Spaces:
Running
Running
Upload 2 files
Browse files- VandyStudentAccessLogo.png +0 -0
- app.py +105 -0
VandyStudentAccessLogo.png
ADDED
![]() |
app.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import warnings
|
2 |
+
warnings.simplefilter('default', DeprecationWarning)
|
3 |
+
|
4 |
+
from fpdf import FPDF
|
5 |
+
import pandas as pd
|
6 |
+
import streamlit as st
|
7 |
+
from datetime import datetime
|
8 |
+
|
9 |
+
def generate_pdf(df):
|
10 |
+
num_students = df.shape[0]
|
11 |
+
page_body_list = []
|
12 |
+
for i in range(num_students):
|
13 |
+
if(df.at[i, 'Exam Status'] == "Approved"): # only generates for students who are approved, not for those who are "processing" or "cancelled"
|
14 |
+
# get the data
|
15 |
+
studentName = df.at[i, 'Student']
|
16 |
+
course = df.at[i, 'Course']
|
17 |
+
date = df.at[i, 'Date']
|
18 |
+
loc = df.at[i, 'Exam_Location']
|
19 |
+
scheduled_start_time = df.at[i, 'Time_Start']
|
20 |
+
scheduled_end_time = df.at[i, 'Time_End']
|
21 |
+
|
22 |
+
# format data with labels
|
23 |
+
studentName = " ".join(["Student's Name:", studentName])
|
24 |
+
course = " ".join(["Course:", course])
|
25 |
+
date = " ".join(["Date:", date])
|
26 |
+
if loc == loc:
|
27 |
+
loc = " ".join(["Location:", loc])
|
28 |
+
else:
|
29 |
+
loc = "Location: __________________"
|
30 |
+
scheduled_start_time = " ".join(["Scheduled Start Time:", scheduled_start_time])
|
31 |
+
scheduled_end_time = " ".join(["Scheduled End Time:", scheduled_end_time])
|
32 |
+
|
33 |
+
# put grouped info together
|
34 |
+
student_info = "\n".join([studentName, course, date, loc])
|
35 |
+
scheduled_time = "\n".join([scheduled_start_time, scheduled_end_time])
|
36 |
+
student_info_and_scheduled_time = "\n".join([student_info, scheduled_time])
|
37 |
+
notes = "Additional Information:\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________"
|
38 |
+
actual_time = "\n\n\n".join(["Actual Start Time: _____________________________________________________", "Estimated/Adjusted End Time: ___________________________________________", "Actual End Time: ______________________________________________________"])
|
39 |
+
proctor = "\n\nProctor's Signature: _______________________ Date: _______________________"
|
40 |
+
|
41 |
+
# construct the body of the pdf
|
42 |
+
body = "\n\n\n".join([student_info_and_scheduled_time, notes, actual_time, proctor])
|
43 |
+
|
44 |
+
# add this student's info to the list
|
45 |
+
page_body_list.append(body)
|
46 |
+
|
47 |
+
pdf = FPDF()
|
48 |
+
for i in range(len(page_body_list)):
|
49 |
+
pdf.add_page()
|
50 |
+
|
51 |
+
pdf.image("VandyStudentAccessLogo.png", 40, 10, w=120)
|
52 |
+
|
53 |
+
pdf.set_font('helvetica', 'B', size=16)
|
54 |
+
pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
55 |
+
|
56 |
+
pdf.set_font('helvetica', 'B', size=16)
|
57 |
+
pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
58 |
+
|
59 |
+
pdf.set_font('helvetica', 'B', size=8)
|
60 |
+
pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
61 |
+
|
62 |
+
pdf.set_font('helvetica', 'B', size=14)
|
63 |
+
pdf.cell(w=210, h=9, text="Exam Check-in Form", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
64 |
+
|
65 |
+
pdf.set_font('helvetica', 'B', size=10)
|
66 |
+
pdf.multi_cell(w=0, h=7, text="This form is to be completed by the proctor. The student must return this \nform along with their seat ticket and all exam materials.\n", border=0,
|
67 |
+
new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
68 |
+
|
69 |
+
pdf.set_font('helvetica', 'B', size=10)
|
70 |
+
pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
71 |
+
|
72 |
+
pdf.set_font('helvetica', size=13)
|
73 |
+
pdf.multi_cell(0, 7, page_body_list[i])
|
74 |
+
|
75 |
+
pdf.set_font('helvetica', 'B', size=10)
|
76 |
+
pdf.set_xy(145, 270)
|
77 |
+
pdf.cell(w=0, h=5, text="# of Exam Pages: _____")
|
78 |
+
|
79 |
+
pdf.output("/tmp/GraySheets.pdf")
|
80 |
+
return "/tmp/GraySheets.pdf"
|
81 |
+
|
82 |
+
def main():
|
83 |
+
st.title("Gray Sheet Generator")
|
84 |
+
|
85 |
+
# File upload
|
86 |
+
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
|
87 |
+
if uploaded_file is not None:
|
88 |
+
# Process the file
|
89 |
+
df = pd.read_csv(uploaded_file)
|
90 |
+
pdf_path = generate_pdf(df)
|
91 |
+
todays_date = datetime.now().strftime("%m_%d_%Y")
|
92 |
+
filename = f"GraySheets_{todays_date}.pdf"
|
93 |
+
|
94 |
+
# Download button
|
95 |
+
with open(pdf_path, "rb") as file:
|
96 |
+
btn = st.download_button(
|
97 |
+
label="Download Gray Sheet",
|
98 |
+
data=file,
|
99 |
+
file_name=filename,
|
100 |
+
mime="application/octet-stream"
|
101 |
+
)
|
102 |
+
|
103 |
+
|
104 |
+
if __name__ == "__main__":
|
105 |
+
main()
|