added file logging with default,

added basic progress bars for each module
This commit is contained in:
Arthur Lu 2022-03-30 04:53:40 +00:00
parent 5885224231
commit 0024a94f4e
3 changed files with 12 additions and 15 deletions

View File

@ -23,7 +23,7 @@ class Logger(L):
self.file = file self.file = file
if file != None: if file is not None:
self.targets.append(self._send_file) self.targets.append(self._send_file)
if profile: if profile:

View File

@ -2,6 +2,7 @@ import abc
import signal import signal
import numpy as np import numpy as np
from tra_analysis import Analysis as an from tra_analysis import Analysis as an
from tqdm import tqdm
class Module(metaclass = abc.ABCMeta): class Module(metaclass = abc.ABCMeta):
@ -87,7 +88,7 @@ class Match (Module):
input_vector = [] input_vector = []
for team in data: for team in tqdm(data, desc = "Match Module ", unit = " team"):
for variable in data[team]: for variable in data[team]:
@ -174,7 +175,7 @@ class Metric (Module):
red = {} red = {}
blu = {} 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"]) red = self.client.load_metric(match, "red", self.config["tests"])
blu = self.client.load_metric(match, "blue", self.config["tests"]) blu = self.client.load_metric(match, "blue", self.config["tests"])
@ -290,7 +291,7 @@ class Pit (Module):
def _process_data(self): def _process_data(self):
tests = self.config["tests"] tests = self.config["tests"]
return_vector = {} return_vector = {}
for team in self.data: for team in tqdm(self.data, desc = "Pit Module ", unit = " team"):
for variable in self.data[team]: for variable in self.data[team]:
if variable in tests: if variable in tests:
if not variable in return_vector: if not variable in return_vector:

View File

@ -250,12 +250,12 @@ def main(logger, verbose, profile, debug, config_path):
close_all() close_all()
return 1 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: if profile:
logger = Logger(verbose, profile, debug)
import cProfile, pstats, io import cProfile, pstats, io
profile = cProfile.Profile() profile = cProfile.Profile()
profile.enable() profile.enable()
@ -268,15 +268,11 @@ def start(verbose, profile, debug, config_path):
elif verbose: elif verbose:
logger = Logger(verbose, profile, debug)
exit_code = main(logger, verbose, profile, debug, config_path) exit_code = main(logger, verbose, profile, debug, config_path)
sys.exit(exit_code) sys.exit(exit_code)
elif debug: elif debug:
logger = Logger(verbose, profile, debug)
exit_code = main(logger, verbose, profile, debug, config_path) exit_code = main(logger, verbose, profile, debug, config_path)
sys.exit(exit_code) sys.exit(exit_code)
@ -289,7 +285,7 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description = "TRA data processing application.") 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("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("--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() args = parser.parse_args()
@ -297,10 +293,10 @@ if __name__ == "__main__":
config_path = args.config config_path = args.config
log_path = args.logfile log_path = args.logfile
if mode == "verbose": 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": 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": 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) exit(0)