neat variable declaration
This commit is contained in:
1 file changed
+22
-21
+22
-21
@@ -83,7 +83,7 @@ def generateScheduleV3(
|
|||||||
|
|
||||||
|
|
||||||
# Step 1 - Calculate which classes can run
|
# Step 1 - Calculate which classes can run
|
||||||
activeCourses = {}
|
activeCourses: dict[str: dict] = {}
|
||||||
for student in students:
|
for student in students:
|
||||||
# Tally class request
|
# Tally class request
|
||||||
for request in (request for request in student.Requests if not request.Alt and request.CrsNo not in flex):
|
for request in (request for request in student.Requests if not request.Alt and request.CrsNo not in flex):
|
||||||
@@ -95,16 +95,16 @@ def generateScheduleV3(
|
|||||||
|
|
||||||
|
|
||||||
# Step 2 - Generate empty classes
|
# Step 2 - Generate empty classes
|
||||||
allClassRunCounts: list[int] = []
|
allClassRunCounts: list[int] = []
|
||||||
courseRunInfo: dict[str: dict[str: any]] = {} # Generated now, used in step 4
|
courseRunInfo: dict[str: dict] = {} # Generated now, used in step 4
|
||||||
emptyClasses: dict[str: dict[str: any]] = {} # List of all classes with how many students should be entered during step 3
|
emptyClasses: dict[str: dict] = {} # List of all classes with how many students should be entered during step 3
|
||||||
|
|
||||||
# calculate number of times to run class
|
# calculate number of times to run class
|
||||||
for i in range(len(activeCourses)):
|
for i in range(len(activeCourses)):
|
||||||
index = list(activeCourses)[i]
|
index: Course = list(activeCourses)[i]
|
||||||
if index not in emptyClasses: emptyClasses[index] = {}
|
if index not in emptyClasses: emptyClasses[index] = {}
|
||||||
classRunCount = activeCourses[index].Requests // median
|
classRunCount: int = activeCourses[index].Requests // median
|
||||||
remaining = activeCourses[index].Requests % median
|
remaining: int = activeCourses[index].Requests % median
|
||||||
|
|
||||||
# Put number of classRunCount classes in emptyClasses
|
# Put number of classRunCount classes in emptyClasses
|
||||||
for j in range(classRunCount):
|
for j in range(classRunCount):
|
||||||
@@ -185,8 +185,8 @@ def generateScheduleV3(
|
|||||||
|
|
||||||
|
|
||||||
# Step 3 - Fill 'emptyClasses' with Students
|
# Step 3 - Fill 'emptyClasses' with Students
|
||||||
selectedCourses = {}
|
selectedCourses: dict[str: dict] = {}
|
||||||
tempStudents = list(students)
|
tempStudents: list[Student] = list(students)
|
||||||
|
|
||||||
while len(tempStudents) > 0:
|
while len(tempStudents) > 0:
|
||||||
# Choose random student to prevent any success
|
# Choose random student to prevent any success
|
||||||
@@ -271,21 +271,21 @@ def generateScheduleV3(
|
|||||||
return (None, invalidStepTypeError)
|
return (None, invalidStepTypeError)
|
||||||
|
|
||||||
# Create copy for step 6
|
# Create copy for step 6
|
||||||
courseRunInfoCopy = dict(courseRunInfo)
|
courseRunInfoCopy: dict[str: dict] = dict(courseRunInfo)
|
||||||
|
|
||||||
while len(allClassRunCounts) > 0:
|
while len(allClassRunCounts) > 0:
|
||||||
# Get highest resource class (most times run)
|
# Get highest resource class (most times run)
|
||||||
index = allClassRunCounts.index(max(allClassRunCounts))
|
index: int = allClassRunCounts.index(max(allClassRunCounts))
|
||||||
course = list(courseRunInfo)[index]
|
course: str = list(courseRunInfo)[index]
|
||||||
|
|
||||||
# Tally first and second semester
|
# Tally first and second semester
|
||||||
allSemBlockLens = [len(running[f'block{i}']) for i in range(1, totalBlocks + 1)]
|
allSemBlockLens: list[int] = [len(running[f'block{i}']) for i in range(1, totalBlocks + 1)]
|
||||||
|
|
||||||
# If there is more than one class Running
|
# If there is more than one class Running
|
||||||
if allClassRunCounts[index] > 1:
|
if allClassRunCounts[index] > 1:
|
||||||
blockIndex = allSemBlockLens.index(min(allSemBlockLens))
|
blockIndex: int = allSemBlockLens.index(min(allSemBlockLens))
|
||||||
stepType = 0 if blockIndex < blockPerSem else 1
|
stepType: int = 0 if blockIndex < blockPerSem else 1
|
||||||
offset = 0
|
offset: int = 0
|
||||||
|
|
||||||
# Spread classes throughout both semesters
|
# Spread classes throughout both semesters
|
||||||
for i in range(courseRunInfo[course]["Total"]):
|
for i in range(courseRunInfo[course]["Total"]):
|
||||||
@@ -344,8 +344,8 @@ def generateScheduleV3(
|
|||||||
studentsCritical, studentsAcceptable = 0, 0
|
studentsCritical, studentsAcceptable = 0, 0
|
||||||
|
|
||||||
for student in students:
|
for student in students:
|
||||||
blocks = [student.Schedule[block] for block in student.Schedule]
|
blocks: list[list] = [student.Schedule[block] for block in student.Schedule]
|
||||||
hasConflicts = True if sum(1 for b in blocks if len(b)>1) > 0 else False
|
hasConflicts: bool = True if sum(1 for b in blocks if len(b)>1) > 0 else False
|
||||||
|
|
||||||
# If there is no conflicts
|
# If there is no conflicts
|
||||||
# and classes inserted to is equal to expectedClasses
|
# and classes inserted to is equal to expectedClasses
|
||||||
@@ -360,14 +360,15 @@ def generateScheduleV3(
|
|||||||
if not newConflict(student.PupilNum, "", "Acceptable", "A-MC", "Missing 1-2 Classses", conflictLogs): studentsAcceptable += 1
|
if not newConflict(student.PupilNum, "", "Acceptable", "A-MC", "Missing 1-2 Classses", conflictLogs): studentsAcceptable += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
studentData = {
|
studentData: dict[str: any] = {
|
||||||
"Pupil #": student.PupilNum,
|
"Pupil #": student.PupilNum,
|
||||||
"index": student.StudentIndex
|
"index": student.StudentIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasConflicts:
|
if hasConflicts:
|
||||||
student.Classes = 0
|
student.Classes: int = 0
|
||||||
missing = []
|
missing: list[str] = []
|
||||||
|
|
||||||
# Clear student schedule to restructure
|
# Clear student schedule to restructure
|
||||||
for block in student.Schedule:
|
for block in student.Schedule:
|
||||||
[running[block][cname]["students"].remove(studentData) for cname in student.Schedule[block]]
|
[running[block][cname]["students"].remove(studentData) for cname in student.Schedule[block]]
|
||||||
|
|||||||
Reference in new issue
Block a user