debug step 4
This commit is contained in:
3 files changed
+56
-20
No files matched your search
@@ -8,6 +8,9 @@ from string import hexdigits
|
||||
from util.mockStudents import getSampleStudents
|
||||
from util.generateCourses import getSampleCourses
|
||||
|
||||
# Import other utilites
|
||||
from util.debug import debug
|
||||
|
||||
'''
|
||||
Block 1-5 is first semester while
|
||||
block 6-10 is second semester
|
||||
@@ -285,7 +288,9 @@ def generateScheduleV3(
|
||||
# Tally first and second semester
|
||||
sem1, sem2 = 0, 0
|
||||
sem1List, sem2List = {}, {}
|
||||
allSemBlockLens = []
|
||||
for i in range(1, 11):
|
||||
allSemBlockLens.append(len(running[f"block{i}"]))
|
||||
if i <= 5:
|
||||
sem1 += len(running[f"block{i}"])
|
||||
sem1List[f"block{i}"] = running[f"block{i}"]
|
||||
@@ -306,7 +311,7 @@ def generateScheduleV3(
|
||||
while not classInserted:
|
||||
|
||||
blockIndex += offset
|
||||
if len(running[list(running)[blockIndex]]) < blockClassLimit:
|
||||
if len(running[f'block{blockIndex+1}']) < blockClassLimit:
|
||||
running[list(running)[blockIndex]][cname] = {
|
||||
"CrsNo": course,
|
||||
"Description": emptyClasses[course][cname]["Description"],
|
||||
@@ -324,20 +329,12 @@ def generateScheduleV3(
|
||||
# If the class only runs once, place in semester with least classes
|
||||
elif allClassRunCounts[index] == 1:
|
||||
# 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
|
||||
leastBlock = semBlocks.index(min(semBlocks))
|
||||
leastBlock = allSemBlockLens.index(min(allSemBlockLens)) + 1
|
||||
cname = f"{course}-0"
|
||||
|
||||
running[f"block{leastBlock+offset}"][cname] = {
|
||||
running[f"block{leastBlock}"][cname] = {
|
||||
"CrsNo": course,
|
||||
"Description": emptyClasses[course][cname]["Description"],
|
||||
"students": selectedCourses[cname]["students"],
|
||||
@@ -350,6 +347,15 @@ def generateScheduleV3(
|
||||
allClassRunCounts.remove(allClassRunCounts[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
|
||||
for block in running:
|
||||
|
||||
@@ -12,15 +12,19 @@ import sys
|
||||
from util.mockStudents import getSampleStudents
|
||||
from util.generateCourses import getSampleCourses
|
||||
|
||||
# Import other utilities
|
||||
from util.debug import debug
|
||||
|
||||
# Import Algorithm
|
||||
from scheduleGenerator.generator import generateScheduleV3
|
||||
|
||||
done = False
|
||||
|
||||
# consts
|
||||
blockClassLimit = 68
|
||||
blockClassLimit = 40
|
||||
|
||||
print(f'\n>> Debug: Current blockClassLimit = {blockClassLimit}')
|
||||
print()
|
||||
debug(f'Current blockClassLimit = {blockClassLimit}')
|
||||
|
||||
def processing(msg: str):
|
||||
for c in itertools.cycle(['|', '/', '-', '\\']):
|
||||
@@ -56,12 +60,26 @@ if __name__ == '__main__':
|
||||
|
||||
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.start() # Start animation
|
||||
sampleStudents = getSampleStudents("./sample_data/course_selection_data.csv", True)
|
||||
done = True # End Animation
|
||||
print('\nStudent list generated.\n')
|
||||
|
||||
|
||||
t = threading.Thread(target=processing, args=('Collection Course Information',))
|
||||
done = False # reset animation
|
||||
t.start() # Start animation
|
||||
@@ -78,15 +96,14 @@ if __name__ == '__main__':
|
||||
timetable["timetable"] = generateScheduleV3(sampleStudents, sampleCourses, blockClassLimit, "./output/students.json", "./output/conflicts.json")
|
||||
|
||||
done = True # End Animation
|
||||
|
||||
et = time() # End time
|
||||
elapsed_time = round((et - st), 3) # Execution time
|
||||
print(f'\n\nDone - Finished in {elapsed_time} seconds\n')
|
||||
|
||||
for e in sys.argv:
|
||||
if e.lower() == 'showerror':
|
||||
if showError:
|
||||
errors, _, _ = errorOutput(sampleStudents)
|
||||
print(errors)
|
||||
break
|
||||
|
||||
with open("./output/timetable.json", "w") as outfile:
|
||||
json.dump(timetable, outfile, indent=2)
|
||||
@@ -94,6 +111,12 @@ if __name__ == '__main__':
|
||||
elif sys.argv[1].lower() == "no_refresh":
|
||||
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
|
||||
|
||||
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}"] = []
|
||||
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.start() # Start animation
|
||||
timetable = {}
|
||||
timetable["Version"] = 3
|
||||
timetable["timetable"] = generateScheduleV3(sampleStudents, sampleCourses, blockClassLimit, "./output/students.json", "./output/conflicts.json")
|
||||
|
||||
done = True # End Animation
|
||||
|
||||
et = time() # End time
|
||||
elapsed_time = round((et - st), 3) # Execution time
|
||||
print(f'\n\nDone - Finished in {elapsed_time} seconds\n')
|
||||
|
||||
for e in sys.argv:
|
||||
if e.lower() == 'showerror':
|
||||
if showError:
|
||||
errors, _, _ = errorOutput(sampleStudents)
|
||||
print(errors)
|
||||
break
|
||||
|
||||
with open("./output/timetable.json", "w") as outfile:
|
||||
json.dump(timetable, outfile, indent=2)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Define global debug function
|
||||
debug = lambda msg : print(f">> Debug: {msg}")
|
||||
Reference in new issue
Block a user