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