From de994f812b332524b6818ac0562e6f10ae93c53f Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Wed, 10 Jun 2020 20:23:53 +0000 Subject: [PATCH] started on tra-cli.py modified tasks.py to work properly Signed-off-by: Arthur Lu --- data-analysis/tasks.py | 62 ++++++++++++++++++++-------------------- data-analysis/tra-cli.py | 23 +++++++++++++++ 2 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 data-analysis/tra-cli.py diff --git a/data-analysis/tasks.py b/data-analysis/tasks.py index eaa8877d..9b3f4ea9 100644 --- a/data-analysis/tasks.py +++ b/data-analysis/tasks.py @@ -18,62 +18,62 @@ class Tasker(): config = {} - def __init__(): + def __init__(self): - config = su.load_config("config.json") + self.config = su.load_config("config.json") - def match(): + def match(self): - match_ = True + self.match_ = True - apikey = config["key"]["database"] - competition = config["competition"] - tests = config["statistics"]["match"] + apikey = self.config["key"]["database"] + competition = self.config["competition"] + tests = self.config["statistics"]["match"] data = su.load_match(apikey, competition) su.matchloop(apikey, competition, data, tests) - match_ = False + self.match_ = False - if match_enable == True and match_ == False: + if self.match_enable == True and self.match_ == False: task = threading.Thread(name = "match", target = match) task.start() def metric(): - metric_ = True + self.metric_ = True - apikey = config["key"]["database"] - tbakey = config["key"]["tba"] - competition = config["competition"] - metric = config["statistics"]["metric"] + apikey = self.config["key"]["database"] + tbakey = self.config["key"]["tba"] + competition = self.config["competition"] + metric = self.config["statistics"]["metric"] timestamp = su.get_previous_time(apikey) su.metricloop(tbakey, apikey, competition, timestamp, metric) - metric_ = False + self.metric_ = False - if metric_enable == True and metric_ == False: + if self.metric_enable == True and self.metric_ == False: task = threading.Thread(name = "match", target = metric) task.start() def pit(): - pit_ = True + self.pit_ = True - apikey = config["key"]["database"] - competition = config["competition"] - tests = config["statistics"]["pit"] + apikey = self.config["key"]["database"] + competition = self.config["competition"] + tests = self.config["statistics"]["pit"] data = su.load_pit(apikey, competition) su.pitloop(apikey, competition, data, tests) - pit_ = False + self.pit_ = False - if pit_enable == True and pit_ == False: + if self.pit_enable == True and self.pit_ == False: task = threading.Thread(name = "pit", target = pit) task.start() @@ -91,31 +91,31 @@ class Tasker(): task.start() def stop_match(): - match_enable = False + self.match_enable = False def stop_metric(): - metric_enable = False + self.metric_enable = False def stop_pit(): - pit_enable = False + self.pit_enable = False def get_match(): - return match_ + return self.match_ def get_metric(): - return metric_ + return self.metric_ def get_pit(): - return pit_ + return self.pit_ def get_match_enable(): - return match_enable + return self.match_enable def get_metric_enable(): - return metric_enable + return self.metric_enable def get_pit_enable(): - return pit_enable + return self.pit_enable """ def main(): diff --git a/data-analysis/tra-cli.py b/data-analysis/tra-cli.py new file mode 100644 index 00000000..6c132e2c --- /dev/null +++ b/data-analysis/tra-cli.py @@ -0,0 +1,23 @@ +import argparse +from tasks import Tasker + +t = Tasker() + +task_map = {"match":None, "metric":None, "pit":None} +status_map = {"match":None, "metric":None, "pit":None} +status_map.update(task_map) + +parser = argparse.ArgumentParser(prog = "TRA") +subparsers = parser.add_subparsers(title = "command", metavar = "C", help = "//commandhelp//") + +parser_start = subparsers.add_parser("start", help = "//starthelp//") +parser_start.add_argument("target(s)", metavar = "T", nargs = "*", choices = task_map.keys()) + +parser_stop = subparsers.add_parser("stop", help = "//stophelp//") +parser_start.add_argument("target(s)", metavar = "T", nargs = "*", choices = task_map.keys()) + +parser_status = subparsers.add_parser("status", help = "//stophelp//") +parser_start.add_argument("target(s)", metavar = "T", nargs = "*", choices = status_map.keys()) + +args = parser.parse_args() +print(args) \ No newline at end of file