update error collection
This commit is contained in:
1 parent
1813f1e79f
commit
5c0d6d8279
2 files changed
+65
-93
No files matched your search
@@ -43,6 +43,21 @@ from util.generateCourses import getSampleCourses
|
||||
|
||||
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
|
||||
mockStudents = []
|
||||
@@ -350,6 +365,8 @@ def generateScheduleV3(
|
||||
|
||||
# Step 6 - Evaluate, move students to fix conflicts
|
||||
conflictLogs = {}
|
||||
criticalCount, acceptableCount = 0, 0
|
||||
c_mc_count, c_cr_count, a_mc_count = 0, 0, 0
|
||||
|
||||
for student in students:
|
||||
initialBlocks = [student["schedule"][block] for block in student["schedule"]]
|
||||
@@ -358,8 +375,8 @@ def generateScheduleV3(
|
||||
|
||||
# If there is no conflicts
|
||||
# and classes inserted to is equal to expectedClasses
|
||||
# or classes the student is inserted do is missing
|
||||
# no more than two:
|
||||
# or classes the student is inserted to is missing
|
||||
# no more than two classes:
|
||||
# continue to next student
|
||||
if (
|
||||
not hasConflicts and (
|
||||
@@ -489,28 +506,15 @@ def generateScheduleV3(
|
||||
if classOutIndex < len(blocks[clashIndex]) - 1: classOutIndex += 1
|
||||
elif classOutIndex == len(blocks[clashIndex]) - 1:
|
||||
if len(student["remainingAlts"]) > 0:
|
||||
# pass
|
||||
exceptions.append(clashIndex)
|
||||
print("Attempt to use alt")
|
||||
attemptResolve = False
|
||||
# Attempt to use alt
|
||||
elif len(student["remainingAlts"]) == 0:
|
||||
exceptions.append(clashIndex)
|
||||
if student["Pupil #"] in conflictLogs:
|
||||
conflictLogs[student["Pupil #"]].append({
|
||||
"Pupil #": student["Pupil #"],
|
||||
"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"
|
||||
}]
|
||||
criticalCount += 1
|
||||
c_cr_count += 1
|
||||
newConflict(student["Pupil #"], "", "Critical", "C-CR", "Couldn't Resolve", conflictLogs)
|
||||
|
||||
attemptResolve = False
|
||||
else: print("Impossible - Thanos")
|
||||
@@ -525,44 +529,20 @@ def generateScheduleV3(
|
||||
while not metSelfRequirements:
|
||||
|
||||
if (student["expectedClasses"] - 2) <= student["classes"] < student["expectedClasses"]:
|
||||
if student["Pupil #"] in conflictLogs:
|
||||
conflictLogs[student["Pupil #"]].append({
|
||||
"Pupil #": student["Pupil #"],
|
||||
"Email": "",
|
||||
"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
|
||||
a_mc_count += 1
|
||||
acceptableCount += 1
|
||||
newConflict(student["Pupil #"], "", "Acceptable", "A-MC", "Missing 1-2 Classses", conflictLogs)
|
||||
break
|
||||
|
||||
elif student["classes"] < (student["expectedClasses"] - 2):
|
||||
# Difference between classes inserted to and
|
||||
# expected classes is too great, attempt to fix
|
||||
if student["Pupil #"] in conflictLogs:
|
||||
conflictLogs[student["Pupil #"]].append({
|
||||
"Pupil #": student["Pupil #"],
|
||||
"Email": "",
|
||||
"Type": "Critical",
|
||||
"Code": "C-MC",
|
||||
"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
|
||||
c_mc_count += 1
|
||||
criticalCount += 1
|
||||
newConflict(student["Pupil #"], "", "Critical", "C-MC", "Missing too many Classses", conflictLogs)
|
||||
|
||||
break
|
||||
|
||||
else:
|
||||
print(f"Fatal error ({getLineNumber()}): Impossible error")
|
||||
@@ -576,9 +556,27 @@ def generateScheduleV3(
|
||||
elif conflict["Type"] == "Acceptable": acceptables.append(conflict)
|
||||
|
||||
finalConflictLogs = {
|
||||
"All": conflictLogs,
|
||||
"Critical": criticals,
|
||||
"Acceptable": acceptables
|
||||
"Conflicts": conflictLogs,
|
||||
"Critical": {
|
||||
"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
|
||||
|
||||
+12
-38
@@ -19,32 +19,18 @@ def errorOutput(students) -> Tuple[PrettyTable, dict, dict]:
|
||||
f = open('./output/conflicts.json')
|
||||
conflicts = json.load(f)
|
||||
f.close()
|
||||
|
||||
critical, acceptable = 0, 0
|
||||
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
|
||||
totalCritical = conflicts["Critical"]["Total"]
|
||||
totalAcceptable = conflicts["Acceptable"]["Total"]
|
||||
|
||||
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)
|
||||
errorsA = round(acceptable / len(students) * 100, 2)
|
||||
errorsA = round(totalAcceptable / len(students) * 100, 2)
|
||||
successA = round(100 - errorsA, 2)
|
||||
|
||||
t.add_row(['Critical', f"{errorsC} %", f"{successC} %", f"{critical}/{len(students)}"])
|
||||
t.add_row(['Acceptable', f"{errorsA} %", f"{successA} %", f"{acceptable}/{len(students)}"])
|
||||
t.add_row(['Critical', f"{errorsC} %", f"{successC} %", f"{totalCritical}/{len(students)}"])
|
||||
t.add_row(['Acceptable', f"{errorsA} %", f"{successA} %", f"{totalAcceptable}/{len(students)}"])
|
||||
|
||||
return t, conflicts["Critical"], conflicts["Acceptable"]
|
||||
|
||||
@@ -92,25 +78,13 @@ if __name__ == '__main__':
|
||||
print()
|
||||
print(errors)
|
||||
|
||||
print(f"\n{len(critical)} critical errors")
|
||||
c1, c2, co = 0, 0, 0
|
||||
for error in critical:
|
||||
if error["Code"] == "C-MC": c1 +=1
|
||||
elif error["Code"] == "C-CR": c2 += 1
|
||||
else: co += 1
|
||||
print(f"\n{critical['Total']} critical errors")
|
||||
for i in range(len(critical["Errors"])):
|
||||
print(f"x{critical['Errors'][i]['Total']} {critical['Errors'][i]['Code']} Errors: Critical - {critical['Errors'][i]['Description']}")
|
||||
|
||||
print(f"x{c1} C-MC Errors: Critical - Missing too many Classes")
|
||||
print(f"x{c2} C-CR Errors: Critical - Couldn't Resolve")
|
||||
print(f"x{co} Other/Undefined Critical Errors")
|
||||
|
||||
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")
|
||||
print(f"\n{acceptable['Total']} acceptable errors")
|
||||
for i in range(len(acceptable["Errors"])):
|
||||
print(f"x{acceptable['Errors'][i]['Total']} {acceptable['Errors'][i]['Code']} Errors: Critical - {acceptable['Errors'][i]['Description']}")
|
||||
|
||||
exit()
|
||||
|
||||
|
||||
Reference in new issue
Block a user