debug step 4

This commit is contained in:
SowinskiBraeden committed 2022-09-10 12:50:32 -07:00
1 parent 9ba4cc4853
commit eed78007f3
3 files changed
+56 -20

No files matched your search

+17 -11
View File
@@ -8,6 +8,9 @@ from string import hexdigits
from util.mockStudents import getSampleStudents from util.mockStudents import getSampleStudents
from util.generateCourses import getSampleCourses from util.generateCourses import getSampleCourses
# Import other utilites
from util.debug import debug
''' '''
Block 1-5 is first semester while Block 1-5 is first semester while
block 6-10 is second semester block 6-10 is second semester
@@ -285,7 +288,9 @@ def generateScheduleV3(
# Tally first and second semester # Tally first and second semester
sem1, sem2 = 0, 0 sem1, sem2 = 0, 0
sem1List, sem2List = {}, {} sem1List, sem2List = {}, {}
allSemBlockLens = []
for i in range(1, 11): for i in range(1, 11):
allSemBlockLens.append(len(running[f"block{i}"]))
if i <= 5: if i <= 5:
sem1 += len(running[f"block{i}"]) sem1 += len(running[f"block{i}"])
sem1List[f"block{i}"] = running[f"block{i}"] sem1List[f"block{i}"] = running[f"block{i}"]
@@ -306,7 +311,7 @@ def generateScheduleV3(
while not classInserted: while not classInserted:
blockIndex += offset blockIndex += offset
if len(running[list(running)[blockIndex]]) < blockClassLimit: if len(running[f'block{blockIndex+1}']) < blockClassLimit:
running[list(running)[blockIndex]][cname] = { running[list(running)[blockIndex]][cname] = {
"CrsNo": course, "CrsNo": course,
"Description": emptyClasses[course][cname]["Description"], "Description": emptyClasses[course][cname]["Description"],
@@ -324,20 +329,12 @@ def generateScheduleV3(
# If the class only runs once, place in semester with least classes # If the class only runs once, place in semester with least classes
elif allClassRunCounts[index] == 1: elif allClassRunCounts[index] == 1:
# Equally disperse into semesters classes # Equally disperse into semesters classes
semBlocks = []
offset = 1
# If sem1 is less than or equal to sem2, add to sem1
if sem1 <= sem2: [semBlocks.append(len(block)) for block in sem1List]
# If sem2 is less than sem1, add to sem2
elif sem1 > sem2: [semBlocks.append(len(block)) for block in sem2List]
# Get block with least classes # Get block with least classes
leastBlock = semBlocks.index(min(semBlocks)) leastBlock = allSemBlockLens.index(min(allSemBlockLens)) + 1
cname = f"{course}-0" cname = f"{course}-0"
running[f"block{leastBlock+offset}"][cname] = { running[f"block{leastBlock}"][cname] = {
"CrsNo": course, "CrsNo": course,
"Description": emptyClasses[course][cname]["Description"], "Description": emptyClasses[course][cname]["Description"],
"students": selectedCourses[cname]["students"], "students": selectedCourses[cname]["students"],
@@ -350,6 +347,15 @@ def generateScheduleV3(
allClassRunCounts.remove(allClassRunCounts[index]) allClassRunCounts.remove(allClassRunCounts[index])
courseRunInfo.pop(list(courseRunInfo)[index]) courseRunInfo.pop(list(courseRunInfo)[index])
# Debug to json for analysis
if blockClassLimit == 40:
with open('./output/timetable-debug1.json', 'w') as outfile:
json.dump(running, outfile, indent=2)
else:
with open('./output/timetable-debug2.json', 'w') as outfile:
json.dump(running, outfile, indent=2)
# Step 5 - Fill student schedule # Step 5 - Fill student schedule
for block in running: for block in running:
+35 -9
View File
@@ -12,15 +12,19 @@ import sys
from util.mockStudents import getSampleStudents from util.mockStudents import getSampleStudents
from util.generateCourses import getSampleCourses from util.generateCourses import getSampleCourses
# Import other utilities
from util.debug import debug
# Import Algorithm # Import Algorithm
from scheduleGenerator.generator import generateScheduleV3 from scheduleGenerator.generator import generateScheduleV3
done = False done = False
# consts # consts
blockClassLimit = 68 blockClassLimit = 40
print(f'\n>> Debug: Current blockClassLimit = {blockClassLimit}') print()
debug(f'Current blockClassLimit = {blockClassLimit}')
def processing(msg: str): def processing(msg: str):
for c in itertools.cycle(['|', '/', '-', '\\']): for c in itertools.cycle(['|', '/', '-', '\\']):
@@ -56,12 +60,26 @@ if __name__ == '__main__':
st = time() # Start time st = time() # Start time
showError = False
noAnim = False
for e in sys.argv:
if e.lower() == 'showerror': showError = True
if e.lower() == 'noanim': noAnim = True
if noAnim:
sampleStudents = getSampleStudents("./sample_data/course_selection_data.csv", True)
sampleCourses = getSampleCourses("./sample_data/course_selection_data.csv", True)
timetable = {}
timetable["Version"] = 3
timetable["timetable"] = generateScheduleV3(sampleStudents, sampleCourses, blockClassLimit, "./output/students.json", "./output/conflicts.json")
else:
t = threading.Thread(target=processing, args=('Collection student requests',)) t = threading.Thread(target=processing, args=('Collection student requests',))
t.start() # Start animation t.start() # Start animation
sampleStudents = getSampleStudents("./sample_data/course_selection_data.csv", True) sampleStudents = getSampleStudents("./sample_data/course_selection_data.csv", True)
done = True # End Animation done = True # End Animation
print('\nStudent list generated.\n') print('\nStudent list generated.\n')
t = threading.Thread(target=processing, args=('Collection Course Information',)) t = threading.Thread(target=processing, args=('Collection Course Information',))
done = False # reset animation done = False # reset animation
t.start() # Start animation t.start() # Start animation
@@ -78,15 +96,14 @@ if __name__ == '__main__':
timetable["timetable"] = generateScheduleV3(sampleStudents, sampleCourses, blockClassLimit, "./output/students.json", "./output/conflicts.json") timetable["timetable"] = generateScheduleV3(sampleStudents, sampleCourses, blockClassLimit, "./output/students.json", "./output/conflicts.json")
done = True # End Animation done = True # End Animation
et = time() # End time et = time() # End time
elapsed_time = round((et - st), 3) # Execution time elapsed_time = round((et - st), 3) # Execution time
print(f'\n\nDone - Finished in {elapsed_time} seconds\n') print(f'\n\nDone - Finished in {elapsed_time} seconds\n')
for e in sys.argv: if showError:
if e.lower() == 'showerror':
errors, _, _ = errorOutput(sampleStudents) errors, _, _ = errorOutput(sampleStudents)
print(errors) print(errors)
break
with open("./output/timetable.json", "w") as outfile: with open("./output/timetable.json", "w") as outfile:
json.dump(timetable, outfile, indent=2) json.dump(timetable, outfile, indent=2)
@@ -94,6 +111,12 @@ if __name__ == '__main__':
elif sys.argv[1].lower() == "no_refresh": elif sys.argv[1].lower() == "no_refresh":
print() print()
showError = False
noAnim = False
for e in sys.argv:
if e.lower() == 'showerror': showError = True
if e.lower() == 'noanim': noAnim = True
st = time() # Start time st = time() # Start time
if not file_exists('./output/students.json') or not file_exists('./output/courses.json'): if not file_exists('./output/students.json') or not file_exists('./output/courses.json'):
@@ -108,22 +131,25 @@ if __name__ == '__main__':
for i in range(1, 11): student["schedule"][f"block{i}"] = [] for i in range(1, 11): student["schedule"][f"block{i}"] = []
student["classes"] = 0 student["classes"] = 0
if noAnim:
timetable = {}
timetable["Version"] = 3
timetable["timetable"] = generateScheduleV3(sampleStudents, sampleCourses, blockClassLimit, "./output/students.json", "./output/conflicts.json")
else :
t = threading.Thread(target=processing, args=('Processing',)) t = threading.Thread(target=processing, args=('Processing',))
t.start() # Start animation t.start() # Start animation
timetable = {} timetable = {}
timetable["Version"] = 3 timetable["Version"] = 3
timetable["timetable"] = generateScheduleV3(sampleStudents, sampleCourses, blockClassLimit, "./output/students.json", "./output/conflicts.json") timetable["timetable"] = generateScheduleV3(sampleStudents, sampleCourses, blockClassLimit, "./output/students.json", "./output/conflicts.json")
done = True # End Animation done = True # End Animation
et = time() # End time et = time() # End time
elapsed_time = round((et - st), 3) # Execution time elapsed_time = round((et - st), 3) # Execution time
print(f'\n\nDone - Finished in {elapsed_time} seconds\n') print(f'\n\nDone - Finished in {elapsed_time} seconds\n')
for e in sys.argv: if showError:
if e.lower() == 'showerror':
errors, _, _ = errorOutput(sampleStudents) errors, _, _ = errorOutput(sampleStudents)
print(errors) print(errors)
break
with open("./output/timetable.json", "w") as outfile: with open("./output/timetable.json", "w") as outfile:
json.dump(timetable, outfile, indent=2) json.dump(timetable, outfile, indent=2)
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env python
# Define global debug function
debug = lambda msg : print(f">> Debug: {msg}")