finish step 4

This commit is contained in:
SowinskiBraeden committed 2022-04-26 13:29:43 -07:00
1 parent dfdb6bf35a
commit bf08c023c1
1 file changed
+45 -24
+45 -24
View File
@@ -222,34 +222,20 @@ def generateScheduleV3(students: list, courses: dict) -> dict[str, dict]:
tempStudents.remove(student) tempStudents.remove(student)
# Step 4 - Attempt to fit classes into timetable # Step 4 - Attempt to fit classes into timetable
def stepIndex(offset: int, stepType: int) -> int:
if stepType == 0:
if offset == 0 or offset == -4: return 5
else: return -4
elif stepType == 1:
if offset == 0 or offset == 6: return -5
else: return 6
else: return 0
while len(allClassRunCounts) > 0: while len(allClassRunCounts) > 0:
# Get lowest resource class (least times run) # Get highest resource class (most times run)
index = allClassRunCounts.index(min(allClassRunCounts)) index = allClassRunCounts.index(min(allClassRunCounts))
course = list(courseRunInfo)[index] course = list(courseRunInfo)[index]
# If there is more than one class Running
if allClassRunCounts[index] > 1:
# Spread classes throughout both semesters
blockIndex = 0
offset = 0
for i in range(courseRunInfo[course]["Total"]):
cname = f"{course}-{i}"
blockIndex += offset
running[list(running)[blockIndex]][cname] = {
"CrsNo": course,
"Description": emptyClasses[course][cname]["Description"],
"students": selectedCourses[cname]["students"]
}
if offset == 0 or offset == -4: offset = 5
else: offset = -4
allClassRunCounts[index] -= 1
if blockIndex >= 9:
blockIndex = 0
offset = 0
# If the class only runs once, place in semester with least classes
elif allClassRunCounts[index] == 1:
# Tally first and second semester # Tally first and second semester
sem1, sem2 = 0, 0 sem1, sem2 = 0, 0
sem1List, sem2List = {}, {} sem1List, sem2List = {}, {}
@@ -260,6 +246,41 @@ def generateScheduleV3(students: list, courses: dict) -> dict[str, dict]:
sem2 += len(running[f"block{i}"]) sem2 += len(running[f"block{i}"])
sem2List[f"block{i}"] = running[f"block{i}"] sem2List[f"block{i}"] = running[f"block{i}"]
# If there is more than one class Running
if allClassRunCounts[index] > 1:
blockIndex = 0
offset = 0
stepType = 0
if sem1 > sem2:
# Update values to accomadate for sem2 fill priority
blockIndex = 5
stepType = 1
# Spread classes throughout both semesters
for i in range(courseRunInfo[course]["Total"]):
cname = f"{course}-{i}"
classInserted = False
while not classInserted:
blockIndex += offset
if len(running[list(running)[blockIndex]]) < 40:
running[list(running)[blockIndex]][cname] = {
"CrsNo": course,
"Description": emptyClasses[course][cname]["Description"],
"students": selectedCourses[cname]["students"]
}
allClassRunCounts[index] -= 1
classInserted = True
offset = stepIndex(offset, stepType)
if blockIndex >= 9:
blockIndex = 0
offset = 0
# If the class only runs once, place in semester with least classes
elif allClassRunCounts[index] == 1:
# Equally disperse into semesters classes # Equally disperse into semesters classes
semBlocks = [] semBlocks = []
offset = 1 offset = 1