File size: 6,211 Bytes
a013fbc
841c63e
 
 
 
 
 
 
 
 
a013fbc
 
 
0e626cd
a013fbc
0e626cd
 
 
 
 
 
a013fbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6bddf8a
1a4bc5e
a013fbc
 
1a4bc5e
a013fbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e626cd
 
 
 
 
 
 
 
841c63e
 
a013fbc
 
 
0e626cd
a013fbc
 
0e626cd
a013fbc
0e626cd
 
 
 
 
 
 
a013fbc
 
 
 
 
 
 
 
 
841c63e
 
0e626cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 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()