Spaces:
Sleeping
Sleeping
| # New Graysheet | |
| import warnings | |
| warnings.simplefilter('default', DeprecationWarning) | |
| from fpdf import FPDF | |
| import pandas as pd | |
| import streamlit as st | |
| from datetime import datetime | |
| def generate_pdf(df): | |
| num_students = df.shape[0] | |
| page_body_list = [] | |
| for i in range(num_students): | |
| if(df.at[i, 'Approved'] == "Yes"): # only generates for students who are approved | |
| # get the data | |
| studentName = f"{df.at[i, 'First Name']} {df.at[i, 'Last Name']}" | |
| course = f"{df.at[i, 'Subject']} {df.at[i, 'Course']}.{df.at[i, 'Section']}" | |
| date = df.at[i, 'Exam Date'].strftime('%m/%d/%Y') | |
| loc = df.at[i, 'Location Name'] | |
| scheduled_start_time = str(df.at[i, 'Start Time']) | |
| scheduled_end_time = str(df.at[i, 'End Time']) | |
| # format data with labels | |
| studentName = " ".join(["Student's Name:", studentName]) | |
| course = " ".join(["Course:", course]) | |
| date = " ".join(["Date:", date]) | |
| if loc == loc: | |
| loc = " ".join(["Location:", loc]) | |
| else: | |
| loc = "Location: __________________" | |
| scheduled_start_time = " ".join(["Scheduled Start Time:", scheduled_start_time]) | |
| scheduled_end_time = " ".join(["Scheduled End Time:", scheduled_end_time]) | |
| # add additional text about exam conditions | |
| exam_conditions = ("\nThis exam is proctored under the specified conditions and expectations set by your faculty and Student Access. " | |
| "Subverting the testing conditions or violating the Honor Code by utilizing unauthorized forms of assistance during " | |
| "this exam will result in Student Access stopping your exam and reporting the incident.") | |
| # put grouped info together | |
| student_info = "\n".join([studentName, course, date, loc]) | |
| scheduled_time = "\n".join([scheduled_start_time, scheduled_end_time]) | |
| student_info_and_scheduled_time = "\n".join([student_info, scheduled_time, exam_conditions]) | |
| notes = "Additional Information:\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________\n____________________________________________________________________" | |
| actual_time = "\n".join(["Actual Start Time: _____________________________________________________", | |
| "Estimated/Adjusted End Time: ___________________________________________", | |
| "Actual End Time: ______________________________________________________"]) | |
| proctor = "Proctor Signature: _______________________ Date: _______________________" | |
| student = "Student Signature: ______________________ Date: _______________________" | |
| # construct the body of the pdf | |
| body = "\n\n".join([student_info_and_scheduled_time, notes, actual_time, proctor, student]) | |
| # add this student's info to the list | |
| page_body_list.append(body) | |
| pdf = FPDF() | |
| for i in range(len(page_body_list)): | |
| pdf.add_page() | |
| pdf.image("VandyStudentAccessLogo.png", 40, 10, w=120) | |
| pdf.set_font('helvetica', 'B', size=16) | |
| pdf.cell(w=210, h=9, txt="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) | |
| pdf.set_font('helvetica', 'B', size=16) | |
| pdf.cell(w=210, h=9, txt="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) | |
| pdf.set_font('helvetica', 'B', size=8) | |
| pdf.cell(w=210, h=9, txt="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) | |
| pdf.set_font('helvetica', 'B', size=14) | |
| pdf.cell(w=210, h=9, txt="Exam Check-in Form", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) | |
| pdf.set_font('helvetica', 'B', size=10) | |
| 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, | |
| new_x="LMARGIN", new_y="NEXT", align='C', fill=False) | |
| pdf.set_font('helvetica', 'B', size=10) | |
| pdf.cell(w=210, h=9, txt="\n", border=0, new_x="LMARGIN", new_y="NEXT", align='C', fill=False) | |
| pdf.set_font('helvetica', size=13) | |
| pdf.multi_cell(0, 7, page_body_list[i]) | |
| pdf.set_font('helvetica', 'B', size=10) | |
| pdf.set_xy(145, 255) | |
| pdf.cell(w=0, h=7, txt="# of Exam Pages _________") | |
| pdf.set_xy(145, 260) | |
| pdf.cell(w=0, h=7, txt="Cover Sheets +2") | |
| pdf.set_xy(145, 265) | |
| pdf.cell(w=0, h=7, txt="Notes, Notecards, etc. ____") | |
| pdf.set_xy(170, 270) | |
| pdf.cell(w=0, h=7, txt="Total ______") | |
| if len(page_body_list) > 0: | |
| exam_date = df.at[0, 'Exam Date'].strftime('%m_%d_%Y') | |
| pdf.output(f"/tmp/GraySheets_{exam_date}.pdf") | |
| return f"/tmp/GraySheets_{exam_date}.pdf" | |
| else: | |
| todays_date = datetime.now().strftime("%m_%d_%Y") | |
| pdf.output(f"/tmp/GraySheets_{todays_date}.pdf") | |
| return f"/tmp/GraySheets_{todays_date}.pdf" | |
| def main(): | |
| st.title("Gray Sheet Generator") | |
| # File upload | |
| uploaded_file = st.file_uploader("Choose an Excel file", type=["xlsx", "xls"]) | |
| if uploaded_file is not None: | |
| # Process the file | |
| df = pd.read_excel(uploaded_file) | |
| pdf_path = generate_pdf(df) | |
| if len(df) > 0: | |
| exam_date = df.at[0, 'Exam Date'].strftime('%m_%d_%Y') | |
| filename = f"GraySheets_{exam_date}.pdf" | |
| else: | |
| todays_date = datetime.now().strftime("%m_%d_%Y") | |
| filename = f"GraySheets_{todays_date}.pdf" | |
| # Download button | |
| with open(pdf_path, "rb") as file: | |
| btn = st.download_button( | |
| label="Download Gray Sheet", | |
| data=file, | |
| file_name=filename, | |
| mime="application/octet-stream" | |
| ) | |
| if __name__ == "__main__": | |
| main() |