From ac66545226d5d25d7df8e80f2a4e3c2e12215fb4 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 23 Nov 2021 22:23:59 +0000 Subject: [PATCH] changed Module interface to 3 functions Signed-off-by: Arthur Lu Former-commit-id: 356b71be62ff0c9ca786bc53f0df91d637b802a5 --- src/cli/module.py | 63 +++++++++++++++++++++++++++--------------- src/cli/superscript.py | 4 +-- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/cli/module.py b/src/cli/module.py index b3cac88..3c89fc4 100644 --- a/src/cli/module.py +++ b/src/cli/module.py @@ -8,20 +8,24 @@ class Module(metaclass = abc.ABCMeta): @classmethod def __subclasshook__(cls, subclass): - return (hasattr(subclass, 'validate_config') and - callable(subclass.validate_config) and - hasattr(subclass, 'load_data') and - callable(subclass.load_data) and - hasattr(subclass, 'process_data') and - callable(subclass.process_data) and - hasattr(subclass, 'push_results') and - callable(subclass.push_results) + return (hasattr(subclass, '__init__') and + callable(subclass.__init__) and + hasattr(subclass, 'validate_config') and + callable(subclass.validate_config) and + hasattr(subclass, 'run') and + callable(subclass.run) ) - @abc.abstractmethod - def validate_config(self): + def __init__(self, config, apikey, tbakey, timestamp, competition, *args, **kwargs): raise NotImplementedError @abc.abstractmethod + def validate_config(self, *args, **kwargs): + raise NotImplementedError + @abc.abstractmethod + def run(self, exec_threads, *args, **kwargs): + raise NotImplementedError + """ + @abc.abstractmethod def load_data(self): raise NotImplementedError @abc.abstractmethod @@ -29,7 +33,7 @@ class Module(metaclass = abc.ABCMeta): raise NotImplementedError @abc.abstractmethod def push_results(self): - raise NotImplementedError + raise NotImplementedError""" class Match (Module): @@ -52,10 +56,15 @@ class Match (Module): def validate_config(self): return True, "" - def load_data(self): + def run(self, exec_threads): + self._load_data() + self._process_data(exec_threads) + self._push_results() + + def _load_data(self): self.data = d.load_match(self.apikey, self.competition) - def simplestats(data_test): + def _simplestats(data_test): signal.signal(signal.SIGINT, signal.SIG_IGN) @@ -86,7 +95,7 @@ class Match (Module): if test == "regression_sigmoidal": return an.regression(ranges, data, ['sig']) - def process_data(self, exec_threads): + def _process_data(self, exec_threads): tests = self.config["tests"] data = self.data @@ -104,9 +113,9 @@ class Match (Module): input_vector.append((team, variable, test, data[team][variable])) self.data = input_vector - self.results = list(exec_threads.map(self.simplestats, self.data)) + self.results = list(exec_threads.map(self._simplestats, self.data)) - def push_results(self): + def _push_results(self): short_mapping = {"regression_linear": "lin", "regression_logarithmic": "log", "regression_exponential": "exp", "regression_polynomial": "ply", "regression_sigmoidal": "sig"} @@ -162,10 +171,15 @@ class Metric (Module): def validate_config(self): return True, "" - def load_data(self): + def run(self, exec_threads): + self._load_data() + self._process_data(exec_threads) + self._push_results() + + def _load_data(self): self.data = d.pull_new_tba_matches(self.tbakey, self.competition, self.timestamp) - def process_data(self, exec_threads): + def _process_data(self, exec_threads): elo_N = self.config["tests"]["elo"]["N"] elo_K = self.config["tests"]["elo"]["K"] @@ -258,7 +272,7 @@ class Metric (Module): d.push_metric(self.client, self.competition, temp_vector) - def push_results(self): + def _push_results(self): pass class Pit (Module): @@ -282,10 +296,15 @@ class Pit (Module): def validate_config(self): return True, "" - def load_data(self): + def run(self, exec_threads): + self._load_data() + self._process_data(exec_threads) + self._push_results() + + def _load_data(self): self.data = d.load_pit(self.apikey, self.competition) - def process_data(self, exec_threads): + def _process_data(self, exec_threads): return_vector = {} for team in self.data: for variable in self.data[team]: @@ -296,7 +315,7 @@ class Pit (Module): self.results = return_vector - def push_results(self): + def _push_results(self): d.push_pit(self.apikey, self.competition, self.results) class Rating (Module): diff --git a/src/cli/superscript.py b/src/cli/superscript.py index e3f138f..064a371 100644 --- a/src/cli/superscript.py +++ b/src/cli/superscript.py @@ -223,9 +223,7 @@ def main(send, verbose = False, profile = False, debug = False): valid = current_module.validate_config() if not valid: continue - current_module.load_data() - current_module.process_data(exec_threads) - current_module.push_results() + current_module.run(exec_threads) send(stdout, INF, m + " module finished in " + str(time.time() - start) + " seconds") if debug: f = open(m + ".log", "w+")