conflict log dataclass
This commit is contained in:
1 file changed
+27
-17
+27
-17
@@ -2,12 +2,22 @@
|
|||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
from string import hexdigits
|
from string import hexdigits
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from app.util.globals import flex, Error
|
from app.util.globals import flex, Error
|
||||||
from app.util.estimateGrade import getGrade
|
from app.util.estimateGrade import getGrade
|
||||||
from app.util.students import Student, studentsToDict
|
from app.util.students import Student, studentsToDict
|
||||||
from app.util.courses import Course, coursesToDict
|
from app.util.courses import Course, coursesToDict
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Conflict:
|
||||||
|
PupilNum: str
|
||||||
|
Email: str
|
||||||
|
Type: str
|
||||||
|
Code: str
|
||||||
|
Conflict: str
|
||||||
|
Missing: list = None
|
||||||
|
|
||||||
# Takes in information to create or add a new conflict
|
# Takes in information to create or add a new conflict
|
||||||
# Returns if the particular student has a previous error
|
# Returns if the particular student has a previous error
|
||||||
def newConflict(
|
def newConflict(
|
||||||
@@ -16,28 +26,28 @@ def newConflict(
|
|||||||
conflictType: str,
|
conflictType: str,
|
||||||
code: str,
|
code: str,
|
||||||
description: str,
|
description: str,
|
||||||
logs: dict
|
logs: dict[str: list[Conflict]]
|
||||||
) -> bool:
|
) -> bool:
|
||||||
exists = True if pupilNum in logs else False
|
exists = True if pupilNum in logs else False
|
||||||
log = {
|
log = Conflict(
|
||||||
"Pupil #": pupilNum,
|
pupilNum,
|
||||||
"Email": email,
|
email,
|
||||||
"Type": conflictType,
|
conflictType,
|
||||||
"Code": code,
|
code,
|
||||||
"Conflict": description
|
description
|
||||||
}
|
)
|
||||||
if exists: logs[pupilNum].append(log)
|
if exists: logs[pupilNum].append(log)
|
||||||
else: logs[pupilNum] = [log]
|
else: logs[pupilNum] = [log]
|
||||||
return exists if conflictType == "Critical" else False
|
return exists if conflictType == "Critical" else False
|
||||||
|
|
||||||
def insertConflictSolutions(
|
def insertConflictSolutions(
|
||||||
pupilNum: str,
|
pupilNum: str,
|
||||||
logs: dict,
|
logs: dict[str: list[Conflict]],
|
||||||
data: dict
|
data: list[dict[str: any]]
|
||||||
) -> None:
|
) -> None:
|
||||||
for conflict in logs[pupilNum]:
|
for conflict in logs[pupilNum]:
|
||||||
if conflict["Type"] == "Critical":
|
if conflict.Type == "Critical":
|
||||||
conflict["Missing"] = data
|
conflict.Missing = data
|
||||||
break
|
break
|
||||||
|
|
||||||
# V3 differs a lot by V1/2 as it does not focus on fitting the classes
|
# V3 differs a lot by V1/2 as it does not focus on fitting the classes
|
||||||
@@ -330,7 +340,7 @@ def generateScheduleV3(
|
|||||||
|
|
||||||
|
|
||||||
# Step 6 - Evaluate, move students to fix conflicts
|
# Step 6 - Evaluate, move students to fix conflicts
|
||||||
conflictLogs = {}
|
conflictLogs: dict[str: list[Conflict]] = {}
|
||||||
criticalCount, acceptableCount = 0, 0
|
criticalCount, acceptableCount = 0, 0
|
||||||
c_mc_count, c_cr_count, a_mc_count = 0, 0, 0
|
c_mc_count, c_cr_count, a_mc_count = 0, 0, 0
|
||||||
studentsCritical, studentsAcceptable = 0, 0
|
studentsCritical, studentsAcceptable = 0, 0
|
||||||
@@ -463,14 +473,14 @@ def generateScheduleV3(
|
|||||||
classes.remove(classes[index])
|
classes.remove(classes[index])
|
||||||
runCounts.remove(runCounts[index])
|
runCounts.remove(runCounts[index])
|
||||||
|
|
||||||
# Collect missing course data and solutions
|
# Collect missing course data and
|
||||||
|
|
||||||
if len(missing) > 0:
|
if len(missing) > 0:
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
if student.Gradelevel is None:
|
if student.Gradelevel is None:
|
||||||
for obj in missing:
|
for obj in missing:
|
||||||
data["missing"].append({
|
data.append({
|
||||||
"CrsNo": obj["CrsNo"],
|
"CrsNo": obj["CrsNo"],
|
||||||
"block": obj['block'],
|
"block": obj['block'],
|
||||||
"solutions": None,
|
"solutions": None,
|
||||||
@@ -511,8 +521,8 @@ def generateScheduleV3(
|
|||||||
criticalCount += 1
|
criticalCount += 1
|
||||||
if not newConflict(student.PupilNum, "", "Critical", "C-MC", "Missing too many Classses", conflictLogs): studentsCritical += 1
|
if not newConflict(student.PupilNum, "", "Critical", "C-MC", "Missing too many Classses", conflictLogs): studentsCritical += 1
|
||||||
|
|
||||||
finalConflictLogs = {
|
finalConflictLogs: dict[str: any] = {
|
||||||
"Conflicts": conflictLogs,
|
"Conflicts": {s: [c.__dict__ for c in conflictLogs[s]] for s in conflictLogs},
|
||||||
"Critical": {
|
"Critical": {
|
||||||
"Total": criticalCount,
|
"Total": criticalCount,
|
||||||
"Students": studentsCritical,
|
"Students": studentsCritical,
|
||||||
|
|||||||
Reference in new issue
Block a user