debug step 4 perf. issues
This commit is contained in:
commit
3d0b57793f
11 files changed
+13983
No files matched your search
@@ -0,0 +1,26 @@
|
||||
#! python
|
||||
import json
|
||||
|
||||
# Get students
|
||||
try:
|
||||
with open("../output/students.json") as studentFile: students = json.load(studentFile)
|
||||
except FileNotFoundError:
|
||||
with open("./output/students.json") as studentFile: students = json.load(studentFile)
|
||||
|
||||
flex = ("XAT--12A-S", "XAT--12B-S")
|
||||
|
||||
most_frequent = lambda l : max(set(l), key = l.count)
|
||||
|
||||
def getEstimatedGrade(pupil: dict) -> int:
|
||||
grades = [] # List of all possible grades
|
||||
for request in pupil["requests"]:
|
||||
if request["CrsNo"] in flex: continue
|
||||
for extractedGrade in [int(s) for s in request["CrsNo"].split("-") if s.isdigit()]:
|
||||
grades.append(extractedGrade)
|
||||
|
||||
return None if len(grades) == 0 else most_frequent(grades) # Final estimate of grade
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Define students grade level
|
||||
for student in students:
|
||||
student["gradelevel"] = getEstimatedGrade(student)
|
||||
@@ -0,0 +1,36 @@
|
||||
#! python
|
||||
import json
|
||||
import csv
|
||||
|
||||
realCourses = {}
|
||||
|
||||
# Get all courses from real sample data
|
||||
def getSampleCourses(data_dir, log=False) -> dict:
|
||||
with open(data_dir, newline='') as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
exists = False
|
||||
for course in realCourses:
|
||||
exists = True if realCourses[course]["CrsNo"] == row["CrsNo"] else False
|
||||
if exists: break
|
||||
if not exists:
|
||||
realCourses[row["CrsNo"]] = {
|
||||
"CrsNo": row["CrsNo"],
|
||||
"Requests": 0,
|
||||
"Description": row["Description"],
|
||||
"Credits": 4,
|
||||
"students": []
|
||||
}
|
||||
|
||||
if log:
|
||||
with open("./output/courses.json", "w") as outfile:
|
||||
json.dump(realCourses, outfile, indent=2)
|
||||
|
||||
return realCourses
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
courseSet: dict = getSampleCourses("../sample_data/course_selection_data.csv")
|
||||
|
||||
with open("../output/courses.json", "w") as outfile:
|
||||
json.dump(courseSet, outfile, indent=2)
|
||||
@@ -0,0 +1,68 @@
|
||||
#! python
|
||||
import json
|
||||
import csv
|
||||
|
||||
flex= ("XAT--12A-S", "XAT--12B-S")
|
||||
|
||||
mockStudents: list[dict] = []
|
||||
|
||||
# sort real sample data into usable dictionary
|
||||
def getSampleStudents(data_dir: str, log: bool = False) -> list[dict]:
|
||||
with open(data_dir, newline='') as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
exists = False
|
||||
for student in mockStudents:
|
||||
exists = True if student["Pupil #"] == row["Pupil #"] else False
|
||||
if exists: break
|
||||
alternate = True if row["Alternate?"] == 'TRUE' else False
|
||||
if exists:
|
||||
if len(mockStudents[student["studentIndex"]]["requests"]) >= 10 and not alternate and row["CrsNo"] not in flex: alternate = True
|
||||
mockStudents[student["studentIndex"]]["requests"].append({
|
||||
"CrsNo": row["CrsNo"],
|
||||
"Description": row["Description"],
|
||||
"alt": alternate
|
||||
})
|
||||
if row["CrsNo"] not in flex and not alternate and mockStudents[student["studentIndex"]]["expectedClasses"] < 10:
|
||||
mockStudents[student["studentIndex"]]["expectedClasses"] += 1
|
||||
else:
|
||||
newStudent = {
|
||||
"Pupil #": row["Pupil #"],
|
||||
"requests": [{
|
||||
"CrsNo": row["CrsNo"],
|
||||
"Description": row["Description"],
|
||||
"alt": alternate
|
||||
}],
|
||||
"schedule": {
|
||||
"block1": [],
|
||||
"block2": [],
|
||||
"block3": [],
|
||||
"block4": [],
|
||||
"block5": [],
|
||||
"block6": [],
|
||||
"block7": [],
|
||||
"block8": [],
|
||||
"block9": [],
|
||||
"block10": []
|
||||
},
|
||||
"expectedClasses": 1,
|
||||
"classes": 0,
|
||||
"remainingAlts": [],
|
||||
"studentIndex": len(mockStudents)
|
||||
}
|
||||
mockStudents.append(newStudent)
|
||||
|
||||
if log:
|
||||
with open("./output/students.json", "w") as outfile:
|
||||
json.dump(mockStudents, outfile, indent=2)
|
||||
|
||||
return mockStudents
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
studentRequests: list[dict] = getSampleStudents("../sample_data/course_selection_data.csv")
|
||||
|
||||
with open("../output/students.json", "w") as outfile:
|
||||
json.dump(studentRequests, outfile, indent=2)
|
||||
|
||||
print("done")
|
||||
Reference in new issue
Block a user