add step 6 exception handlers

This commit is contained in:
SowinskiBraeden committed 2022-05-04 13:30:09 -07:00
1 parent 996cf963ae
commit d5636831dc
2 files changed
+44 -10

No files matched your search

+40 -8
View File
@@ -338,27 +338,51 @@ def generateScheduleV3(
for cname in running[block]: for cname in running[block]:
for student in running[block][cname]["students"]: for student in running[block][cname]["students"]:
students[student["index"]]["schedule"][block].append(cname) students[student["index"]]["schedule"][block].append(cname)
students[student["index"]]["classes"] += 1
# Step 6 - Evaluate, move students to fix # Step 6 - Evaluate, move students to fix
conflicts = [] conflicts = []
for student in students: for student in students:
print(student["Pupil #"])
blocks = [student["schedule"][block] for block in student["schedule"]] blocks = [student["schedule"][block] for block in student["schedule"]]
origin = list(block) origin = list(block)
exceptions = [] exceptions = []
count, hasConflict = 0, True count, hasConflict = 0, True
initialCount = sum(1 for b in blocks if len(b)==1)
if initialCount == student["classes"]:
hasConflict = False
if initialCount < student["expectedClasses"]:
conflicts.append({
"Pupil #": student["Pupil #"],
"Email": "",
"Conflict": "Missing classes"
})
while hasConflict: while hasConflict:
count = sum(1 for b in blocks if len(b)==1)
if count < student["expectedClasses"]:
blockLens = [len(block) for block in blocks]
# Get clash # Get clash
if len(exceptions) > 0: if len(exceptions) > 0:
blocks = [elem for i, elem in enumerate(blocks) if i not in exceptions] blocks = [elem for i, elem in enumerate(blocks) if i not in exceptions]
for index in exceptions: blocks.insert(index, ['nil']) exceptCopy = list(exceptions)
while len(exceptCopy) > 0:
minIndex = exceptCopy.index(min(exceptCopy))
blocks.insert(minIndex, ['nil'])
count = sum(1 for b in blocks if len(b)==1)
if count < student["expectedClasses"]:
if count == student["classes"]:
conflicts.append({
"Pupil #": student["Pupil #"],
"Email": "",
"Conflict": "Missing classes"
})
hasConflict = False
break
blockLens = [len(block) for block in blocks]
index = blockLens.index(max(blockLens)) index = blockLens.index(max(blockLens))
blockOut = f"block{index+1}" blockOut = f"block{index+1}"
@@ -395,8 +419,14 @@ def generateScheduleV3(
moveIndex += 1 moveIndex += 1
elif moveIndex == len(blocks[index])-1: elif moveIndex == len(blocks[index])-1:
if index not in exceptions: exceptions.append(index) if index not in exceptions: exceptions.append(index)
done = True
break else:
print('impossible err 3')
elif found: done = True
else:
print('impossible err 2')
elif count == student["expectedClasses"]: elif count == student["expectedClasses"]:
if len(exceptions) > 0: if len(exceptions) > 0:
@@ -417,6 +447,8 @@ def generateScheduleV3(
"Conflict": "More classes than expected" "Conflict": "More classes than expected"
}) })
hasConflict = False hasConflict = False
else:
print('impossible err 1')
# Update Student Schedule # Update Student Schedule
student["schedule"] = blocks student["schedule"] = blocks
+4 -2
View File
@@ -51,6 +51,8 @@ def getSampleStudents(data_dir: str, log: bool = False) -> list[dict]:
"Description": row["Description"], "Description": row["Description"],
"alt": alternate "alt": alternate
}) })
if row["CrsNo"] not in ["XAT--12A-S", "XAT--12B-S"] and not alternate:
mockStudents[student["studentIndex"]]["expectedClasses"] += 1
else: else:
newStudent = { newStudent = {
"Pupil #": row["Pupil #"], "Pupil #": row["Pupil #"],
@@ -71,13 +73,13 @@ def getSampleStudents(data_dir: str, log: bool = False) -> list[dict]:
"block9": [], "block9": [],
"block10": [] "block10": []
}, },
"expectedClasses": 8, "expectedClasses": 1,
"classes": 0,
"remainingAlts": [], "remainingAlts": [],
"studentIndex": len(mockStudents) "studentIndex": len(mockStudents)
} }
mockStudents.append(newStudent) mockStudents.append(newStudent)
if row["CrsNo"] in ["XAT--12A-S", "XAT--12B-S"]: mockStudents[student["studentIndex"]]["expectedClasses"] -= 1
if log: if log:
with open("./output/students.json", "w") as outfile: with open("./output/students.json", "w") as outfile:
json.dump(mockStudents, outfile, indent=2) json.dump(mockStudents, outfile, indent=2)