debug step 4
This commit is contained in:
3 files changed
+90
-54
No files matched your search
@@ -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,14 +288,16 @@ 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}"]
|
||||||
elif i > 5:
|
elif i > 5:
|
||||||
sem2 += len(running[f"block{i}"])
|
sem2 += len(running[f"block{i}"])
|
||||||
sem2List[f"block{i}"] = running[f"block{i}"]
|
sem2List[f"block{i}"] = running[f"block{i}"]
|
||||||
|
|
||||||
# If there is more than one class Running
|
# If there is more than one class Running
|
||||||
if allClassRunCounts[index] > 1:
|
if allClassRunCounts[index] > 1:
|
||||||
blockIndex = 0 if sem1 <= sem2 else 5
|
blockIndex = 0 if sem1 <= sem2 else 5
|
||||||
@@ -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:
|
||||||
@@ -531,7 +537,7 @@ def generateScheduleV3(
|
|||||||
|
|
||||||
# Update Student records
|
# Update Student records
|
||||||
with open(studentsDir, "w") as outfile:
|
with open(studentsDir, "w") as outfile:
|
||||||
json.dump(students, outfile, indent=2)
|
json.dump(students, outfile, indent=2)
|
||||||
|
|
||||||
return running
|
return running
|
||||||
|
|
||||||
|
|||||||
@@ -12,16 +12,20 @@ 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(['|', '/', '-', '\\']):
|
||||||
if done: break
|
if done: break
|
||||||
@@ -56,37 +60,50 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
st = time() # Start time
|
st = time() # Start time
|
||||||
|
|
||||||
t = threading.Thread(target=processing, args=('Collection student requests',))
|
showError = False
|
||||||
t.start() # Start animation
|
noAnim = False
|
||||||
sampleStudents = getSampleStudents("./sample_data/course_selection_data.csv", True)
|
for e in sys.argv:
|
||||||
done = True # End Animation
|
if e.lower() == 'showerror': showError = True
|
||||||
print('\nStudent list generated.\n')
|
if e.lower() == 'noanim': noAnim = True
|
||||||
|
|
||||||
t = threading.Thread(target=processing, args=('Collection Course Information',))
|
|
||||||
done = False # reset animation
|
|
||||||
t.start() # Start animation
|
|
||||||
sampleCourses = getSampleCourses("./sample_data/course_selection_data.csv", True)
|
|
||||||
done = True # End Animation
|
|
||||||
print('\nCourse Information Collected.\n')
|
|
||||||
|
|
||||||
sleep(0.1)
|
if noAnim:
|
||||||
t = threading.Thread(target=processing, args=('Processing',))
|
sampleStudents = getSampleStudents("./sample_data/course_selection_data.csv", True)
|
||||||
done = False # reset animation
|
sampleCourses = getSampleCourses("./sample_data/course_selection_data.csv", True)
|
||||||
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")
|
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')
|
||||||
|
|
||||||
done = True # End Animation
|
|
||||||
|
t = threading.Thread(target=processing, args=('Collection Course Information',))
|
||||||
|
done = False # reset animation
|
||||||
|
t.start() # Start animation
|
||||||
|
sampleCourses = getSampleCourses("./sample_data/course_selection_data.csv", True)
|
||||||
|
done = True # End Animation
|
||||||
|
print('\nCourse Information Collected.\n')
|
||||||
|
|
||||||
|
sleep(0.1)
|
||||||
|
t = threading.Thread(target=processing, args=('Processing',))
|
||||||
|
done = False # reset animation
|
||||||
|
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
|
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
|
||||||
|
|
||||||
t = threading.Thread(target=processing, args=('Processing',))
|
if noAnim:
|
||||||
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")
|
else :
|
||||||
|
t = threading.Thread(target=processing, args=('Processing',))
|
||||||
done = True # End Animation
|
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
|
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)
|
||||||
|
|||||||
@@ -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