work on step 6
This commit is contained in:
1 parent
bfaacebc2d
commit
9a4c3916eb
3 files changed
+26
-22
No files matched your search
@@ -341,12 +341,15 @@ def generateScheduleV3(
|
|||||||
students[student["index"]]["classes"] += 1
|
students[student["index"]]["classes"] += 1
|
||||||
|
|
||||||
|
|
||||||
|
with open("./output/timetable.json", "w") as outfile:
|
||||||
|
json.dump(running, outfile, indent=2)
|
||||||
|
|
||||||
# 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("====New Student====")
|
# print("====New Student====")
|
||||||
# print(student["Pupil #"])
|
print(student["Pupil #"])
|
||||||
blocks = [student["schedule"][block] for block in student["schedule"]]
|
blocks = [student["schedule"][block] for block in student["schedule"]]
|
||||||
# print("Blocks: ", blocks)
|
# print("Blocks: ", blocks)
|
||||||
origin = list(block)
|
origin = list(block)
|
||||||
@@ -373,16 +376,23 @@ def generateScheduleV3(
|
|||||||
# Get clash
|
# Get clash
|
||||||
if len(exceptions) > 0:
|
if len(exceptions) > 0:
|
||||||
# print("Exceptions exists, make new list to ignore exceptions")
|
# print("Exceptions exists, make new list to ignore 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:
|
||||||
minIndex = exceptCopy.index(min(exceptCopy))
|
minIndex = exceptCopy.index(min(exceptCopy))
|
||||||
blocks.insert(minIndex, ['nil'])
|
blocks[minIndex] = ['nil']
|
||||||
|
exceptCopy.remove(min(exceptCopy))
|
||||||
|
|
||||||
count = sum(1 for b in blocks if len(b)==1)
|
count = sum(1 for b in blocks if len(b)==1)
|
||||||
|
c = sum(1 for b in blocks if len(b)>1)
|
||||||
|
if c == 0:
|
||||||
|
hasConflict = False
|
||||||
|
student["classes"] = c
|
||||||
|
break
|
||||||
# print("New Count: ", count)
|
# print("New Count: ", count)
|
||||||
|
|
||||||
if count < student["expectedClasses"]:
|
if count < student["expectedClasses"]:
|
||||||
|
# print(student["expectedClasses"])
|
||||||
|
# print(student["classes"])
|
||||||
# print("There must be a clash...")
|
# print("There must be a clash...")
|
||||||
if count == student["classes"]:
|
if count == student["classes"]:
|
||||||
# print("New Conflict 2: Missing Classes")
|
# print("New Conflict 2: Missing Classes")
|
||||||
@@ -413,29 +423,29 @@ def generateScheduleV3(
|
|||||||
# print("classOut: ",classOut)
|
# print("classOut: ",classOut)
|
||||||
found = False
|
found = False
|
||||||
# print("begin check for blocks in running...")
|
# print("begin check for blocks in running...")
|
||||||
for block in running:
|
for blockIndex in freeBlocks:
|
||||||
#print("Block: ", block)
|
# print("Block index: ", blockIndex)
|
||||||
if found:
|
if found:
|
||||||
# print("Found, breaking check for blocks in running")
|
# print("Found, breaking check for blocks in running")
|
||||||
break
|
break
|
||||||
if list(running).index(block) != index and list(running).index(block) in freeBlocks:
|
if blockIndex != index:
|
||||||
|
block = list(running)[blockIndex]
|
||||||
# print("This block is available, begin check for classes in this block")
|
# 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)
|
# print("Class: ", cname)
|
||||||
if cname[:-2] == blocks[index][moveIndex][:-2] and len(running[block][cname]["students"]) < classCap:
|
if cname[:-2] == classOut[:-2] and len(running[block][cname]["students"]) < classCap:
|
||||||
# print("Exists! This class matches target and has space!")
|
# print("Exists! This class matches target and has space!")
|
||||||
studentData = {
|
studentData = {
|
||||||
"Pupil #": student["Pupil #"],
|
"Pupil #": student["Pupil #"],
|
||||||
"index": student["studentIndex"]
|
"index": student["studentIndex"]
|
||||||
}
|
}
|
||||||
studentIndex = running[blockOut][classOut]["students"].index(studentData)
|
|
||||||
|
|
||||||
# Update current blocks to work with
|
# Update current blocks to work with
|
||||||
blocks[index].remove(classOut)
|
blocks[index].remove(classOut)
|
||||||
blocks[list(running).index(block)].append(cname)
|
blocks[blockIndex].append(cname)
|
||||||
|
|
||||||
# Update Final Records
|
# Update Final Records
|
||||||
del running[blockOut][classOut]["students"][studentIndex] # Remove final
|
running[blockOut][classOut]["students"].remove(studentData) # Remove final
|
||||||
running[block][cname]["students"].append(studentData)
|
running[block][cname]["students"].append(studentData)
|
||||||
|
|
||||||
found, done = True, True
|
found, done = True, True
|
||||||
@@ -444,11 +454,9 @@ def generateScheduleV3(
|
|||||||
break
|
break
|
||||||
# else:
|
# else:
|
||||||
# print("This class does not match the target, or this class is full")
|
# print("This class does not match the target, or this class is full")
|
||||||
#print("Found: ", found)
|
|
||||||
# else:
|
# else:
|
||||||
# print("This block is the conflict, or is not free")
|
# print("This block is the conflict, or is not free")
|
||||||
|
|
||||||
|
|
||||||
# print("end check for blocks in running...")
|
# print("end check for blocks in running...")
|
||||||
if not found:
|
if not found:
|
||||||
# print("Could not find a solution for this class")
|
# print("Could not find a solution for this class")
|
||||||
@@ -458,13 +466,7 @@ def generateScheduleV3(
|
|||||||
elif moveIndex == len(blocks[index])-1:
|
elif moveIndex == len(blocks[index])-1:
|
||||||
# print("No more attempts possible, add to exceptions")
|
# 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
|
done = True
|
||||||
hasConflict = False
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print('impossible err 3')
|
print('impossible err 3')
|
||||||
|
|||||||
+4
-3
@@ -49,10 +49,11 @@ if __name__ == '__main__':
|
|||||||
conflicts = json.load(f)
|
conflicts = json.load(f)
|
||||||
|
|
||||||
print(f"{len(conflicts)}/{len(sampleStudents)} have errors")
|
print(f"{len(conflicts)}/{len(sampleStudents)} have errors")
|
||||||
percent = len(conflicts) / len(sampleStudents) * 100
|
errors = round(len(conflicts) / len(sampleStudents) * 100, 2)
|
||||||
|
success = round(100 - errors, 2)
|
||||||
|
|
||||||
print(f"{round(percent, 2)}% errors")
|
print(f"{errors}% errors")
|
||||||
print(f"{100-(round(percent, 2))}% success")
|
print(f"{success}% success")
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|||||||
@@ -46,12 +46,13 @@ def getSampleStudents(data_dir: str, log: bool = False) -> list[dict]:
|
|||||||
if exists: break
|
if exists: break
|
||||||
alternate = True if row["Alternate?"] == 'TRUE' else False
|
alternate = True if row["Alternate?"] == 'TRUE' else False
|
||||||
if exists:
|
if exists:
|
||||||
|
if not alternate and len(mockStudents[student["studentIndex"]]["requests"]) >= 10: alternate = True
|
||||||
mockStudents[student["studentIndex"]]["requests"].append({
|
mockStudents[student["studentIndex"]]["requests"].append({
|
||||||
"CrsNo": row["CrsNo"],
|
"CrsNo": row["CrsNo"],
|
||||||
"Description": row["Description"],
|
"Description": row["Description"],
|
||||||
"alt": alternate
|
"alt": alternate
|
||||||
})
|
})
|
||||||
if row["CrsNo"] not in ["XAT--12A-S", "XAT--12B-S"] and not alternate:
|
if row["CrsNo"] not in ["XAT--12A-S", "XAT--12B-S"] and not alternate and mockStudents[student["studentIndex"]]["expectedClasses"] < 10:
|
||||||
mockStudents[student["studentIndex"]]["expectedClasses"] += 1
|
mockStudents[student["studentIndex"]]["expectedClasses"] += 1
|
||||||
else:
|
else:
|
||||||
newStudent = {
|
newStudent = {
|
||||||
|
|||||||
Reference in new issue
Block a user