Use alternates last
This commit is contained in:
1 file changed
+42
-42
@@ -419,58 +419,58 @@ def generateScheduleV3(
|
|||||||
break
|
break
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
# Try alternate
|
# Determine all places class exists
|
||||||
alternates = [alt["CrsNo"] for alt in students[student["studentIndex"]]["remainingAlts"] if alt["CrsNo"] not in flex and alt["CrsNo"] in courseRunInfoCopy]
|
existsIn, existingClassNames = [], []
|
||||||
if len(alternates) == 0: # If not alternates, create critical error
|
for block in running:
|
||||||
# Determine all places class exists
|
for cname in running[block]:
|
||||||
existsIn, existingClassNames = [], []
|
if cname[:-2] == classes[index] and len(running[block][cname]["students"]) < classCap:
|
||||||
for block in running:
|
existsIn.append(block)
|
||||||
for cname in running[block]:
|
existingClassNames.append(cname)
|
||||||
if cname[:-2] == classes[index] and len(running[block][cname]["students"]) < classCap:
|
|
||||||
existsIn.append(block)
|
|
||||||
existingClassNames.append(cname)
|
|
||||||
|
|
||||||
# Attempt to fix
|
# Attempt to fix
|
||||||
solution = False
|
solution = False
|
||||||
if len(existsIn) > 0:
|
if len(existsIn) > 0:
|
||||||
for i, existing in enumerate(existsIn):
|
for i, existing in enumerate(existsIn):
|
||||||
|
if solution: break
|
||||||
|
classOut = student["schedule"][existing][0]
|
||||||
|
for block in running:
|
||||||
if solution: break
|
if solution: break
|
||||||
classOut = student["schedule"][existing][0]
|
if block == existing or block not in availableBlocks: continue
|
||||||
for block in running:
|
for cname in running[block]:
|
||||||
if solution: break
|
if cname[:-2] == classOut[:-2] and len(running[block][cname]["students"]) < classCap:
|
||||||
if block == existing or block not in availableBlocks: continue
|
# Move to existing class elsewhere
|
||||||
for cname in running[block]:
|
student["schedule"][block].append(cname)
|
||||||
if cname[:-2] == classOut[:-2] and len(running[block][cname]["students"]) < classCap:
|
running[block][cname]["students"].append(studentData)
|
||||||
# Move to existing class elsewhere
|
|
||||||
student["schedule"][block].append(cname)
|
|
||||||
running[block][cname]["students"].append(studentData)
|
|
||||||
|
|
||||||
# Overwrite old class
|
# Overwrite old class
|
||||||
running[existing][student["schedule"][existing][0]]["students"].remove(studentData)
|
running[existing][student["schedule"][existing][0]]["students"].remove(studentData)
|
||||||
student["schedule"][existing][0] = existingClassNames[i]
|
student["schedule"][existing][0] = existingClassNames[i]
|
||||||
running[existing][existingClassNames[i]]["students"].append(studentData)
|
running[existing][existingClassNames[i]]["students"].append(studentData)
|
||||||
|
|
||||||
solution = True
|
solution = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if not solution:
|
if not solution:
|
||||||
|
# Try alternate
|
||||||
|
alternates = [alt["CrsNo"] for alt in students[student["studentIndex"]]["remainingAlts"] if alt["CrsNo"] not in flex and alt["CrsNo"] in courseRunInfoCopy]
|
||||||
|
if len(alternates) == 0: # If not alternates, create critical error
|
||||||
c_cr_count += 1
|
c_cr_count += 1
|
||||||
criticalCount += 1
|
criticalCount += 1
|
||||||
if not newConflict(student["Pupil #"], "", "Critical", "C-CR", "Couldn't Resolve", conflictLogs): studentsCritical += 1
|
if not newConflict(student["Pupil #"], "", "Critical", "C-CR", "Couldn't Resolve", conflictLogs): studentsCritical += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Get alternate least run
|
# Get alternate least run
|
||||||
altRunCounts = [courseRunInfoCopy[alt]["Total"] for alt in alternates]
|
altRunCounts = [courseRunInfoCopy[alt]["Total"] for alt in alternates]
|
||||||
altIndex = altRunCounts.index(min(altRunCounts))
|
altIndex = altRunCounts.index(min(altRunCounts))
|
||||||
|
|
||||||
# add alternate
|
# add alternate
|
||||||
classes.append(alternates[altIndex])
|
classes.append(alternates[altIndex])
|
||||||
runCounts.append(altRunCounts[altIndex])
|
runCounts.append(altRunCounts[altIndex])
|
||||||
|
|
||||||
# Remove alternate from remaining alternates
|
# Remove alternate from remaining alternates
|
||||||
for remaining in students[student["studentIndex"]]["remainingAlts"]:
|
for remaining in students[student["studentIndex"]]["remainingAlts"]:
|
||||||
if remaining["CrsNo"] == alternates[altIndex]:
|
if remaining["CrsNo"] == alternates[altIndex]:
|
||||||
students[student["studentIndex"]]["remainingAlts"].remove(remaining)
|
students[student["studentIndex"]]["remainingAlts"].remove(remaining)
|
||||||
|
|
||||||
# Remove class after inserted or failed to insert
|
# Remove class after inserted or failed to insert
|
||||||
classes.remove(classes[index])
|
classes.remove(classes[index])
|
||||||
|
|||||||
Reference in new issue
Block a user