update error logs and impossible exceptions step 6
This commit is contained in:
1 parent
e50a779ec8
commit
803bdb8fdd
2 files changed
+33
-11
No files matched your search
@@ -2,6 +2,7 @@
|
||||
import json
|
||||
import math
|
||||
import random
|
||||
from inspect import currentframe
|
||||
|
||||
# Import from custom utilities
|
||||
from util.mockStudents import getSampleStudents
|
||||
@@ -38,6 +39,9 @@ from util.generateCourses import getSampleCourses
|
||||
}
|
||||
'''
|
||||
|
||||
def getLineNumber(): return currentframe().f_back.f_lineno
|
||||
|
||||
|
||||
minReq, median, classCap = 18, 24, 30
|
||||
mockStudents = []
|
||||
activeCourses = {}
|
||||
@@ -373,23 +377,41 @@ def generateScheduleV3(
|
||||
while hasConflicts:
|
||||
# Check if conflicts have been resolved
|
||||
conflicts = sum(1 for b in block if len(b)>1)
|
||||
if (
|
||||
conflicts == 0 and
|
||||
student["classes"] < student["expectedClasses"] and
|
||||
student["classes"] >= (student["expectedClasses"]-2)
|
||||
):
|
||||
|
||||
if conflicts == 0: hasConflicts = False
|
||||
|
||||
elif conflicts > 0:
|
||||
blocks = [student["scheudle"][block] for block in student["schedule"]]
|
||||
|
||||
else:
|
||||
print(f"Fatal error ({getLineNumber()}): Impossible error")
|
||||
continue
|
||||
|
||||
metSelfRequirements = False
|
||||
while not metSelfRequirements:
|
||||
if student["classes"] == student["expectedClasses"]: metSelfRequirements = True
|
||||
|
||||
elif (student["expectedClasses"] - 2) <= student["classes"] < student["expectedClasses"]:
|
||||
acceptableConflictLogs.append({
|
||||
"Pupil #": student["Pupil #"],
|
||||
"Email": "",
|
||||
"Conflict": "Acceptable: Missing 1-2 classes"
|
||||
})
|
||||
hasConflicts = False
|
||||
metSelfRequirements = True
|
||||
|
||||
elif conflicts > 0:
|
||||
elif student["classes"] < (student["expectedClasses"] - 2):
|
||||
# Difference between classes inserted to and
|
||||
# expected classes is too great, attempt to fix
|
||||
pass
|
||||
|
||||
else:
|
||||
print(f"Fatal error ({getLineNumber()}): Impossible error")
|
||||
continue
|
||||
|
||||
# If difference is too great, attempt to fix
|
||||
finalConflictLogs = {
|
||||
"Fatal": conflictLogs,
|
||||
"Acceptable": acceptableConflictLogs
|
||||
}
|
||||
|
||||
# Update Student records
|
||||
with open(studentsDir, "w") as outfile:
|
||||
@@ -397,7 +419,7 @@ def generateScheduleV3(
|
||||
|
||||
# Log Conflict to records
|
||||
with open(conflictsDir, "w") as outfile:
|
||||
json.dump(conflicts, outfile, indent=2)
|
||||
json.dump(finalConflictLogs, outfile, indent=2)
|
||||
|
||||
return running
|
||||
|
||||
|
||||
+2
-2
@@ -48,8 +48,8 @@ if __name__ == '__main__':
|
||||
f = open('./output/conflicts.json')
|
||||
conflicts = json.load(f)
|
||||
|
||||
print(f"{len(conflicts)}/{len(sampleStudents)} have errors")
|
||||
errors = round(len(conflicts) / len(sampleStudents) * 100, 2)
|
||||
print(f"{len(conflicts['Fatal'])}/{len(sampleStudents)} have errors")
|
||||
errors = round(len(conflicts["Fatal"]) / len(sampleStudents) * 100, 2)
|
||||
success = round(100 - errors, 2)
|
||||
|
||||
print(f"{errors}% errors")
|
||||
|
||||
Reference in new issue
Block a user