diff --git a/README.md b/README.md index 46f531c..2f879f2 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,37 @@ The algorithm reads student requests and generates a timetable for all requested The algorithm has been moved out of `tinker.py` into its own python script. Version 1 and 2 are removed and the script can be found in the `/scheduleGenerator` folder. The algorithm has come a long way; using real 2018 course selection data from my school, enabling me to better test the script. V3 has a entirely different approach from V1 and V2, that you can read about at the top of the function in [`generator.py`](/scheduleGenerator/generator.py). The function is broken up into 6 steps, each step is labeled within the function with a comment, giving a brief explination of what that step contributes to the algorithm. -This is the output after running it with the following command +Here is the list of commands. +1. Collect latest data from files and generate timetable ``` $ ./tinker.py ``` +2. Collect Data and store it in files for later +``` + $ ./tinker.py generate_data +``` + +3. Generate timetable from existing files (faster), requires last command run +``` + $ ./tinker.py no_refresh +``` + +4. More details on errors +``` + $ ./tinker.py errors +``` + +
+ +This is the output after running it with the following command. +``` + $ ./tinker.py no_refresh +``` + ![preview](/preview/generator-preview.png) +
A more in depth error log can be read with the additional argument ``` diff --git a/preview/error-preview.png b/preview/error-preview.png index 9659494..4cd1a44 100644 Binary files a/preview/error-preview.png and b/preview/error-preview.png differ diff --git a/preview/generator-preview.png b/preview/generator-preview.png index d7eda60..e897a69 100644 Binary files a/preview/generator-preview.png and b/preview/generator-preview.png differ diff --git a/tinker.py b/tinker.py index fa87ca9..19bc809 100644 --- a/tinker.py +++ b/tinker.py @@ -1,4 +1,5 @@ #! python +from os.path import exists as file_exists from prettytable import PrettyTable from typing import Tuple from time import time, sleep @@ -79,11 +80,18 @@ if __name__ == '__main__': errors, _, _ = errorOutput(sampleStudents) print(errors) - elif sys.argv[1].lower() == "norefresh" or sys.argv[1].lower() == "no_refresh": + with open("./output/timetable.json", "w") as outfile: + json.dump(timetable, outfile, indent=2) + + elif sys.argv[1].lower() == "no_refresh": print('\nGenerating...\n') st = time() # Start time + if not file_exists('./output/students.json') or not file_exists('./output/courses.json'): + print('\n No previous data exists, please use the following command\n./tinker.py generate_data') + exit() + with open('./output/students.json') as f: sampleStudents = json.load(f) with open('./output/courses.json') as f: sampleCourses = json.load(f) @@ -106,6 +114,24 @@ if __name__ == '__main__': errors, _, _ = errorOutput(sampleStudents) print(errors) + with open("./output/timetable.json", "w") as outfile: + json.dump(timetable, outfile, indent=2) + + elif sys.argv[1].lower() == "generate_data": + t = threading.Thread(target=processing, args=('Collection student requests',)) + t.start() # Start animation + _ = 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 + _ = getSampleCourses("./sample_data/course_selection_data.csv", True) + done = True # End Animation + print('\nCourse Information Collected.\n') + print('You can now use the following command\n./tinker.py no_refresh') + elif sys.argv[1].upper() == "ERRORS": f = open('./output/students.json') studentData = json.load(f) @@ -128,5 +154,3 @@ if __name__ == '__main__': print("Invalid argument") exit() - with open("./output/timetable.json", "w") as outfile: - json.dump(timetable, outfile, indent=2)