diff --git a/test/scheduleGenerator/v3.py b/test/scheduleGenerator/v3.py index 400027c..1970d21 100644 --- a/test/scheduleGenerator/v3.py +++ b/test/scheduleGenerator/v3.py @@ -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: + # Get clash + if len(exceptions) > 0: + blocks = [elem for i, elem in enumerate(blocks) if i not in exceptions] + 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] - - # 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']) - 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 diff --git a/test/util/mockStudents.py b/test/util/mockStudents.py index c767608..6c3abc3 100644 --- a/test/util/mockStudents.py +++ b/test/util/mockStudents.py @@ -47,10 +47,12 @@ def getSampleStudents(data_dir: str, log: bool = False) -> list[dict]: alternate = True if row["Alternate?"] == 'TRUE' else False if exists: mockStudents[student["studentIndex"]]["requests"].append({ - "CrsNo": row["CrsNo"], - "Description": row["Description"], - "alt": alternate - }) + "CrsNo": row["CrsNo"], + "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)