update error collection

This commit is contained in:
SowinskiBraeden committed 2022-05-16 15:48:21 -07:00
1 parent 1813f1e79f
commit 5c0d6d8279
2 files changed
+65 -93

No files matched your search

+53 -55
View File
@@ -43,6 +43,21 @@ from util.generateCourses import getSampleCourses
def getLineNumber(): return currentframe().f_back.f_lineno def getLineNumber(): return currentframe().f_back.f_lineno
def newConflict(pupilNum, email, type, code, description, logs):
if pupilNum in logs: logs[pupilNum].append({
"Pupil #": pupilNum,
"Email": email,
"Type": type,
"Code": code,
"Conflict": description
})
else: logs[pupilNum] = [{
"Pupil #": pupilNum,
"Email": email,
"Type": type,
"Code": code,
"Conflict": description
}]
minReq, median, classCap = 18, 24, 30 minReq, median, classCap = 18, 24, 30
mockStudents = [] mockStudents = []
@@ -350,6 +365,8 @@ def generateScheduleV3(
# Step 6 - Evaluate, move students to fix conflicts # Step 6 - Evaluate, move students to fix conflicts
conflictLogs = {} conflictLogs = {}
criticalCount, acceptableCount = 0, 0
c_mc_count, c_cr_count, a_mc_count = 0, 0, 0
for student in students: for student in students:
initialBlocks = [student["schedule"][block] for block in student["schedule"]] initialBlocks = [student["schedule"][block] for block in student["schedule"]]
@@ -358,8 +375,8 @@ def generateScheduleV3(
# If there is no conflicts # If there is no conflicts
# and classes inserted to is equal to expectedClasses # and classes inserted to is equal to expectedClasses
# or classes the student is inserted do is missing # or classes the student is inserted to is missing
# no more than two: # no more than two classes:
# continue to next student # continue to next student
if ( if (
not hasConflicts and ( not hasConflicts and (
@@ -489,28 +506,15 @@ def generateScheduleV3(
if classOutIndex < len(blocks[clashIndex]) - 1: classOutIndex += 1 if classOutIndex < len(blocks[clashIndex]) - 1: classOutIndex += 1
elif classOutIndex == len(blocks[clashIndex]) - 1: elif classOutIndex == len(blocks[clashIndex]) - 1:
if len(student["remainingAlts"]) > 0: if len(student["remainingAlts"]) > 0:
# pass
exceptions.append(clashIndex) exceptions.append(clashIndex)
print("Attempt to use alt")
attemptResolve = False attemptResolve = False
# Attempt to use alt # Attempt to use alt
elif len(student["remainingAlts"]) == 0: elif len(student["remainingAlts"]) == 0:
exceptions.append(clashIndex) exceptions.append(clashIndex)
if student["Pupil #"] in conflictLogs: criticalCount += 1
conflictLogs[student["Pupil #"]].append({ c_cr_count += 1
"Pupil #": student["Pupil #"], newConflict(student["Pupil #"], "", "Critical", "C-CR", "Couldn't Resolve", conflictLogs)
"Email": "",
"Type": "Critical",
"Code": "C-CR",
"Conflict": "Couldn't Resolve"
})
else:
conflictLogs[student["Pupil #"]] = [{
"Pupil #": student["Pupil #"],
"Email": "",
"Type": "Critical",
"Code": "C-CR",
"Conflict": "Couldn't Resolve"
}]
attemptResolve = False attemptResolve = False
else: print("Impossible - Thanos") else: print("Impossible - Thanos")
@@ -525,44 +529,20 @@ def generateScheduleV3(
while not metSelfRequirements: while not metSelfRequirements:
if (student["expectedClasses"] - 2) <= student["classes"] < student["expectedClasses"]: if (student["expectedClasses"] - 2) <= student["classes"] < student["expectedClasses"]:
if student["Pupil #"] in conflictLogs: a_mc_count += 1
conflictLogs[student["Pupil #"]].append({ acceptableCount += 1
"Pupil #": student["Pupil #"], newConflict(student["Pupil #"], "", "Acceptable", "A-MC", "Missing 1-2 Classses", conflictLogs)
"Email": "", break
"Type": "Acceptable",
"Code": "A-MC",
"Conflict": "Missing 1-2 classes"
})
else:
conflictLogs[student["Pupil #"]] = [{
"Pupil #": student["Pupil #"],
"Email": "",
"Type": "Acceptable",
"Code": "A-MC",
"Conflict": "Missing 1-2 classes"
}]
metSelfRequirements = True
elif student["classes"] < (student["expectedClasses"] - 2): elif student["classes"] < (student["expectedClasses"] - 2):
# Difference between classes inserted to and # Difference between classes inserted to and
# expected classes is too great, attempt to fix # expected classes is too great, attempt to fix
if student["Pupil #"] in conflictLogs: if student["Pupil #"] in conflictLogs:
conflictLogs[student["Pupil #"]].append({ c_mc_count += 1
"Pupil #": student["Pupil #"], criticalCount += 1
"Email": "", newConflict(student["Pupil #"], "", "Critical", "C-MC", "Missing too many Classses", conflictLogs)
"Type": "Critical",
"Code": "C-MC", break
"Conflict": "Missing too many classes"
})
else:
conflictLogs[student["Pupil #"]] = [{
"Pupil #": student["Pupil #"],
"Email": "",
"Type": "Critical",
"Code": "C-MC",
"Conflict": "Missing too many classes"
}]
metSelfRequirements = True
else: else:
print(f"Fatal error ({getLineNumber()}): Impossible error") print(f"Fatal error ({getLineNumber()}): Impossible error")
@@ -576,9 +556,27 @@ def generateScheduleV3(
elif conflict["Type"] == "Acceptable": acceptables.append(conflict) elif conflict["Type"] == "Acceptable": acceptables.append(conflict)
finalConflictLogs = { finalConflictLogs = {
"All": conflictLogs, "Conflicts": conflictLogs,
"Critical": criticals, "Critical": {
"Acceptable": acceptables "Total": criticalCount,
"Errors": [{
"Total": c_mc_count,
"Description": "Missing too many Classes",
"Code": "C-MC"
}, {
"Total": c_cr_count,
"Description": "Couldn't Resolve",
"Code": "C-CR"
}]
},
"Acceptable": {
"Total": acceptableCount,
"Errors": [{
"Total": a_mc_count,
"Description": "Missing 1-2 Classes",
"Code": "A-MC"
}]
}
} }
# Update Student records # Update Student records
+12 -38
View File
@@ -19,32 +19,18 @@ def errorOutput(students) -> Tuple[PrettyTable, dict, dict]:
f = open('./output/conflicts.json') f = open('./output/conflicts.json')
conflicts = json.load(f) conflicts = json.load(f)
f.close() f.close()
totalCritical = conflicts["Critical"]["Total"]
critical, acceptable = 0, 0 totalAcceptable = conflicts["Acceptable"]["Total"]
for student in conflicts["All"]:
studentHasCritical, studentHasAcceptable = False, False
read = False
for conflict in conflicts["All"][student]:
if read: break
if conflict["Type"] == "Critical":
critical += 1
studentHasCritical = True
if studentHasAcceptable: read = True
elif conflict["Type"] == "Acceptable":
acceptable += 1
studentHasAcceptable = True
if studentHasCritical: read = True
continue
t = PrettyTable(['Type', 'Error %', 'Success %', 'Error Ratio']) t = PrettyTable(['Type', 'Error %', 'Success %', 'Error Ratio'])
errorsC = round(critical / len(students) * 100, 2) errorsC = round(totalCritical / len(students) * 100, 2)
successC = round(100 - errorsC, 2) successC = round(100 - errorsC, 2)
errorsA = round(acceptable / len(students) * 100, 2) errorsA = round(totalAcceptable / len(students) * 100, 2)
successA = round(100 - errorsA, 2) successA = round(100 - errorsA, 2)
t.add_row(['Critical', f"{errorsC} %", f"{successC} %", f"{critical}/{len(students)}"]) t.add_row(['Critical', f"{errorsC} %", f"{successC} %", f"{totalCritical}/{len(students)}"])
t.add_row(['Acceptable', f"{errorsA} %", f"{successA} %", f"{acceptable}/{len(students)}"]) t.add_row(['Acceptable', f"{errorsA} %", f"{successA} %", f"{totalAcceptable}/{len(students)}"])
return t, conflicts["Critical"], conflicts["Acceptable"] return t, conflicts["Critical"], conflicts["Acceptable"]
@@ -92,25 +78,13 @@ if __name__ == '__main__':
print() print()
print(errors) print(errors)
print(f"\n{len(critical)} critical errors") print(f"\n{critical['Total']} critical errors")
c1, c2, co = 0, 0, 0 for i in range(len(critical["Errors"])):
for error in critical: print(f"x{critical['Errors'][i]['Total']} {critical['Errors'][i]['Code']} Errors: Critical - {critical['Errors'][i]['Description']}")
if error["Code"] == "C-MC": c1 +=1
elif error["Code"] == "C-CR": c2 += 1
else: co += 1
print(f"x{c1} C-MC Errors: Critical - Missing too many Classes") print(f"\n{acceptable['Total']} acceptable errors")
print(f"x{c2} C-CR Errors: Critical - Couldn't Resolve") for i in range(len(acceptable["Errors"])):
print(f"x{co} Other/Undefined Critical Errors") print(f"x{acceptable['Errors'][i]['Total']} {acceptable['Errors'][i]['Code']} Errors: Critical - {acceptable['Errors'][i]['Description']}")
print(f"\n{len(acceptable)} acceptable errors")
a1, ao = 0, 0
for error in acceptable:
if error["Code"] == "A-MC": a1 +=1
else: ao += 1
print(f"x{a1} A-MC Errors: Acceptable - Missing 1-2 Classes")
print(f"x{ao} Other/Undefined Acceptable Errors")
exit() exit()