Spaces:
Sleeping
Sleeping
Update for new data format
Browse files
app.py
CHANGED
@@ -11,14 +11,14 @@ def generate_pdf(df):
|
|
11 |
num_students = df.shape[0]
|
12 |
page_body_list = []
|
13 |
for i in range(num_students):
|
14 |
-
if(df.at[i, '
|
15 |
# get the data
|
16 |
-
studentName = df.at[i, '
|
17 |
-
course = df.at[i, 'Course']
|
18 |
-
date = df.at[i, 'Date']
|
19 |
-
loc = df.at[i, '
|
20 |
-
scheduled_start_time = df.at[i, '
|
21 |
-
scheduled_end_time = df.at[i, '
|
22 |
|
23 |
# format data with labels
|
24 |
studentName = " ".join(["Student's Name:", studentName])
|
@@ -91,20 +91,31 @@ def generate_pdf(df):
|
|
91 |
pdf.set_xy(170, 270)
|
92 |
pdf.cell(w=0, h=7, txt="Total ______")
|
93 |
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
def main():
|
98 |
st.title("Gray Sheet Generator")
|
99 |
|
100 |
# File upload
|
101 |
-
uploaded_file = st.file_uploader("Choose
|
102 |
if uploaded_file is not None:
|
103 |
# Process the file
|
104 |
-
df = pd.
|
105 |
pdf_path = generate_pdf(df)
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
# Download button
|
110 |
with open(pdf_path, "rb") as file:
|
@@ -116,112 +127,4 @@ def main():
|
|
116 |
)
|
117 |
|
118 |
if __name__ == "__main__":
|
119 |
-
main()
|
120 |
-
|
121 |
-
|
122 |
-
# Old GraySheet
|
123 |
-
# import warnings
|
124 |
-
# warnings.simplefilter('default', DeprecationWarning)
|
125 |
-
|
126 |
-
# from fpdf import FPDF
|
127 |
-
# import pandas as pd
|
128 |
-
# import streamlit as st
|
129 |
-
# from datetime import datetime
|
130 |
-
|
131 |
-
# def generate_pdf(df):
|
132 |
-
# num_students = df.shape[0]
|
133 |
-
# page_body_list = []
|
134 |
-
# for i in range(num_students):
|
135 |
-
# if(df.at[i, 'Exam Status'] == "Approved"): # only generates for students who are approved, not for those who are "processing" or "cancelled"
|
136 |
-
# # get the data
|
137 |
-
# studentName = df.at[i, 'Student']
|
138 |
-
# course = df.at[i, 'Course']
|
139 |
-
# date = df.at[i, 'Date']
|
140 |
-
# loc = df.at[i, 'Exam_Location']
|
141 |
-
# scheduled_start_time = df.at[i, 'Time_Start']
|
142 |
-
# scheduled_end_time = df.at[i, 'Time_End']
|
143 |
-
|
144 |
-
# # format data with labels
|
145 |
-
# studentName = " ".join(["Student's Name:", studentName])
|
146 |
-
# course = " ".join(["Course:", course])
|
147 |
-
# date = " ".join(["Date:", date])
|
148 |
-
# if loc == loc:
|
149 |
-
# loc = " ".join(["Location:", loc])
|
150 |
-
# else:
|
151 |
-
# loc = "Location: __________________"
|
152 |
-
# scheduled_start_time = " ".join(["Scheduled Start Time:", scheduled_start_time])
|
153 |
-
# scheduled_end_time = " ".join(["Scheduled End Time:", scheduled_end_time])
|
154 |
-
|
155 |
-
# # put grouped info together
|
156 |
-
# student_info = "\n".join([studentName, course, date, loc])
|
157 |
-
# scheduled_time = "\n".join([scheduled_start_time, scheduled_end_time])
|
158 |
-
# student_info_and_scheduled_time = "\n".join([student_info, scheduled_time])
|
159 |
-
# notes = "Additional Information:\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________"
|
160 |
-
# actual_time = "\n\n\n".join(["Actual Start Time: _____________________________________________________", "Estimated/Adjusted End Time: ___________________________________________", "Actual End Time: ______________________________________________________"])
|
161 |
-
# proctor = "\n\nProctor's Signature: _______________________ Date: _______________________"
|
162 |
-
|
163 |
-
# # construct the body of the pdf
|
164 |
-
# body = "\n\n\n".join([student_info_and_scheduled_time, notes, actual_time, proctor])
|
165 |
-
|
166 |
-
# # add this student's info to the list
|
167 |
-
# page_body_list.append(body)
|
168 |
-
|
169 |
-
# pdf = FPDF()
|
170 |
-
# for i in range(len(page_body_list)):
|
171 |
-
# pdf.add_page()
|
172 |
-
|
173 |
-
# pdf.image("VandyStudentAccessLogo.png", 40, 10, w=120)
|
174 |
-
|
175 |
-
# pdf.set_font('helvetica', 'B', size=16)
|
176 |
-
# pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
177 |
-
|
178 |
-
# pdf.set_font('helvetica', 'B', size=16)
|
179 |
-
# pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
180 |
-
|
181 |
-
# pdf.set_font('helvetica', 'B', size=8)
|
182 |
-
# pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
183 |
-
|
184 |
-
# pdf.set_font('helvetica', 'B', size=14)
|
185 |
-
# pdf.cell(w=210, h=9, text="Exam Check-in Form", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
186 |
-
|
187 |
-
# pdf.set_font('helvetica', 'B', size=10)
|
188 |
-
# 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,
|
189 |
-
# new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
190 |
-
|
191 |
-
# pdf.set_font('helvetica', 'B', size=10)
|
192 |
-
# pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
|
193 |
-
|
194 |
-
# pdf.set_font('helvetica', size=13)
|
195 |
-
# pdf.multi_cell(0, 7, page_body_list[i])
|
196 |
-
|
197 |
-
# pdf.set_font('helvetica', 'B', size=10)
|
198 |
-
# pdf.set_xy(145, 270)
|
199 |
-
# pdf.cell(w=0, h=5, text="# of Exam Pages: _____")
|
200 |
-
|
201 |
-
# pdf.output("/tmp/GraySheets.pdf")
|
202 |
-
# return "/tmp/GraySheets.pdf"
|
203 |
-
|
204 |
-
# def main():
|
205 |
-
# st.title("Gray Sheet Generator")
|
206 |
-
|
207 |
-
# # File upload
|
208 |
-
# uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
|
209 |
-
# if uploaded_file is not None:
|
210 |
-
# # Process the file
|
211 |
-
# df = pd.read_csv(uploaded_file)
|
212 |
-
# pdf_path = generate_pdf(df)
|
213 |
-
# todays_date = datetime.now().strftime("%m_%d_%Y")
|
214 |
-
# filename = f"GraySheets_{todays_date}.pdf"
|
215 |
-
|
216 |
-
# # Download button
|
217 |
-
# with open(pdf_path, "rb") as file:
|
218 |
-
# btn = st.download_button(
|
219 |
-
# label="Download Gray Sheet",
|
220 |
-
# data=file,
|
221 |
-
# file_name=filename,
|
222 |
-
# mime="application/octet-stream"
|
223 |
-
# )
|
224 |
-
|
225 |
-
|
226 |
-
# if __name__ == "__main__":
|
227 |
-
# main()
|
|
|
11 |
num_students = df.shape[0]
|
12 |
page_body_list = []
|
13 |
for i in range(num_students):
|
14 |
+
if(df.at[i, 'Approved'] == "Yes"): # only generates for students who are approved
|
15 |
# get the data
|
16 |
+
studentName = f"{df.at[i, 'First Name']} {df.at[i, 'Last Name']}"
|
17 |
+
course = f"{df.at[i, 'Subject']} {df.at[i, 'Course']}.{df.at[i, 'Section']}"
|
18 |
+
date = df.at[i, 'Exam Date'].strftime('%m/%d/%Y')
|
19 |
+
loc = df.at[i, 'Location Name']
|
20 |
+
scheduled_start_time = str(df.at[i, 'Start Time'])
|
21 |
+
scheduled_end_time = str(df.at[i, 'End Time'])
|
22 |
|
23 |
# format data with labels
|
24 |
studentName = " ".join(["Student's Name:", studentName])
|
|
|
91 |
pdf.set_xy(170, 270)
|
92 |
pdf.cell(w=0, h=7, txt="Total ______")
|
93 |
|
94 |
+
if len(page_body_list) > 0:
|
95 |
+
exam_date = df.at[0, 'Exam Date'].strftime('%m_%d_%Y')
|
96 |
+
pdf.output(f"/tmp/GraySheets_{exam_date}.pdf")
|
97 |
+
return f"/tmp/GraySheets_{exam_date}.pdf"
|
98 |
+
else:
|
99 |
+
todays_date = datetime.now().strftime("%m_%d_%Y")
|
100 |
+
pdf.output(f"/tmp/GraySheets_{todays_date}.pdf")
|
101 |
+
return f"/tmp/GraySheets_{todays_date}.pdf"
|
102 |
|
103 |
def main():
|
104 |
st.title("Gray Sheet Generator")
|
105 |
|
106 |
# File upload
|
107 |
+
uploaded_file = st.file_uploader("Choose an Excel file", type=["xlsx", "xls"])
|
108 |
if uploaded_file is not None:
|
109 |
# Process the file
|
110 |
+
df = pd.read_excel(uploaded_file)
|
111 |
pdf_path = generate_pdf(df)
|
112 |
+
|
113 |
+
if len(df) > 0:
|
114 |
+
exam_date = df.at[0, 'Exam Date'].strftime('%m_%d_%Y')
|
115 |
+
filename = f"GraySheets_{exam_date}.pdf"
|
116 |
+
else:
|
117 |
+
todays_date = datetime.now().strftime("%m_%d_%Y")
|
118 |
+
filename = f"GraySheets_{todays_date}.pdf"
|
119 |
|
120 |
# Download button
|
121 |
with open(pdf_path, "rb") as file:
|
|
|
127 |
)
|
128 |
|
129 |
if __name__ == "__main__":
|
130 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|