From 014570930a00220fab406f71d449083eb5acfd37 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Sat, 10 Apr 2021 06:08:18 +0000 Subject: [PATCH] superscript v 0.8.5 Former-commit-id: 4de011ef45c6c0785784582d31ec3718116a3493 --- .gitignore | 4 +- dist/superscript.REMOVED.git-id | 2 +- src/superscript.py | 119 ++++++++++++++++++-------------- 3 files changed, 72 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index c1d3443..edba599 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ **/*.egg-info/ **/config.json -**/tra_analysis/ \ No newline at end of file +**/tra_analysis/ + +**/errorlog.txt \ No newline at end of file diff --git a/dist/superscript.REMOVED.git-id b/dist/superscript.REMOVED.git-id index 819a8ba..f30f495 100644 --- a/dist/superscript.REMOVED.git-id +++ b/dist/superscript.REMOVED.git-id @@ -1 +1 @@ -e5f402045a28f8602e17dbd7e4ca6641c33ccd65 \ No newline at end of file +d7d6e7a11e9acaf8966e4a25edcacad84793282e \ No newline at end of file diff --git a/src/superscript.py b/src/superscript.py index 6adaf6f..d93f7e0 100644 --- a/src/superscript.py +++ b/src/superscript.py @@ -3,11 +3,14 @@ # Notes: # setup: -__version__ = "0.8.4" +__version__ = "0.8.5" # changelog should be viewed using print(analysis.__changelog__) __changelog__ = """changelog: - 0.84: + 0.8.5: + - added more gradeful KeyboardInterrupt exiting + - redirected stderr to errorlog.txt + 0.8.4: - added better error message for missing config.json - added automatic config.json creation - added splash text with version and system info @@ -138,6 +141,7 @@ from pathlib import Path from multiprocessing import Pool import platform import matplotlib.pyplot as plt +import sys from concurrent.futures import ThreadPoolExecutor import time import warnings @@ -148,71 +152,84 @@ def main(): global exec_threads + sys.stderr = open("errorlog.txt", "w") + warnings.filterwarnings("ignore") splash() while (True): - current_time = time.time() - print("[OK] time: " + str(current_time)) + try: - config = load_config("config.json") - competition = config["competition"] - match_tests = config["statistics"]["match"] - pit_tests = config["statistics"]["pit"] - metrics_tests = config["statistics"]["metric"] - print("[OK] configs loaded") + current_time = time.time() + print("[OK] time: " + str(current_time)) - print("[OK] starting threads") - cfg_max_threads = config["max-threads"] - sys_max_threads = os.cpu_count() - if cfg_max_threads > -sys_max_threads and cfg_max_threads < 0 : - alloc_processes = sys_max_threads + cfg_max_threads - elif cfg_max_threads > 0 and cfg_max_threads < 1: - alloc_processes = math.floor(cfg_max_threads * sys_max_threads) - elif cfg_max_threads > 1 and cfg_max_threads <= sys_max_threads: - alloc_processes = cfg_max_threads - elif cfg_max_threads == 0: - alloc_processes = sys_max_threads - else: - print("[ERROR] Invalid number of processes, must be between -" + str(sys_max_threads) + " and " + str(sys_max_threads)) - exit() - exec_threads = Pool(processes = alloc_processes) - print("[OK] " + str(alloc_processes) + " threads started") + config = load_config("config.json") + competition = config["competition"] + match_tests = config["statistics"]["match"] + pit_tests = config["statistics"]["pit"] + metrics_tests = config["statistics"]["metric"] + print("[OK] configs loaded") - apikey = config["key"]["database"] - tbakey = config["key"]["tba"] - print("[OK] loaded keys") + print("[OK] starting threads") + cfg_max_threads = config["max-threads"] + sys_max_threads = os.cpu_count() + if cfg_max_threads > -sys_max_threads and cfg_max_threads < 0 : + alloc_processes = sys_max_threads + cfg_max_threads + elif cfg_max_threads > 0 and cfg_max_threads < 1: + alloc_processes = math.floor(cfg_max_threads * sys_max_threads) + elif cfg_max_threads > 1 and cfg_max_threads <= sys_max_threads: + alloc_processes = cfg_max_threads + elif cfg_max_threads == 0: + alloc_processes = sys_max_threads + else: + print("[ERROR] Invalid number of processes, must be between -" + str(sys_max_threads) + " and " + str(sys_max_threads)) + exit() + exec_threads = Pool(processes = alloc_processes) + print("[OK] " + str(alloc_processes) + " threads started") - previous_time = get_previous_time(apikey) - print("[OK] analysis backtimed to: " + str(previous_time)) + apikey = config["key"]["database"] + tbakey = config["key"]["tba"] + print("[OK] loaded keys") - print("[OK] loading data") - start = time.time() - match_data = load_match(apikey, competition) - pit_data = load_pit(apikey, competition) - print("[OK] loaded data in " + str(time.time() - start) + " seconds") + previous_time = get_previous_time(apikey) + print("[OK] analysis backtimed to: " + str(previous_time)) - print("[OK] running match stats") - start = time.time() - matchloop(apikey, competition, match_data, match_tests) - print("[OK] finished match stats in " + str(time.time() - start) + " seconds") + print("[OK] loading data") + start = time.time() + match_data = load_match(apikey, competition) + pit_data = load_pit(apikey, competition) + print("[OK] loaded data in " + str(time.time() - start) + " seconds") - print("[OK] running team metrics") - start = time.time() - metricloop(tbakey, apikey, competition, previous_time, metrics_tests) - print("[OK] finished team metrics in " + str(time.time() - start) + " seconds") + print("[OK] running match stats") + start = time.time() + matchloop(apikey, competition, match_data, match_tests) + print("[OK] finished match stats in " + str(time.time() - start) + " seconds") - print("[OK] running pit analysis") - start = time.time() - pitloop(apikey, competition, pit_data, pit_tests) - print("[OK] finished pit analysis in " + str(time.time() - start) + " seconds") + print("[OK] running team metrics") + start = time.time() + metricloop(tbakey, apikey, competition, previous_time, metrics_tests) + print("[OK] finished team metrics in " + str(time.time() - start) + " seconds") + + print("[OK] running pit analysis") + start = time.time() + pitloop(apikey, competition, pit_data, pit_tests) + print("[OK] finished pit analysis in " + str(time.time() - start) + " seconds") + + set_current_time(apikey, current_time) + print("[OK] finished all tests, looping") + + print_hrule() - set_current_time(apikey, current_time) - print("[OK] finished all tests, looping") + except KeyboardInterrupt: + print("\n[OK] caught KeyboardInterrupt, killing processes") + exec_threads.terminate() + print("[OK] processes killed, exiting") + exit() - print_hrule() + else: + pass #clear()