continue step 4

This commit is contained in:
SowinskiBraeden committed 2022-04-21 13:58:37 -07:00
1 parent 3f9511e77a
commit 22c87ee1de
3 files changed
+23 -13

No files matched your search

+16 -6
View File
@@ -58,7 +58,7 @@ running = {
# It starts by trying to get all classes full and give all students a full class list. # 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 # Then it starts to attempt to fit all classes into a timetable, making corretions along
# the way. Corrections being moving a students class # 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 def equal(l): # Used to equalize list of numbers
q,r = divmod(sum(l),len(l)) q,r = divmod(sum(l),len(l))
return [q+1]*r + [q]*(len(l)-r) return [q+1]*r + [q]*(len(l)-r)
@@ -225,11 +225,21 @@ def generateScheduleV3(students, courses):
while len(allClassRunCounts) > 0: while len(allClassRunCounts) > 0:
# Get lowest resource class (least times run) # Get lowest resource class (least times run)
index = allClassRunCounts.index(min(allClassRunCounts)) index = allClassRunCounts.index(min(allClassRunCounts))
course = courseRunInfo[index]["CrsNo"] course = list(courseRunInfo)[index]
# Insert 1 class into timetable # Spread classes throughout both semesters
for i in range(courseRunInfo[index]["Total"]): blockIndex = 0
pass 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
# Remove course when fully inserted # Remove course when fully inserted
if allClassRunCounts[index] == 0: if allClassRunCounts[index] == 0:
@@ -252,7 +262,7 @@ def generateScheduleV3(students, courses):
# Step 5 - Evaluate, move classes or students to fix # Step 5 - Evaluate, move classes or students to fix
return [] return running
if __name__ == '__main__': if __name__ == '__main__':
print("Processing...") print("Processing...")
+2 -2
View File
@@ -5,7 +5,7 @@ import csv
realCourses = {} realCourses = {}
# Get all courses from real sample data # 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: with open(data_dir, newline='') as csvfile:
reader = csv.DictReader(csvfile) reader = csv.DictReader(csvfile)
for row in reader: for row in reader:
@@ -30,7 +30,7 @@ def getSampleCourses(data_dir, log=False):
if __name__ == '__main__': 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: with open("../output/realCourses.json", "w") as outfile:
json.dump(courseSet, outfile, indent=2) json.dump(courseSet, outfile, indent=2)
+5 -5
View File
@@ -6,10 +6,10 @@ import csv
import sys import sys
from util.courses import mockCourses from util.courses import mockCourses
mockStudents = [] mockStudents: list[dict] = []
# Generate n students for mock data # Generate n students for mock data
def generateMockStudents(n): def generateMockStudents(n: int) -> list[dict]:
for _ in range(n): for _ in range(n):
newStudent = { newStudent = {
"name": names.get_full_name(), "name": names.get_full_name(),
@@ -36,7 +36,7 @@ def generateMockStudents(n):
# sort real sample data into usable dictionary # 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: with open(data_dir, newline='') as csvfile:
reader = csv.DictReader(csvfile) reader = csv.DictReader(csvfile)
for row in reader: for row in reader:
@@ -87,12 +87,12 @@ if __name__ == '__main__':
print("Missing argument") print("Missing argument")
exit() exit()
if sys.argv[1].lower() == 'sample': 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: with open("../output/students.json", "w") as outfile:
json.dump(studentRequests, outfile, indent=2) json.dump(studentRequests, outfile, indent=2)
elif sys.argv[1].lower() == 'mock': elif sys.argv[1].lower() == 'mock':
studentRequests = generateMockStudents(400) studentRequests: list[dict] = generateMockStudents(400)
with open("../output/students.json", "w") as outfile: with open("../output/students.json", "w") as outfile:
json.dump(studentRequests, outfile, indent=2) json.dump(studentRequests, outfile, indent=2)