diff --git a/app/util/convertRawData.py b/app/util/convertRawData.py index ba312d5..389ba47 100644 --- a/app/util/convertRawData.py +++ b/app/util/convertRawData.py @@ -6,7 +6,8 @@ import docx def putMasterTimetable(timetable: dict) -> None: pass -def putScheduleToWord(courses: dict, student: dict, output_dir: str='../../output/final/student_schedules') -> None: +def putScheduleToWord(courses: dict, student: dict, output_dir: str='./output/final/student_schedules') -> None: + # create an instance of a word doc. doc = docx.Document() diff --git a/app/util/globals.py b/app/util/globals.py index ad7c1e8..8234d96 100644 --- a/app/util/globals.py +++ b/app/util/globals.py @@ -17,3 +17,10 @@ class Error: def __init__(self, title: str, description: str): self.Title = title self.Description = description + + # return dict version of self + def toDict(self) -> dict: + return { + "Title": self.Title, + "Description": self.Description + } diff --git a/main.py b/main.py index 8d3e915..ee64eec 100755 --- a/main.py +++ b/main.py @@ -1,13 +1,15 @@ #!/usr/bin/env python3.11 import eel import os +import json from app.generator import generateScheduleV3 from app.util.globals import Error from app.util.getCourses import getCourses from app.util.getStudents import getStudents +from app.util.convertRawData import putScheduleToWord, putMasterTimetable eel.init('template') - + @eel.expose def start( raw_file_data: str, @@ -15,8 +17,9 @@ def start( class_cap: int, block_class_limit: int, total_blocks: int, -) -> Error: - +) -> dict: + + eel.post_data('Ensuring Directories Exists...') # Ensure output paths exists if not os.path.exists('output'): os.makedirs('output') if not os.path.exists('output/temp'): os.makedirs('output/temp') @@ -26,9 +29,9 @@ def start( raw_data_dir = './output/temp/course_selection_data.csv' + eel.post_data('Saving raw data to local file...') # save raw file data to local file with open(raw_data_dir, 'w') as raw_file: - raw_file_data = raw_file_data.replace('\n', '') raw_file.write(raw_file_data) # Ensure params are of correct type @@ -37,8 +40,7 @@ def start( block_class_limit = int(block_class_limit) total_blocks = int(total_blocks) - err = None - + eel.post_data('Collecting student information...') # call pre-algorithm functions read raw data into a processable format students = getStudents( raw_data_dir, @@ -46,14 +48,16 @@ def start( totalBlocks=total_blocks, log_dir='./output/raw/students.json' ) + eel.post_data('Collecting course information...') courses = getCourses( raw_data_dir, log=True, log_dir='./output/raw/courses.json' ) + eel.post_data('Generating timetables...') # call algorithm to sort data - _, err = generateScheduleV3( + master_timetable, err = generateScheduleV3( students, courses, minReq=min_req, @@ -64,12 +68,22 @@ def start( conflictsDir='./output/raw/conflicts.json' ) - print(err) + + if err is not None: + eel.post_data(f'An error has occured while generating the timetable: {err.Title}') + return err.toDict() + + eel.post_data('Gathering latest data...')() + # Get updated students + with open('./output/raw/students.json', 'r') as studentFile: students = json.load(studentFile) + + eel.post_data('Writing timetables to .docx files...') + # call post-algorithm functions to present sorted data + for student in students: + putScheduleToWord(courses, student, './output/final/student_schedules') # TODO: log master_timetable - # TODO: call post-algorithm functions to present sorted data - - return err + return err.toDict() if err is not None else None eel.start('index.html', size=(800, 1000)) diff --git a/template/index.html b/template/index.html index c2e590a..4dfd3a4 100644 --- a/template/index.html +++ b/template/index.html @@ -9,8 +9,8 @@ - +