initial commit

This commit is contained in:
SowinskiBraeden committed 2022-11-06 11:50:13 -08:00
commit 7b909b770b
15 files changed
+1011

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env python 3.11
from docx.shared import Inches
from app.util.globals import flex
import docx
def putMasterTimetable(timetable: dict) -> None:
pass
def putScheduleToWord(courses: dict, student: dict, output_dir: str='../../output/final/student_schedules') -> None:
# create an instance of a word doc.
doc = docx.Document()
doc.add_heading(f'Schedule for Student {student["Pupil #"]}')
# Create a table object
table = doc.add_table(rows=1, cols=3)
table.autofit = True
table.style = 'Colorful List'
# course name + (code) | block | semester
row = table.rows[0].cells
row[0].text = 'Course'
row[1].text = 'Block'
row[2].text = 'Sem.'
table.columns[0].width = Inches(3.5)
table.columns[1].width = Inches(0.75)
table.columns[2].width = Inches(0.75)
for block in student['schedule']:
courseCode = student["schedule"][block][0]
if courseCode in flex: courseName = 'Study'
else: courseName = courses[courseCode[:-2]]["Description"]
blockNum = int(block.split('block')[1])
semester = 2 if blockNum > 5 else 1
if blockNum > (len(student["schedule"])/2): blockNum -= (len(student["schedule"])/2)
row = table.add_row().cells
row[0].text = f'{courseName}\n({courseCode})'
row[1].text = str(blockNum)
row[2].text = str(semester)
for row in table.rows:
row.height = Inches(0.75)
doc.save(f'{output_dir}/{student["Pupil #"]}_schedule.docx')
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env python3.11
from app.util.globals import flex
most_frequent = lambda l : max(set(l), key = l.count)
def getGradeFromCourseCode(code: str) -> int:
grades = [int(s) for s in code.split("-") if s.isdigit()]
return None if len(grades) == 0 else most_frequent(grades)
def getEstimatedGrade(pupil: dict) -> int:
grades = [] # List of all possible grades
for request in (r for r in pupil["requests"] if r not in flex):
for extractedGrade in [int(s) for s in request["CrsNo"].split("-") if s.isdigit()]:
grades.append(extractedGrade)
return None if len(grades) == 0 else most_frequent(grades) # Final estimate of grade
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env python3.11
import json
import csv
# Get all requested courses from data
def getCourses(
data_dir: str,
log: int=False,
log_dir: str='./output/raw/courses.json',
) -> dict[dict[str: any]]:
courses = {}
with open(data_dir, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
exists = False
for course in courses:
exists = True if courses[course]["CrsNo"] == row["CrsNo"] else False
if exists: break
if not exists:
courses[row["CrsNo"]] = {
"CrsNo": row["CrsNo"],
"Requests": 0,
"Description": row["Description"],
"students": []
}
if log:
with open(log_dir, "w") as outfile:
json.dump(courses, outfile, indent=2)
return courses
+59
View File
@@ -0,0 +1,59 @@
#!/usr/bin/env python3.11
import json
import csv
from app.util.estimateGrade import getEstimatedGrade
from app.util.globals import flex
# sort data into usable dictionary
def getStudents(
data_dir: str,
log: bool=False,
totalBlocks: int=10,
log_dir: str='./output/raw/students.json'
) -> list[ dict[ str: any ] ]:
students: list[ dict[ str: any ] ] = []
with open(data_dir, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
exists = False
for student in students:
exists = True if student["Pupil #"] == row["Pupil #"] else False
if exists: break
alternate = True if row["Alternate?"] == 'TRUE' else False
if exists:
if len(students[student["studentIndex"]]["requests"]) >= totalBlocks and not alternate and row["CrsNo"] not in flex: alternate = True
students[student["studentIndex"]]["requests"].append({
"CrsNo": row["CrsNo"],
"Description": row["Description"],
"alt": alternate
})
if row["CrsNo"] not in flex and not alternate and students[student["studentIndex"]]["expectedClasses"] < 10:
students[student["studentIndex"]]["expectedClasses"] += 1
else:
newStudent = {
"Pupil #": row["Pupil #"],
"requests": [{
"CrsNo": row["CrsNo"],
"Description": row["Description"],
"alt": alternate
}],
"schedule": {},
"expectedClasses": 1,
"classes": 0,
"remainingAlts": [],
"studentIndex": len(students)
}
for i in range(1, totalBlocks+1): newStudent["schedule"][f'block{i}'] = []
students.append(newStudent)
# Estimate student grades
for student in students:
student["gradelevel"] = getEstimatedGrade(student)
if log:
with open(log_dir, "w") as outfile:
json.dump(students, outfile, indent=2)
return students
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env python3.11
from dataclasses import dataclass
# These are the codes for Flex (spare) blocks
# Semester 1 and 2
flex: tuple = ("XAT--12A-S", "XAT--12B-S")
# Global function
exists = lambda n : True if n not in ('', None) else False
# Global data class
@dataclass
class Error:
Title: str
Description: str
def __init__(self, title: str, description: str):
self.Title = title
self.Description = description