changed Match module to use current data bindings

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2021-10-22 01:40:56 +00:00
parent 8966900341
commit afab67f8ef

View File

@ -23,89 +23,106 @@ class Match:
apikey = None apikey = None
tbakey = None tbakey = None
timestamp = None timestamp = None
teams = None competition = None
data = [] data = []
results = [] results = []
def __init__(self, config, apikey, tbakey, timestamp, teams): def __init__(self, config, apikey, tbakey, timestamp, competition):
self.config = config self.config = config
self.apikey = apikey self.apikey = apikey
self.tbakey = tbakey self.tbakey = tbakey
self.timestamp = timestamp self.timestamp = timestamp
self.teams = teams self.competition = competition
def validate_config(self): def validate_config(self):
return True, "" return True, ""
"""
if self.config == None:
return False, "config cannot be empty"
elif self.apikey == None or self.apikey == "":
return False, "apikey cannot be empty"
elif self.tbakey == None or self.tbakey == "":
return False, "tbakey cannot be empty"
elif not(self.config["scope"] in ["competition", "season", "none"]):
return False, "scope must be one of: (competition, season, none)"
elif self.config["agglomeration"] != "none":
return False, "agglomeration must be 'none', there are currently no supported Agglomeration methods"
elif self.config["tests"] == None:
return False, "tests must not be None, it may be empty {}"
else:
return True, ""
"""
def load_data(self): def load_data(self):
scope = self.config["scope"] self.data = d.load_match(self.apikey, self.competition)
for team in self.teams:
competitions = d.get_team_conpetitions(self.apikey, team, scope) # unimplemented def simplestats(data_test):
for competition in competitions:
for variable in self.config["tests"]:
match_data = d.get_team_match_data(self.apikey, competition, team, variable) # needs modified implementation
variable_tests = self.config["tests"][variable]
self.data.append({"team": team, "competition": competition, "variable": variable, "tests": variable_tests, "data": match_data})
def tests(test_data):
signal.signal(signal.SIGINT, signal.SIG_IGN) signal.signal(signal.SIGINT, signal.SIG_IGN)
if(test_data["data"] == None): data = np.array(data_test[3])
return None
data = np.array(test_data["data"])
data = data[np.isfinite(data)] data = data[np.isfinite(data)]
ranges = list(range(len(data))) ranges = list(range(len(data)))
tests = test_data["tests"] test = data_test[2]
results = {} if test == "basic_stats":
return an.basic_stats(data)
if "basic_stats" in tests: if test == "historical_analysis":
results["basic_stats"] = an.basic_stats(data) return an.histo_analysis([ranges, data])
if "historical_analysis" in tests:
results["historical_analysis"] = an.histo_analysis([ranges, data])
if "regression_linear" in tests:
results["regression_linear"] = an.regression(ranges, data, ['lin'])
if "regression_logarithmic" in tests:
results["regression_logarithmic"] = an.regression(ranges, data, ['log'])
if "regression_exponential" in tests:
results["regression_exponential"] = an.regression(ranges, data, ['exp'])
if "regression_polynomial" in tests:
results["regression_polynomial"] = an.regression(ranges, data, ['ply'])
if "regression_sigmoidal" in tests:
results["regression_sigmoidal"] = an.regression(ranges, data, ['sig'])
return results if test == "regression_linear":
return an.regression(ranges, data, ['lin'])
if test == "regression_logarithmic":
return an.regression(ranges, data, ['log'])
if test == "regression_exponential":
return an.regression(ranges, data, ['exp'])
if test == "regression_polynomial":
return an.regression(ranges, data, ['ply'])
if test == "regression_sigmoidal":
return an.regression(ranges, data, ['sig'])
def process_data(self, exec_threads): def process_data(self, exec_threads):
self.results = list(exec_threads.map(self.tests, self.data))
tests = self.config["tests"]
data = self.data
input_vector = []
for team in data:
for variable in data[team]:
if variable in tests:
for test in tests[variable]:
input_vector.append((team, variable, test, data[team][variable]))
self.data = input_vector
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"} short_mapping = {"regression_linear": "lin", "regression_logarithmic": "log", "regression_exponential": "exp", "regression_polynomial": "ply", "regression_sigmoidal": "sig"}
class AutoVivification(dict):
def __getitem__(self, item):
try:
return dict.__getitem__(self, item)
except KeyError:
value = self[item] = type(self)()
return value
result_filtered = self.results
input_vector = self.data
return_vector = AutoVivification()
i = 0 i = 0
for result in self.results:
for variable in result: for result in result_filtered:
if variable in short_mapping:
short = short_mapping[variable] filtered = input_vector[i][2]
else:
short = variable try:
d.push_team_match_results(self.data[i]["team"], self.data[i]["competition"], self.data[i]["variable"], short, result[variable]) # needs implementation short = short_mapping[filtered]
return_vector[input_vector[i][0]][input_vector[i][1]][input_vector[i][2]] = result[short]
except KeyError: # not in mapping
return_vector[input_vector[i][0]][input_vector[i][1]][input_vector[i][2]] = result
i += 1 i += 1
self.results = return_vector
d.push_match(self.apikey, self.competition, self.results)