From 0024a94f4ef811636e070781856b13d0598553e5 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Wed, 30 Mar 2022 04:53:40 +0000 Subject: [PATCH] added file logging with default, added basic progress bars for each module --- src/interface.py | 2 +- src/module.py | 7 ++++--- src/superscript.py | 18 +++++++----------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/interface.py b/src/interface.py index 5eef26b..92c9994 100644 --- a/src/interface.py +++ b/src/interface.py @@ -23,7 +23,7 @@ class Logger(L): self.file = file - if file != None: + if file is not None: self.targets.append(self._send_file) if profile: diff --git a/src/module.py b/src/module.py index c260dd2..d69a67d 100644 --- a/src/module.py +++ b/src/module.py @@ -2,6 +2,7 @@ import abc import signal import numpy as np from tra_analysis import Analysis as an +from tqdm import tqdm class Module(metaclass = abc.ABCMeta): @@ -87,7 +88,7 @@ class Match (Module): input_vector = [] - for team in data: + for team in tqdm(data, desc = "Match Module ", unit = " team"): for variable in data[team]: @@ -174,7 +175,7 @@ class Metric (Module): red = {} blu = {} - for match in matches: + for match in tqdm(matches, desc = "Metric Module ", unit = " match"): red = self.client.load_metric(match, "red", self.config["tests"]) blu = self.client.load_metric(match, "blue", self.config["tests"]) @@ -290,7 +291,7 @@ class Pit (Module): def _process_data(self): tests = self.config["tests"] return_vector = {} - for team in self.data: + for team in tqdm(self.data, desc = "Pit Module ", unit = " team"): for variable in self.data[team]: if variable in tests: if not variable in return_vector: diff --git a/src/superscript.py b/src/superscript.py index afc919c..e70bb37 100644 --- a/src/superscript.py +++ b/src/superscript.py @@ -250,12 +250,12 @@ def main(logger, verbose, profile, debug, config_path): close_all() return 1 -def start(verbose, profile, debug, config_path): +def start(verbose, profile, debug, config_path, log_path): + + logger = Logger(verbose, profile, debug, file = log_path) if profile: - logger = Logger(verbose, profile, debug) - import cProfile, pstats, io profile = cProfile.Profile() profile.enable() @@ -268,15 +268,11 @@ def start(verbose, profile, debug, config_path): elif verbose: - logger = Logger(verbose, profile, debug) - exit_code = main(logger, verbose, profile, debug, config_path) sys.exit(exit_code) elif debug: - logger = Logger(verbose, profile, debug) - exit_code = main(logger, verbose, profile, debug, config_path) sys.exit(exit_code) @@ -289,7 +285,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description = "TRA data processing application.") parser.add_argument("mode", metavar = "MODE", type = str, nargs = 1, choices = ["verbose", "profile", "debug"], help = "verbose, debug, profile") parser.add_argument("--config", dest = "config", default = "config.json", type = str, help = "path to config file") - parser.add_argument("--logfile", dest = "logfile", default = "logfile", type = str, help = "path to log file") + parser.add_argument("--logfile", dest = "logfile", default = "logfile.log", type = str, help = "path to log file") args = parser.parse_args() @@ -297,10 +293,10 @@ if __name__ == "__main__": config_path = args.config log_path = args.logfile if mode == "verbose": - start(True, False, False, config_path = config_path) + start(True, False, False, config_path = config_path, log_path = log_path) elif mode == "profile": - start(False, True, False, config_path = config_path) + start(False, True, False, config_path = config_path, log_path = log_path) elif mode == "debug": - start(False, False, True, config_path = config_path) + start(False, False, True, config_path = config_path, log_path = log_path) exit(0) \ No newline at end of file