update error logs and impossible exceptions step 6

This commit is contained in:
SowinskiBraeden committed 2022-05-12 12:54:29 -07:00
1 parent e50a779ec8
commit 803bdb8fdd
2 files changed
+33 -11

No files matched your search

+31 -9
View File
@@ -2,6 +2,7 @@
import json import json
import math import math
import random import random
from inspect import currentframe
# Import from custom utilities # Import from custom utilities
from util.mockStudents import getSampleStudents 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 minReq, median, classCap = 18, 24, 30
mockStudents = [] mockStudents = []
activeCourses = {} activeCourses = {}
@@ -373,23 +377,41 @@ def generateScheduleV3(
while hasConflicts: while hasConflicts:
# Check if conflicts have been resolved # Check if conflicts have been resolved
conflicts = sum(1 for b in block if len(b)>1) conflicts = sum(1 for b in block if len(b)>1)
if (
conflicts == 0 and if conflicts == 0: hasConflicts = False
student["classes"] < student["expectedClasses"] and
student["classes"] >= (student["expectedClasses"]-2) 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({ acceptableConflictLogs.append({
"Pupil #": student["Pupil #"], "Pupil #": student["Pupil #"],
"Email": "", "Email": "",
"Conflict": "Acceptable: Missing 1-2 classes" "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 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 # Update Student records
with open(studentsDir, "w") as outfile: with open(studentsDir, "w") as outfile:
@@ -397,7 +419,7 @@ def generateScheduleV3(
# Log Conflict to records # Log Conflict to records
with open(conflictsDir, "w") as outfile: with open(conflictsDir, "w") as outfile:
json.dump(conflicts, outfile, indent=2) json.dump(finalConflictLogs, outfile, indent=2)
return running return running
+2 -2
View File
@@ -48,8 +48,8 @@ if __name__ == '__main__':
f = open('./output/conflicts.json') f = open('./output/conflicts.json')
conflicts = json.load(f) conflicts = json.load(f)
print(f"{len(conflicts)}/{len(sampleStudents)} have errors") print(f"{len(conflicts['Fatal'])}/{len(sampleStudents)} have errors")
errors = round(len(conflicts) / len(sampleStudents) * 100, 2) errors = round(len(conflicts["Fatal"]) / len(sampleStudents) * 100, 2)
success = round(100 - errors, 2) success = round(100 - errors, 2)
print(f"{errors}% errors") print(f"{errors}% errors")