From dfdb6bf35a2ef2ab351e0264711bd869e345a936 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 26 Apr 2022 12:01:39 -0700 Subject: [PATCH] continue part 4 --- test/scheduleGenerator/v1.py | 2 +- test/scheduleGenerator/v2.py | 2 +- test/scheduleGenerator/v3.py | 79 ++++++++++++++++++++++++++++-------- test/util/__init__.py | 2 +- test/util/generateCourses.py | 2 +- test/util/mockStudents.py | 2 +- 6 files changed, 66 insertions(+), 23 deletions(-) diff --git a/test/scheduleGenerator/v1.py b/test/scheduleGenerator/v1.py index c802791..9cd4b72 100644 --- a/test/scheduleGenerator/v1.py +++ b/test/scheduleGenerator/v1.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 from util.courses import mockCourses, activeCourses # Fake courses from util.mockStudents import generateMockStudents # Generate fake students import json diff --git a/test/scheduleGenerator/v2.py b/test/scheduleGenerator/v2.py index 0af35b7..9e56f12 100644 --- a/test/scheduleGenerator/v2.py +++ b/test/scheduleGenerator/v2.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 from util.courses import mockCourses, activeCourses # Fake courses from util.mockStudents import generateMockStudents # Generate fake students import math diff --git a/test/scheduleGenerator/v3.py b/test/scheduleGenerator/v3.py index e58af93..f22e97c 100644 --- a/test/scheduleGenerator/v3.py +++ b/test/scheduleGenerator/v3.py @@ -1,7 +1,9 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 import json import math import random + +from numpy import empty from util.mockStudents import getSampleStudents from util.generateCourses import getSampleCourses @@ -225,24 +227,65 @@ def generateScheduleV3(students: list, courses: dict) -> dict[str, dict]: index = allClassRunCounts.index(min(allClassRunCounts)) course = list(courseRunInfo)[index] - # Spread classes throughout both semesters - blockIndex = 0 - offset = 0 - for i in range(courseRunInfo[course]["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 - allClassRunCounts[index] -= 1 + # If there is more than one class Running + if allClassRunCounts[index] > 1: + # Spread classes throughout both semesters + blockIndex = 0 + offset = 0 + for i in range(courseRunInfo[course]["Total"]): + cname = f"{course}-{i}" + blockIndex += offset + running[list(running)[blockIndex]][cname] = { + "CrsNo": course, + "Description": emptyClasses[course][cname]["Description"], + "students": selectedCourses[cname]["students"] + } + if offset == 0 or offset == -4: offset = 5 + else: offset = -4 + allClassRunCounts[index] -= 1 - if blockIndex >= 9: - blockIndex = 0 - offset = 0 + if blockIndex >= 9: + blockIndex = 0 + offset = 0 + + # If the class only runs once, place in semester with least classes + elif allClassRunCounts[index] == 1: + # Tally first and second semester + sem1, sem2 = 0, 0 + sem1List, sem2List = {}, {} + for i in range(1, 6): + sem1 += len(running[f"block{i}"]) + sem1List[f"block{i}"] = running[f"block{i}"] + for i in range(5, 11): + sem2 += len(running[f"block{i}"]) + sem2List[f"block{i}"] = running[f"block{i}"] + + # Equally disperse into semesters classes + semBlocks = [] + offset = 1 + + # If sem1 is less than or equal to sem2, add to sem1 + if sem1 <= sem2: + for block in sem1List: + semBlocks.append(len(block)) + + # If sem2 is less than sem1, add to sem2 + elif sem1 > sem2: + offset = 5 + for block in sem2List: + semBlocks.append(len(block)) + + # Get block with least classes + leastBlock = semBlocks.index(min(semBlocks)) + cname = f"{course}-0" + + running[f"block{leastBlock+offset}"][course] = { + "CrsNo": course, + "Description": emptyClasses[course][cname]["Description"], + "Students": selectedCourses[cname]["students"], + } + + allClassRunCounts[index] -= 1 # Remove course when fully inserted if allClassRunCounts[index] == 0: diff --git a/test/util/__init__.py b/test/util/__init__.py index a93a4bf..e5a0d9b 100644 --- a/test/util/__init__.py +++ b/test/util/__init__.py @@ -1 +1 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 diff --git a/test/util/generateCourses.py b/test/util/generateCourses.py index 2c842a1..d2b64a8 100644 --- a/test/util/generateCourses.py +++ b/test/util/generateCourses.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 import json import csv diff --git a/test/util/mockStudents.py b/test/util/mockStudents.py index 18816e4..b32f643 100644 --- a/test/util/mockStudents.py +++ b/test/util/mockStudents.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 import random import names import json