From 60e88a59874f7fad8c3b54a55cd027ba3d97ee06 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 2 Nov 2021 05:37:27 +0000 Subject: [PATCH] formalized module interface Former-commit-id: 108284a94b2e63c3fc10b02b9f60739f4ccbbaba --- src/cli/module.py | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/cli/module.py b/src/cli/module.py index dfc9a16..233e1aa 100644 --- a/src/cli/module.py +++ b/src/cli/module.py @@ -1,24 +1,37 @@ +import abc import data as d import signal import numpy as np import tra_analysis as an -class Module: - config = None - data = None - results = None - def __init__(self, config, apikey, tbakey, timestamp): - pass - def validate_config(self): - pass - def load_data(self): - pass - def process_data(self, exec_threads): - pass - def push_results(self): - pass +class Module(metaclass = abc.ABCMeta): -class Match: + @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) + ) + + @abc.abstractmethod + def validate_config(self): + raise NotImplementedError + @abc.abstractmethod + def load_data(self): + raise NotImplementedError + @abc.abstractmethod + def process_data(self, exec_threads): + raise NotImplementedError + @abc.abstractmethod + def push_results(self): + raise NotImplementedError + +class Match (Module): config = None apikey = None @@ -128,7 +141,7 @@ class Match: d.push_match(self.apikey, self.competition, self.results) -class Metric: +class Metric (Module): config = None apikey = None @@ -248,7 +261,7 @@ class Metric: def push_results(self): pass -class Pit: +class Pit (Module): config = None apikey = None