From fd914e4be7265a9f9e6e73e90539e8e7e5f80967 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 21 Jun 2022 18:02:47 -0700 Subject: [PATCH] cleaner --- scheduleGenerator/generator.py | 25 +++++++++---------------- tinker.py | 27 +++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/scheduleGenerator/generator.py b/scheduleGenerator/generator.py index 30a491f..64e1e0e 100644 --- a/scheduleGenerator/generator.py +++ b/scheduleGenerator/generator.py @@ -21,7 +21,6 @@ from util.generateCourses import getSampleCourses ... } - running example: running: { "block1": { @@ -44,21 +43,15 @@ def getLineNumber(): return currentframe().f_back.f_lineno # Returns if the particular student has a previous error def newConflict(pupilNum: str, email: str, conflictType: str, code: str, description: str, logs: dict) -> bool: exists = True if pupilNum in logs else False - if exists: logs[pupilNum].append({ - "Pupil #": pupilNum, - "Email": email, - "Type": conflictType, - "Code": code, - "Conflict": description - }) - else: - logs[pupilNum] = [{ - "Pupil #": pupilNum, - "Email": email, - "Type": conflictType, - "Code": code, - "Conflict": description - }] + log = { + "Pupil #": pupilNum, + "Email": email, + "Type": conflictType, + "Code": code, + "Conflict": description + } + if exists: logs[pupilNum].append(log) + else: logs[pupilNum] = [log] return exists minReq, median, classCap = 18, 24, 30 diff --git a/tinker.py b/tinker.py index 106df56..af0a969 100644 --- a/tinker.py +++ b/tinker.py @@ -1,6 +1,9 @@ #! python from prettytable import PrettyTable from typing import Tuple +from time import time, sleep +import itertools +import threading import json import sys @@ -11,6 +14,15 @@ from util.generateCourses import getSampleCourses # Import Algorithm from scheduleGenerator.generator import generateScheduleV3 +done = False + +def processing(): + for c in itertools.cycle(['|', '/', '-', '\\']): + if done: break + sys.stdout.write(f'\rProcessing {c}') + sys.stdout.flush() + sleep(0.1) + def errorOutput(students) -> Tuple[PrettyTable, dict, dict]: # Error Table calulation / output f = open('./output/conflicts.json') @@ -34,14 +46,23 @@ def errorOutput(students) -> Tuple[PrettyTable, dict, dict]: if __name__ == '__main__': if len(sys.argv) == 1: - print("Processing...\n") - + print() + + st = time() # Start time + t = threading.Thread(target=processing) + t.start() # Start animation + sampleStudents = getSampleStudents("./sample_data/course_selection_data.csv", True) samplemockCourses = getSampleCourses("./sample_data/course_selection_data.csv", True) timetable = {} timetable["Version"] = 3 timetable["timetable"] = generateScheduleV3(sampleStudents, samplemockCourses, 40, "./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') + errors, _, _ = errorOutput(sampleStudents) print(errors) @@ -69,5 +90,3 @@ if __name__ == '__main__': with open("./output/timetable.json", "w") as outfile: json.dump(timetable, outfile, indent=2) - - print("\nDone")