debug all of step 6
This commit is contained in:
1 parent
d5636831dc
commit
71d59f7227
2 files changed
+66
-4
No files matched your search
@@ -345,25 +345,34 @@ def generateScheduleV3(
|
|||||||
conflicts = []
|
conflicts = []
|
||||||
|
|
||||||
for student in students:
|
for student in students:
|
||||||
print(student["Pupil #"])
|
#print("====New Student====")
|
||||||
|
# print(student["Pupil #"])
|
||||||
blocks = [student["schedule"][block] for block in student["schedule"]]
|
blocks = [student["schedule"][block] for block in student["schedule"]]
|
||||||
|
#print("Blocks: ", blocks)
|
||||||
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)
|
initialCount = sum(1 for b in blocks if len(b)==1)
|
||||||
|
#print("Initial Count: ", initialCount)
|
||||||
if initialCount == student["classes"]:
|
if initialCount == student["classes"]:
|
||||||
|
#print("Classes already set")
|
||||||
hasConflict = False
|
hasConflict = False
|
||||||
|
|
||||||
if initialCount < student["expectedClasses"]:
|
if initialCount < student["expectedClasses"]:
|
||||||
|
#print("New Conflict 1: Missing Classes")
|
||||||
conflicts.append({
|
conflicts.append({
|
||||||
"Pupil #": student["Pupil #"],
|
"Pupil #": student["Pupil #"],
|
||||||
"Email": "",
|
"Email": "",
|
||||||
"Conflict": "Missing classes"
|
"Conflict": "Missing classes"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#print("Begin conflic Check...")
|
||||||
|
#print("Has Conflict: ", hasConflict)
|
||||||
while hasConflict:
|
while hasConflict:
|
||||||
|
#print("Retrieve clash...")
|
||||||
# Get clash
|
# Get clash
|
||||||
if len(exceptions) > 0:
|
if len(exceptions) > 0:
|
||||||
|
#print("Exceptions exists, make new list to ignore exceptions")
|
||||||
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]
|
||||||
exceptCopy = list(exceptions)
|
exceptCopy = list(exceptions)
|
||||||
while len(exceptCopy) > 0:
|
while len(exceptCopy) > 0:
|
||||||
@@ -371,32 +380,50 @@ def generateScheduleV3(
|
|||||||
blocks.insert(minIndex, ['nil'])
|
blocks.insert(minIndex, ['nil'])
|
||||||
|
|
||||||
count = sum(1 for b in blocks if len(b)==1)
|
count = sum(1 for b in blocks if len(b)==1)
|
||||||
|
#print("New Count: ", count)
|
||||||
|
|
||||||
if count < student["expectedClasses"]:
|
if count < student["expectedClasses"]:
|
||||||
|
#print("There must be a clash...")
|
||||||
if count == student["classes"]:
|
if count == student["classes"]:
|
||||||
|
#print("New Conflict 2: Missing Classes")
|
||||||
conflicts.append({
|
conflicts.append({
|
||||||
"Pupil #": student["Pupil #"],
|
"Pupil #": student["Pupil #"],
|
||||||
"Email": "",
|
"Email": "",
|
||||||
"Conflict": "Missing classes"
|
"Conflict": "Missing classes"
|
||||||
})
|
})
|
||||||
hasConflict = False
|
hasConflict = False
|
||||||
|
#print("end conflicts...")
|
||||||
break
|
break
|
||||||
|
|
||||||
blockLens = [len(block) for block in blocks]
|
blockLens = [len(block) for block in blocks]
|
||||||
index = blockLens.index(max(blockLens))
|
index = blockLens.index(max(blockLens))
|
||||||
|
#print("Block Lengths: ", blockLens)
|
||||||
|
#print("Clash Index: ", index)
|
||||||
|
|
||||||
blockOut = f"block{index+1}"
|
blockOut = f"block{index+1}"
|
||||||
|
#print("blockOut: ", blockOut)
|
||||||
done = False
|
done = False
|
||||||
moveIndex = 0
|
moveIndex = 0
|
||||||
|
#print("moveIndex: ", moveIndex)
|
||||||
freeBlocks = [blockIndex for blockIndex in range(len(blocks)) if len(blocks[blockIndex]) == 0]
|
freeBlocks = [blockIndex for blockIndex in range(len(blocks)) if len(blocks[blockIndex]) == 0]
|
||||||
|
#print("Free blocks: ", freeBlocks)
|
||||||
|
#print("Begin attempt to move...")
|
||||||
while not done:
|
while not done:
|
||||||
classOut = blocks[index][moveIndex]
|
classOut = blocks[index][moveIndex]
|
||||||
|
#print("classOut: ",classOut)
|
||||||
found = False
|
found = False
|
||||||
|
#print("begin check for blocks in running...")
|
||||||
for block in running:
|
for block in running:
|
||||||
if found: break
|
#print("Block: ", block)
|
||||||
|
if found:
|
||||||
|
#print("Found, breaking check for blocks in running")
|
||||||
|
break
|
||||||
if list(running).index(block) != index and list(running).index(block) in freeBlocks:
|
if list(running).index(block) != index and list(running).index(block) in freeBlocks:
|
||||||
|
#print("This block is available, begin check for classes in this block")
|
||||||
for cname in running[block]:
|
for cname in running[block]:
|
||||||
|
#print("Class: ", cname)
|
||||||
if cname[:-2] == blocks[index][moveIndex][:-2] and len(running[block][cname]["students"]) < classCap:
|
if cname[:-2] == blocks[index][moveIndex][:-2] and len(running[block][cname]["students"]) < classCap:
|
||||||
|
#print("Exists! This class matches target and has space!")
|
||||||
studentData = {
|
studentData = {
|
||||||
"Pupil #": student["Pupil #"],
|
"Pupil #": student["Pupil #"],
|
||||||
"index": student["studentIndex"]
|
"index": student["studentIndex"]
|
||||||
@@ -412,24 +439,47 @@ def generateScheduleV3(
|
|||||||
running[block][cname]["students"].append(studentData)
|
running[block][cname]["students"].append(studentData)
|
||||||
|
|
||||||
found, done = True, True
|
found, done = True, True
|
||||||
|
#print("Found: ", found)
|
||||||
|
#print("done: ", done)
|
||||||
break
|
break
|
||||||
|
# else:
|
||||||
|
#print("This class does not match the target, or this class is full")
|
||||||
|
#print("Found: ", found)
|
||||||
|
# else:
|
||||||
|
#print("This block is the conflict, or is not free")
|
||||||
|
|
||||||
|
|
||||||
|
#print("end check for blocks in running...")
|
||||||
if not found:
|
if not found:
|
||||||
|
#print("Could not find a solution for this class")
|
||||||
if moveIndex < len(blocks[index])-1:
|
if moveIndex < len(blocks[index])-1:
|
||||||
|
#print("Trying next class")
|
||||||
moveIndex += 1
|
moveIndex += 1
|
||||||
elif moveIndex == len(blocks[index])-1:
|
elif moveIndex == len(blocks[index])-1:
|
||||||
|
#print("No more attempts possible, add to exceptions")
|
||||||
if index not in exceptions: exceptions.append(index)
|
if index not in exceptions: exceptions.append(index)
|
||||||
|
conflicts.append({
|
||||||
|
"Pupil #": student["Pupil #"],
|
||||||
|
"Email": "",
|
||||||
|
"Conflict": "Error"
|
||||||
|
})
|
||||||
|
done = True
|
||||||
|
hasConflict = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print('impossible err 3')
|
print('impossible err 3')
|
||||||
|
|
||||||
elif found: done = True
|
elif found:
|
||||||
|
done = True
|
||||||
|
#print("Done: ", done)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print('impossible err 2')
|
print('impossible err 2')
|
||||||
|
|
||||||
elif count == student["expectedClasses"]:
|
elif count == student["expectedClasses"]:
|
||||||
|
#print("No conflicts")
|
||||||
if len(exceptions) > 0:
|
if len(exceptions) > 0:
|
||||||
|
#print("Exceptions exist, new conflict 3: More than one class per block")
|
||||||
for i in range(len(exceptions)):
|
for i in range(len(exceptions)):
|
||||||
blocks[i] = origin[i]
|
blocks[i] = origin[i]
|
||||||
|
|
||||||
@@ -441,6 +491,7 @@ def generateScheduleV3(
|
|||||||
|
|
||||||
hasConflict = False
|
hasConflict = False
|
||||||
elif count > student["expectedClasses"]:
|
elif count > student["expectedClasses"]:
|
||||||
|
#print("New conflict 4: More classes than expected")
|
||||||
conflicts.append({
|
conflicts.append({
|
||||||
"Pupil #": student["Pupil #"],
|
"Pupil #": student["Pupil #"],
|
||||||
"Email": "",
|
"Email": "",
|
||||||
|
|||||||
@@ -45,6 +45,17 @@ if __name__ == '__main__':
|
|||||||
timetable["Version"] = 3
|
timetable["Version"] = 3
|
||||||
timetable["timetable"] = generateScheduleV3(sampleStudents, samplemockCourses, 40, "./output/students.json", "./output/conflicts.json")
|
timetable["timetable"] = generateScheduleV3(sampleStudents, samplemockCourses, 40, "./output/students.json", "./output/conflicts.json")
|
||||||
|
|
||||||
|
f = open('./output/conflicts.json')
|
||||||
|
conflicts = json.load(f)
|
||||||
|
|
||||||
|
print(f"{len(conflicts)}/{len(sampleStudents)} have errors")
|
||||||
|
percent = len(conflicts) / len(sampleStudents) * 100
|
||||||
|
|
||||||
|
print(f"{round(percent, 2)}% errors")
|
||||||
|
print(f"{100-(round(percent, 2))}% success")
|
||||||
|
|
||||||
|
f.close()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Invalid argument")
|
print("Invalid argument")
|
||||||
exit()
|
exit()
|
||||||
|
|||||||
Reference in new issue
Block a user