update schedule test scripts
This commit is contained in:
1 parent
faefa08848
commit
f8d531f1b1
3 files changed
+156
-89
No files matched your search
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import random
|
||||||
|
import names
|
||||||
|
from courses import courses
|
||||||
|
|
||||||
|
mockStudents = []
|
||||||
|
|
||||||
|
# Generate n students for mock data
|
||||||
|
def generateMockStudents(n):
|
||||||
|
for _ in range(n):
|
||||||
|
newStudent = {
|
||||||
|
"name": names.get_full_name(),
|
||||||
|
"requests": [], # list of class codes
|
||||||
|
"schedule": {
|
||||||
|
"block1": "",
|
||||||
|
"block2": "",
|
||||||
|
"block3": "",
|
||||||
|
"block4": "",
|
||||||
|
"block5": "",
|
||||||
|
"block6": "",
|
||||||
|
"block7": "",
|
||||||
|
"block8": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Get list of random class choices with no repeats
|
||||||
|
# 8 primary choices, 2 secondary choices
|
||||||
|
courseSelection = random.sample(range(0, len(courses)), 10)
|
||||||
|
for courseNum in courseSelection:
|
||||||
|
newStudent["requests"].append(list(courses)[courseNum])
|
||||||
|
mockStudents.append(newStudent)
|
||||||
|
|
||||||
|
return mockStudents
|
||||||
+20
-9
@@ -4,18 +4,29 @@ let students = require('./students.json');
|
|||||||
// console.table(schedule)
|
// console.table(schedule)
|
||||||
|
|
||||||
// Display first semester
|
// Display first semester
|
||||||
console.table(schedule.block1)
|
// console.table(schedule.block1)
|
||||||
console.table(schedule.block2)
|
// console.table(schedule.block2)
|
||||||
console.table(schedule.block3)
|
// console.table(schedule.block3)
|
||||||
console.table(schedule.block4)
|
// console.table(schedule.block4)
|
||||||
|
|
||||||
// Display second semester
|
// // Display second semester
|
||||||
console.table(schedule.block5)
|
// console.table(schedule.block5)
|
||||||
console.table(schedule.block6)
|
// console.table(schedule.block6)
|
||||||
console.table(schedule.block7)
|
// console.table(schedule.block7)
|
||||||
console.table(schedule.block8)
|
// console.table(schedule.block8)
|
||||||
|
|
||||||
// Display each students schedule
|
// Display each students schedule
|
||||||
// for (let i = 0; i < students.length; i++) {
|
// for (let i = 0; i < students.length; i++) {
|
||||||
// console.table(students[i].schedule)
|
// console.table(students[i].schedule)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
let errors = 0;
|
||||||
|
let classes;
|
||||||
|
for (let i = 0; i < students.length; i++) {
|
||||||
|
for (let j = 0; j < students[i].schedule.length; j++) {
|
||||||
|
if (students[i].schedule[j] != "") classes++;
|
||||||
|
}
|
||||||
|
if (classes != 8) errors++;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`${errors} student(s) have a issue with their schedule`)
|
||||||
+104
-80
@@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import random
|
import sys
|
||||||
import names
|
|
||||||
import math
|
|
||||||
import json
|
import json
|
||||||
|
import math
|
||||||
from prettytable import PrettyTable
|
from prettytable import PrettyTable
|
||||||
from courses import courses, activeCourses
|
from courses import courses, activeCourses
|
||||||
|
from mock import generateMockStudents
|
||||||
|
|
||||||
'''
|
'''
|
||||||
I will be using python to test and
|
I will be using python to test and
|
||||||
@@ -49,11 +49,12 @@ running: {
|
|||||||
|
|
||||||
# Error 1: No classes in schedule can fit this student
|
# Error 1: No classes in schedule can fit this student
|
||||||
# Error 2: No more room in schedule for another class
|
# Error 2: No more room in schedule for another class
|
||||||
# Error 3: No more alternatives
|
|
||||||
|
|
||||||
|
# 400 by default
|
||||||
|
studentsNum = 400
|
||||||
|
|
||||||
err1, err2, err3 = 0,0,0
|
err1, err2, = 0,0
|
||||||
minReq, classCap, blockClassLimit = 18, 30, 15
|
minReq, classCap, blockClassLimit = 18, 30, 21
|
||||||
mockStudents = []
|
mockStudents = []
|
||||||
running = {
|
running = {
|
||||||
"block1": {},
|
"block1": {},
|
||||||
@@ -67,53 +68,7 @@ running = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Generate n students for mock data
|
def generateScheduleV1():
|
||||||
def generateMockStudents(n):
|
|
||||||
newStudent = {
|
|
||||||
"name": "Braeden Sowinski",
|
|
||||||
"requests": [], # list of class codes
|
|
||||||
"schedule": {
|
|
||||||
"block1": "",
|
|
||||||
"block2": "",
|
|
||||||
"block3": "",
|
|
||||||
"block4": "",
|
|
||||||
"block5": "",
|
|
||||||
"block6": "",
|
|
||||||
"block7": "",
|
|
||||||
"block8": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
# Get list of random class choices with no repeats
|
|
||||||
# 8 primary choices, 2 secondary choices
|
|
||||||
courseSelection = random.sample(range(0, len(courses)), 10)
|
|
||||||
for courseNum in courseSelection:
|
|
||||||
newStudent["requests"].append(list(courses)[courseNum])
|
|
||||||
mockStudents.append(newStudent)
|
|
||||||
|
|
||||||
for _ in range(n):
|
|
||||||
newStudent = {
|
|
||||||
"name": names.get_full_name(),
|
|
||||||
"requests": [], # list of class codes
|
|
||||||
"schedule": {
|
|
||||||
"block1": "",
|
|
||||||
"block2": "",
|
|
||||||
"block3": "",
|
|
||||||
"block4": "",
|
|
||||||
"block5": "",
|
|
||||||
"block6": "",
|
|
||||||
"block7": "",
|
|
||||||
"block8": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
# Get list of random class choices with no repeats
|
|
||||||
# 8 primary choices, 2 secondary choices
|
|
||||||
courseSelection = random.sample(range(0, len(courses)), 10)
|
|
||||||
for courseNum in courseSelection:
|
|
||||||
newStudent["requests"].append(list(courses)[courseNum])
|
|
||||||
mockStudents.append(newStudent)
|
|
||||||
|
|
||||||
|
|
||||||
def generateSchedule():
|
|
||||||
global err1, err2, err3
|
global err1, err2, err3
|
||||||
# Collect data and calculate schedules
|
# Collect data and calculate schedules
|
||||||
for student in mockStudents:
|
for student in mockStudents:
|
||||||
@@ -124,19 +79,9 @@ def generateSchedule():
|
|||||||
# Add course to active list if enough requests
|
# Add course to active list if enough requests
|
||||||
if courses[request]["totalrequests"] > minReq and courses[request]["code"] not in activeCourses: activeCourses[courses[request]["code"]] = courses[request]
|
if courses[request]["totalrequests"] > minReq and courses[request]["code"] not in activeCourses: activeCourses[courses[request]["code"]] = courses[request]
|
||||||
|
|
||||||
# This is just for data testing/visualizations
|
|
||||||
# calculate # of times to run class
|
|
||||||
# t = PrettyTable(["Class Name", "Class Runcount"])
|
|
||||||
# for i in range(len(activeCourses)):
|
|
||||||
# classRunCount = math.floor(activeCourses[list(activeCourses)[i]]["totalrequests"] / classCap)
|
|
||||||
# # If there is 18+ requests left, 1 more class could be run
|
|
||||||
# if (activeCourses[list(activeCourses)[i]]["totalrequests"] % classCap) > minReq: classRunCount += 1
|
|
||||||
# activeCourses[list(activeCourses)[i]]["classRunCount"] = classRunCount
|
|
||||||
# t.add_row([activeCourses[list(activeCourses)[i]]["code"], classRunCount])
|
|
||||||
# print(t)
|
|
||||||
|
|
||||||
for student in mockStudents:
|
for student in mockStudents:
|
||||||
alternateOffset = len(student["requests"])-8
|
alternateOffset = len(student["requests"])-8
|
||||||
|
alternateIndex = 8
|
||||||
for i in range(len(student["requests"])-alternateOffset): # Subtract x classes as they are alternatives
|
for i in range(len(student["requests"])-alternateOffset): # Subtract x classes as they are alternatives
|
||||||
currentCourse = student["requests"][i]
|
currentCourse = student["requests"][i]
|
||||||
generate = True
|
generate = True
|
||||||
@@ -155,15 +100,40 @@ def generateSchedule():
|
|||||||
getFreeBlock = False
|
getFreeBlock = False
|
||||||
else: # Find next available class or create new one
|
else: # Find next available class or create new one
|
||||||
if blockIndex == 8: # No available classes
|
if blockIndex == 8: # No available classes
|
||||||
|
if len(student["requests"]) == 8:
|
||||||
|
# This student never had any alternatives
|
||||||
|
# How to solve?
|
||||||
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
# print(f"\nError 1: No more available classes for student {student['name']}")
|
||||||
err1 += 1
|
err1 += 1
|
||||||
|
generate = False
|
||||||
|
else:
|
||||||
|
if alternateIndex <= (len(student["requests"]) - 1):
|
||||||
|
currentCourse = student["requests"][alternateIndex]
|
||||||
|
alternateIndex += 1
|
||||||
|
else: # No more alterantive
|
||||||
|
# print(f"\nError 1: No more available classes for student {student['name']}")
|
||||||
|
err1 += 1
|
||||||
|
generate = False
|
||||||
getFreeBlock = False
|
getFreeBlock = False
|
||||||
else: blockIndex += 1
|
else: blockIndex += 1
|
||||||
else:
|
else:
|
||||||
if blockIndex == 8: # No available classes
|
if blockIndex == 8: # No available classes
|
||||||
|
if len(student["requests"]) == 8:
|
||||||
|
# This student never had any alternatives
|
||||||
|
# How to solve?
|
||||||
|
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
# print(f"\nError 1: No more available classes for student {student['name']}")
|
||||||
err1 += 1
|
err1 += 1
|
||||||
# Resort to alternative
|
generate = False
|
||||||
|
else:
|
||||||
|
if alternateIndex <= (len(student["requests"]) - 1):
|
||||||
|
currentCourse = student["requests"][alternateIndex]
|
||||||
|
alternateIndex += 1
|
||||||
|
else: # No more alternatives
|
||||||
|
# print(f"\nError 1: No more available classes for student {student['name']}")
|
||||||
|
err1 += 1
|
||||||
|
generate = False
|
||||||
getFreeBlock = False
|
getFreeBlock = False
|
||||||
else: blockIndex += 1
|
else: blockIndex += 1
|
||||||
else:
|
else:
|
||||||
@@ -174,7 +144,7 @@ def generateSchedule():
|
|||||||
while True:
|
while True:
|
||||||
newBlock = f"block{blockNum}"
|
newBlock = f"block{blockNum}"
|
||||||
if currentCourse not in running[newBlock] and len(running[newBlock]) < blockClassLimit:
|
if currentCourse not in running[newBlock] and len(running[newBlock]) < blockClassLimit:
|
||||||
if student["schedule"][newBlock] == "":
|
if student["schedule"][newBlock] == "": # Add student to class
|
||||||
running[newBlock][currentCourse] = {
|
running[newBlock][currentCourse] = {
|
||||||
"name": courses[currentCourse]["name"],
|
"name": courses[currentCourse]["name"],
|
||||||
"students": [student["name"]]
|
"students": [student["name"]]
|
||||||
@@ -183,10 +153,7 @@ def generateSchedule():
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if blockNum == 8:
|
if blockNum == 8:
|
||||||
# No available classes
|
# All student classes have been filled
|
||||||
# print(f"\nError 1: No more available classes for student {student['name']}")
|
|
||||||
err1 += 1
|
|
||||||
# TODO: Resort to alternative
|
|
||||||
break
|
break
|
||||||
else: blockNum += 1
|
else: blockNum += 1
|
||||||
else:
|
else:
|
||||||
@@ -200,24 +167,68 @@ def generateSchedule():
|
|||||||
else: blockIndex += 1
|
else: blockIndex += 1
|
||||||
break
|
break
|
||||||
elif currentCourse not in activeCourses:
|
elif currentCourse not in activeCourses:
|
||||||
if alternateOffset == 0:
|
if len(student["requests"]) == 8:
|
||||||
# TODO: No more alternatives, solve problem
|
# This student never had any alternatives
|
||||||
# print("Error 3: No more alternatives")
|
|
||||||
err3 += 1
|
|
||||||
# How to solve?
|
# How to solve?
|
||||||
|
|
||||||
|
# print(f"\nError 1: No more available classes for student {student['name']}")
|
||||||
|
err1 += 1
|
||||||
generate = False
|
generate = False
|
||||||
currentCourse = student["requests"][len(student["requests"])-alternateOffset]
|
else:
|
||||||
alternateOffset -= 1
|
if alternateIndex <= (len(student["requests"]) - 1):
|
||||||
|
currentCourse = student["requests"][alternateIndex]
|
||||||
|
alternateIndex += 1
|
||||||
|
else: # Out of alternatives
|
||||||
|
# print(f"\nError 1: No more available classes for student {student['name']}")
|
||||||
|
err1 += 1
|
||||||
|
generate = False
|
||||||
|
|
||||||
|
|
||||||
|
def generateScheduleV2():
|
||||||
|
# This is just for data testing/visualizations
|
||||||
|
# calculate # of times to run class
|
||||||
|
# t = PrettyTable(["Class Name", "Class Runcount"])
|
||||||
|
for i in range(len(activeCourses)):
|
||||||
|
classRunCount = math.floor(activeCourses[list(activeCourses)[i]]["totalrequests"] / classCap)
|
||||||
|
# If there is minReq+ requests left, 1 more class could be run
|
||||||
|
if (activeCourses[list(activeCourses)[i]]["totalrequests"] % classCap) > minReq: classRunCount += 1
|
||||||
|
activeCourses[list(activeCourses)[i]]["classRunCount"] = classRunCount
|
||||||
|
# t.add_row([activeCourses[list(activeCourses)[i]]["code"], classRunCount])
|
||||||
|
# print(t)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
generateMockStudents(400)
|
if len(sys.argv) == 1:
|
||||||
generateSchedule()
|
print("Missing argument")
|
||||||
|
exit()
|
||||||
|
if sys.argv[1].upper() == 'V1':
|
||||||
|
if len(sys.argv) == 3:
|
||||||
|
try:
|
||||||
|
studentsNum = int(sys.argv[2])
|
||||||
|
except:
|
||||||
|
print("Error parsing number of students")
|
||||||
|
exit()
|
||||||
|
print("Processing...")
|
||||||
|
mockStudents = generateMockStudents(studentsNum)
|
||||||
|
generateScheduleV1()
|
||||||
|
elif sys.argv[1].upper() == 'V2':
|
||||||
|
if len(sys.argv) == 3:
|
||||||
|
try:
|
||||||
|
studentsNum = int(sys.argv[2])
|
||||||
|
except:
|
||||||
|
print("Error parsing number of students")
|
||||||
|
exit()
|
||||||
|
print("Processing...")
|
||||||
|
mockStudents = generateMockStudents(studentsNum)
|
||||||
|
generateScheduleV1()
|
||||||
|
else:
|
||||||
|
print("Invalid argument")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
print("\n")
|
||||||
print(f"Error 1: x{err1}")
|
print(f"Error 1: x{err1}")
|
||||||
print(f"Error 2: x{err2}")
|
print(f"Error 2: x{err2}")
|
||||||
print(f"Error 3: x{err3}")
|
print("\n")
|
||||||
print("\n\n")
|
|
||||||
|
|
||||||
### Displays the number of students in each class
|
### Displays the number of students in each class
|
||||||
# for block in running:
|
# for block in running:
|
||||||
@@ -228,8 +239,21 @@ if __name__ == '__main__':
|
|||||||
# students = len(running[block][cl]["students"])
|
# students = len(running[block][cl]["students"])
|
||||||
# print(f"Class: {name} | Students: {students}")
|
# print(f"Class: {name} | Students: {students}")
|
||||||
|
|
||||||
|
# Count errors in students schedules
|
||||||
|
errors = 0
|
||||||
|
for i in range(len(mockStudents)):
|
||||||
|
count = 0
|
||||||
|
for course in mockStudents[i]["schedule"]:
|
||||||
|
if mockStudents[i]["schedule"][course]=="": count+=1
|
||||||
|
if count > 0: errors += 1
|
||||||
|
|
||||||
|
print(f"{errors}/{studentsNum} student(s) have a issue with their schedule")
|
||||||
|
|
||||||
|
|
||||||
with open("schedule.json", "w") as outfile:
|
with open("schedule.json", "w") as outfile:
|
||||||
json.dump(running, outfile, indent=2)
|
json.dump(running, outfile, indent=2)
|
||||||
|
|
||||||
with open("students.json", "w") as outfile:
|
with open("students.json", "w") as outfile:
|
||||||
json.dump(mockStudents, outfile, indent=2)
|
json.dump(mockStudents, outfile, indent=2)
|
||||||
|
|
||||||
|
print("Done")
|
||||||
Reference in new issue
Block a user