From 22c87ee1de12b4a29ad2c5da81369f9cf57826bc Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Thu, 21 Apr 2022 13:58:37 -0700 Subject: [PATCH] continue step 4 --- test/scheduleGenerator/v3.py | 24 +++++++++++++++++------- test/util/generateCourses.py | 4 ++-- test/util/mockStudents.py | 10 +++++----- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/test/scheduleGenerator/v3.py b/test/scheduleGenerator/v3.py index e5a2b94..35a4b37 100644 --- a/test/scheduleGenerator/v3.py +++ b/test/scheduleGenerator/v3.py @@ -58,7 +58,7 @@ running = { # It starts by trying to get all classes full and give all students a full class list. # Then it starts to attempt to fit all classes into a timetable, making corretions along # the way. Corrections being moving a students class -def generateScheduleV3(students, courses): +def generateScheduleV3(students: list, courses: dict) -> dict[str, dict]: def equal(l): # Used to equalize list of numbers q,r = divmod(sum(l),len(l)) return [q+1]*r + [q]*(len(l)-r) @@ -225,12 +225,22 @@ def generateScheduleV3(students, courses): while len(allClassRunCounts) > 0: # Get lowest resource class (least times run) index = allClassRunCounts.index(min(allClassRunCounts)) - course = courseRunInfo[index]["CrsNo"] + course = list(courseRunInfo)[index] + + # Spread classes throughout both semesters + blockIndex = 0 + offset = 0 + for i in range(courseRunInfo[list(courseRunInfo)[index]]["Total"]): + cname = f"{course}-{i}" + blockIndex += offset + running[list(running)[blockIndex]][cname] = { + "CrsNo": cname[:len(cname)-2], + "Description": course, + "students": selectedCourses[cname]["students"] + } + if offset == 0 or offset == -4: offset = 5 + else: offset == -4 - # Insert 1 class into timetable - for i in range(courseRunInfo[index]["Total"]): - pass - # Remove course when fully inserted if allClassRunCounts[index] == 0: allClassRunCounts.remove(allClassRunCounts[index]) @@ -252,7 +262,7 @@ def generateScheduleV3(students, courses): # Step 5 - Evaluate, move classes or students to fix - return [] + return running if __name__ == '__main__': print("Processing...") diff --git a/test/util/generateCourses.py b/test/util/generateCourses.py index 69f33cf..2c842a1 100644 --- a/test/util/generateCourses.py +++ b/test/util/generateCourses.py @@ -5,7 +5,7 @@ import csv realCourses = {} # Get all courses from real sample data -def getSampleCourses(data_dir, log=False): +def getSampleCourses(data_dir, log=False) -> dict: with open(data_dir, newline='') as csvfile: reader = csv.DictReader(csvfile) for row in reader: @@ -30,7 +30,7 @@ def getSampleCourses(data_dir, log=False): if __name__ == '__main__': - courseSet = getSampleCourses("../sample_data/course_selection_data.csv") + courseSet: dict = getSampleCourses("../sample_data/course_selection_data.csv") with open("../output/realCourses.json", "w") as outfile: json.dump(courseSet, outfile, indent=2) diff --git a/test/util/mockStudents.py b/test/util/mockStudents.py index 21dbf81..18816e4 100644 --- a/test/util/mockStudents.py +++ b/test/util/mockStudents.py @@ -6,10 +6,10 @@ import csv import sys from util.courses import mockCourses -mockStudents = [] +mockStudents: list[dict] = [] # Generate n students for mock data -def generateMockStudents(n): +def generateMockStudents(n: int) -> list[dict]: for _ in range(n): newStudent = { "name": names.get_full_name(), @@ -36,7 +36,7 @@ def generateMockStudents(n): # sort real sample data into usable dictionary -def getSampleStudents(data_dir, log=False): +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: @@ -87,12 +87,12 @@ if __name__ == '__main__': print("Missing argument") exit() if sys.argv[1].lower() == 'sample': - studentRequests = getSampleStudents("../sample_data/course_selection_data.csv") + studentRequests: list[dict] = getSampleStudents("../sample_data/course_selection_data.csv") with open("../output/students.json", "w") as outfile: json.dump(studentRequests, outfile, indent=2) elif sys.argv[1].lower() == 'mock': - studentRequests = generateMockStudents(400) + studentRequests: list[dict] = generateMockStudents(400) with open("../output/students.json", "w") as outfile: json.dump(studentRequests, outfile, indent=2)