Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import tempfile
|
|
| 8 |
COMPLETED_GRADES = {"GM", "RI", "RU", "RG", "RB", "RU+", "R1", "R2", "R3", "S"}
|
| 9 |
PROGRESS_GRADE = "MP"
|
| 10 |
|
| 11 |
-
def process_files(course_files, crn_file):
|
| 12 |
# Validate files exist
|
| 13 |
if not course_files or not crn_file:
|
| 14 |
return None, "Please upload both course roster files and a CRN mapping file."
|
|
@@ -88,6 +88,7 @@ def process_files(course_files, crn_file):
|
|
| 88 |
both_types = "Y" if data["progress"] and data["completed"] else ""
|
| 89 |
summary.append({
|
| 90 |
"Name": full_name,
|
|
|
|
| 91 |
"Progress Courses": progress,
|
| 92 |
"Completed Courses": completed,
|
| 93 |
"Both_Types": both_types
|
|
@@ -120,9 +121,22 @@ def process_files(course_files, crn_file):
|
|
| 120 |
worksheet.row_dimensions[idx + 2].height = max(15 * max_lines, 15) # +2 because of header and 1-based indexing
|
| 121 |
|
| 122 |
# Enable text wrapping for these columns
|
| 123 |
-
for col_idx in [2, 3]: # Columns
|
| 124 |
for cell in worksheet[chr(65 + col_idx)]:
|
| 125 |
cell.alignment = cell.alignment.copy(wrapText=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
# Return the path to the temporary file
|
| 128 |
return temp_file.name, "Summary generated successfully!"
|
|
@@ -135,7 +149,8 @@ iface = gr.Interface(
|
|
| 135 |
fn=process_files,
|
| 136 |
inputs=[
|
| 137 |
gr.Files(label="Upload ALL Course Roster Files (.xlsx)", file_count="multiple"),
|
| 138 |
-
gr.File(label="Upload CRN-to-Course Mapping File (.xlsx)")
|
|
|
|
| 139 |
],
|
| 140 |
outputs=[
|
| 141 |
gr.File(label="Download Student Summary Excel", file_types=[".xlsx"]),
|
|
|
|
| 8 |
COMPLETED_GRADES = {"GM", "RI", "RU", "RG", "RB", "RU+", "R1", "R2", "R3", "S"}
|
| 9 |
PROGRESS_GRADE = "MP"
|
| 10 |
|
| 11 |
+
def process_files(course_files, crn_file, session_name):
|
| 12 |
# Validate files exist
|
| 13 |
if not course_files or not crn_file:
|
| 14 |
return None, "Please upload both course roster files and a CRN mapping file."
|
|
|
|
| 88 |
both_types = "Y" if data["progress"] and data["completed"] else ""
|
| 89 |
summary.append({
|
| 90 |
"Name": full_name,
|
| 91 |
+
"Session": session_name, # Add the session name here
|
| 92 |
"Progress Courses": progress,
|
| 93 |
"Completed Courses": completed,
|
| 94 |
"Both_Types": both_types
|
|
|
|
| 121 |
worksheet.row_dimensions[idx + 2].height = max(15 * max_lines, 15) # +2 because of header and 1-based indexing
|
| 122 |
|
| 123 |
# Enable text wrapping for these columns
|
| 124 |
+
for col_idx in [2, 3]: # Columns C and D (0-indexed would be 2 and 3)
|
| 125 |
for cell in worksheet[chr(65 + col_idx)]:
|
| 126 |
cell.alignment = cell.alignment.copy(wrapText=True)
|
| 127 |
+
|
| 128 |
+
# Auto-adjust column widths
|
| 129 |
+
for column in worksheet.columns:
|
| 130 |
+
max_length = 0
|
| 131 |
+
column_letter = column[0].column_letter
|
| 132 |
+
for cell in column:
|
| 133 |
+
try:
|
| 134 |
+
if len(str(cell.value)) > max_length:
|
| 135 |
+
max_length = len(str(cell.value))
|
| 136 |
+
except:
|
| 137 |
+
pass
|
| 138 |
+
adjusted_width = (max_length + 2)
|
| 139 |
+
worksheet.column_dimensions[column_letter].width = min(adjusted_width, 50) # Cap width at 50
|
| 140 |
|
| 141 |
# Return the path to the temporary file
|
| 142 |
return temp_file.name, "Summary generated successfully!"
|
|
|
|
| 149 |
fn=process_files,
|
| 150 |
inputs=[
|
| 151 |
gr.Files(label="Upload ALL Course Roster Files (.xlsx)", file_count="multiple"),
|
| 152 |
+
gr.File(label="Upload CRN-to-Course Mapping File (.xlsx)"),
|
| 153 |
+
gr.Textbox(label="Session (e.g., Fall 1, Spring 2)", placeholder="Enter session name")
|
| 154 |
],
|
| 155 |
outputs=[
|
| 156 |
gr.File(label="Download Student Summary Excel", file_types=[".xlsx"]),
|