jiax264 commited on
Commit
a013fbc
·
verified ·
1 Parent(s): 841c63e
Files changed (1) hide show
  1. app.py +213 -92
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import warnings
2
  warnings.simplefilter('default', DeprecationWarning)
3
 
@@ -7,99 +8,219 @@ 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()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # New Graysheet
2
  import warnings
3
  warnings.simplefilter('default', DeprecationWarning)
4
 
 
8
  from datetime import datetime
9
 
10
  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, 'Exam Status'] == "Approved"): # only generates for students who are approved
15
+ # get the data
16
+ studentName = df.at[i, 'Student']
17
+ course = df.at[i, 'Course']
18
+ date = df.at[i, 'Date']
19
+ loc = df.at[i, 'Exam_Location']
20
+ scheduled_start_time = df.at[i, 'Time_Start']
21
+ scheduled_end_time = df.at[i, 'Time_End']
22
+
23
+ # format data with labels
24
+ studentName = " ".join(["Student's Name:", studentName])
25
+ course = " ".join(["Course:", course])
26
+ date = " ".join(["Date:", date])
27
+ if loc == loc:
28
+ loc = " ".join(["Location:", loc])
29
+ else:
30
+ loc = "Location: __________________"
31
+ scheduled_start_time = " ".join(["Scheduled Start Time:", scheduled_start_time])
32
+ scheduled_end_time = " ".join(["Scheduled End Time:", scheduled_end_time])
33
+
34
+ # add additional text about exam conditions
35
+ exam_conditions = ("\nThis exam is proctored under the specified conditions and expectations set by your faculty and Student Access. "
36
+ "Subverting the testing conditions or violating the Honor Code by utilizing unauthorized forms of assistance during "
37
+ "this exam will result in Student Access stopping your exam and reporting the incident.")
38
+
39
+ # put grouped info together
40
+ student_info = "\n".join([studentName, course, date, loc])
41
+ scheduled_time = "\n".join([scheduled_start_time, scheduled_end_time])
42
+ student_info_and_scheduled_time = "\n".join([student_info, scheduled_time, exam_conditions])
43
+ notes = "Additional Information:\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________"
44
+ actual_time = "\n".join(["Actual Start Time: _____________________________________________________",
45
+ "Estimated/Adjusted End Time: ___________________________________________",
46
+ "Actual End Time: ______________________________________________________"])
47
+ proctor = "Proctor's Signature: _______________________ Date: _______________________"
48
+
49
+ # construct the body of the pdf
50
+ body = "\n\n".join([student_info_and_scheduled_time, notes, actual_time, proctor])
51
+
52
+ # add this student's info to the list
53
+ page_body_list.append(body)
54
+
55
+ pdf = FPDF()
56
+ for i in range(len(page_body_list)):
57
+ pdf.add_page()
58
+
59
+ pdf.image("VandyStudentAccessLogo.png", 40, 10, w=120)
60
+
61
+ pdf.set_font('helvetica', 'B', size=16)
62
+ pdf.cell(w=210, h=9, txt="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
63
+
64
+ pdf.set_font('helvetica', 'B', size=16)
65
+ pdf.cell(w=210, h=9, txt="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
66
+
67
+ pdf.set_font('helvetica', 'B', size=8)
68
+ pdf.cell(w=210, h=9, txt="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
69
+
70
+ pdf.set_font('helvetica', 'B', size=14)
71
+ pdf.cell(w=210, h=9, txt="Exam Check-in Form", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
72
+
73
+ pdf.set_font('helvetica', 'B', size=10)
74
+ pdf.multi_cell(w=0, h=7, txt="This form is to be completed by the proctor. The student must return this \nform along with their reminder ticket and all exam materials.\n", border=0,
75
+ new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
76
+
77
+ pdf.set_font('helvetica', 'B', size=10)
78
+ pdf.cell(w=210, h=9, txt="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
79
+
80
+ pdf.set_font('helvetica', size=13)
81
+ pdf.multi_cell(0, 7, page_body_list[i])
82
+
83
+ pdf.set_font('helvetica', 'B', size=10)
84
+ pdf.set_xy(145, 255)
85
+ pdf.cell(w=0, h=7, txt="# of Exam Pages _________")
86
+ pdf.set_xy(145, 260)
87
+ pdf.cell(w=0, h=7, txt="Cover Sheets +2")
88
+ pdf.set_xy(145, 265)
89
+ pdf.cell(w=0, h=7, txt="Notes, Notecards, etc. ____")
90
+ pdf.set_xy(170, 270)
91
+ pdf.cell(w=0, h=7, txt="Total ______")
92
+
93
+ pdf.output("/tmp/GraySheets.pdf")
94
+ return "/tmp/GraySheets.pdf"
95
 
96
  def main():
97
+ st.title("Gray Sheet Generator")
98
+
99
+ # File upload
100
+ uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
101
+ if uploaded_file is not None:
102
+ # Process the file
103
+ df = pd.read_csv(uploaded_file)
104
+ pdf_path = generate_pdf(df)
105
+ todays_date = datetime.now().strftime("%m_%d_%Y")
106
+ filename = f"GraySheets_{todays_date}.pdf"
107
+
108
+ # Download button
109
+ with open(pdf_path, "rb") as file:
110
+ btn = st.download_button(
111
+ label="Download Gray Sheet",
112
+ data=file,
113
+ file_name=filename,
114
+ mime="application/octet-stream"
115
+ )
 
116
 
117
  if __name__ == "__main__":
118
+ main()
119
+
120
+
121
+ # Old GraySheet
122
+ # import warnings
123
+ # warnings.simplefilter('default', DeprecationWarning)
124
+
125
+ # from fpdf import FPDF
126
+ # import pandas as pd
127
+ # import streamlit as st
128
+ # from datetime import datetime
129
+
130
+ # def generate_pdf(df):
131
+ # num_students = df.shape[0]
132
+ # page_body_list = []
133
+ # for i in range(num_students):
134
+ # if(df.at[i, 'Exam Status'] == "Approved"): # only generates for students who are approved, not for those who are "processing" or "cancelled"
135
+ # # get the data
136
+ # studentName = df.at[i, 'Student']
137
+ # course = df.at[i, 'Course']
138
+ # date = df.at[i, 'Date']
139
+ # loc = df.at[i, 'Exam_Location']
140
+ # scheduled_start_time = df.at[i, 'Time_Start']
141
+ # scheduled_end_time = df.at[i, 'Time_End']
142
+
143
+ # # format data with labels
144
+ # studentName = " ".join(["Student's Name:", studentName])
145
+ # course = " ".join(["Course:", course])
146
+ # date = " ".join(["Date:", date])
147
+ # if loc == loc:
148
+ # loc = " ".join(["Location:", loc])
149
+ # else:
150
+ # loc = "Location: __________________"
151
+ # scheduled_start_time = " ".join(["Scheduled Start Time:", scheduled_start_time])
152
+ # scheduled_end_time = " ".join(["Scheduled End Time:", scheduled_end_time])
153
+
154
+ # # put grouped info together
155
+ # student_info = "\n".join([studentName, course, date, loc])
156
+ # scheduled_time = "\n".join([scheduled_start_time, scheduled_end_time])
157
+ # student_info_and_scheduled_time = "\n".join([student_info, scheduled_time])
158
+ # notes = "Additional Information:\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________"
159
+ # actual_time = "\n\n\n".join(["Actual Start Time: _____________________________________________________", "Estimated/Adjusted End Time: ___________________________________________", "Actual End Time: ______________________________________________________"])
160
+ # proctor = "\n\nProctor's Signature: _______________________ Date: _______________________"
161
+
162
+ # # construct the body of the pdf
163
+ # body = "\n\n\n".join([student_info_and_scheduled_time, notes, actual_time, proctor])
164
+
165
+ # # add this student's info to the list
166
+ # page_body_list.append(body)
167
+
168
+ # pdf = FPDF()
169
+ # for i in range(len(page_body_list)):
170
+ # pdf.add_page()
171
+
172
+ # pdf.image("VandyStudentAccessLogo.png", 40, 10, w=120)
173
+
174
+ # pdf.set_font('helvetica', 'B', size=16)
175
+ # pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
176
+
177
+ # pdf.set_font('helvetica', 'B', size=16)
178
+ # pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
179
+
180
+ # pdf.set_font('helvetica', 'B', size=8)
181
+ # pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
182
+
183
+ # pdf.set_font('helvetica', 'B', size=14)
184
+ # pdf.cell(w=210, h=9, text="Exam Check-in Form", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
185
+
186
+ # pdf.set_font('helvetica', 'B', size=10)
187
+ # 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,
188
+ # new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
189
+
190
+ # pdf.set_font('helvetica', 'B', size=10)
191
+ # pdf.cell(w=210, h=9, text="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False)
192
+
193
+ # pdf.set_font('helvetica', size=13)
194
+ # pdf.multi_cell(0, 7, page_body_list[i])
195
+
196
+ # pdf.set_font('helvetica', 'B', size=10)
197
+ # pdf.set_xy(145, 270)
198
+ # pdf.cell(w=0, h=5, text="# of Exam Pages: _____")
199
+
200
+ # pdf.output("/tmp/GraySheets.pdf")
201
+ # return "/tmp/GraySheets.pdf"
202
+
203
+ # def main():
204
+ # st.title("Gray Sheet Generator")
205
+
206
+ # # File upload
207
+ # uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
208
+ # if uploaded_file is not None:
209
+ # # Process the file
210
+ # df = pd.read_csv(uploaded_file)
211
+ # pdf_path = generate_pdf(df)
212
+ # todays_date = datetime.now().strftime("%m_%d_%Y")
213
+ # filename = f"GraySheets_{todays_date}.pdf"
214
+
215
+ # # Download button
216
+ # with open(pdf_path, "rb") as file:
217
+ # btn = st.download_button(
218
+ # label="Download Gray Sheet",
219
+ # data=file,
220
+ # file_name=filename,
221
+ # mime="application/octet-stream"
222
+ # )
223
+
224
+
225
+ # if __name__ == "__main__":
226
+ # main()