2021-10-21 20:05:07 +00:00
|
|
|
import data as d
|
2021-10-21 21:27:35 +00:00
|
|
|
import signal
|
|
|
|
import numpy as np
|
|
|
|
import tra_analysis as an
|
2021-10-21 20:42:47 +00:00
|
|
|
|
2021-10-21 20:05:07 +00:00
|
|
|
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 Match:
|
|
|
|
config = None
|
|
|
|
apikey = None
|
|
|
|
tbakey = None
|
|
|
|
timestamp = None
|
|
|
|
teams = None
|
|
|
|
|
2021-10-21 20:42:47 +00:00
|
|
|
data = []
|
2021-10-21 21:27:35 +00:00
|
|
|
results = []
|
2021-10-21 20:05:07 +00:00
|
|
|
|
|
|
|
def __init__(self, config, apikey, tbakey, timestamp, teams):
|
|
|
|
self.config = config
|
|
|
|
self.apikey = apikey
|
|
|
|
self.tbakey = tbakey
|
|
|
|
self.timestamp = timestamp
|
|
|
|
self.teams = teams
|
|
|
|
|
|
|
|
def validate_config(self):
|
2021-10-21 20:42:47 +00:00
|
|
|
"""
|
2021-10-21 20:28:29 +00:00
|
|
|
if self.config == None:
|
2021-10-21 20:42:47 +00:00
|
|
|
return False, "config cannot be empty"
|
2021-10-21 20:28:29 +00:00
|
|
|
elif self.apikey == None or self.apikey == "":
|
2021-10-21 20:42:47 +00:00
|
|
|
return False, "apikey cannot be empty"
|
2021-10-21 20:28:29 +00:00
|
|
|
elif self.tbakey == None or self.tbakey == "":
|
2021-10-21 20:42:47 +00:00
|
|
|
return False, "tbakey cannot be empty"
|
2021-10-21 20:28:29 +00:00
|
|
|
elif not(self.config["scope"] in ["competition", "season", "none"]):
|
2021-10-21 20:42:47 +00:00
|
|
|
return False, "scope must be one of: (competition, season, none)"
|
2021-10-21 21:51:14 +00:00
|
|
|
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 {}"
|
2021-10-21 20:28:29 +00:00
|
|
|
else:
|
2021-10-21 20:42:47 +00:00
|
|
|
return True, ""
|
|
|
|
"""
|
2021-10-21 20:05:07 +00:00
|
|
|
|
|
|
|
def load_data(self):
|
2021-10-21 20:42:47 +00:00
|
|
|
scope = self.config["scope"]
|
|
|
|
for team in self.teams:
|
|
|
|
competitions = d.get_team_conpetitions(self.apikey, team, scope) # unimplemented
|
|
|
|
for competition in competitions:
|
|
|
|
for variable in self.config["tests"]:
|
2021-10-21 20:56:06 +00:00
|
|
|
match_data = d.get_team_match_data(self.apikey, competition, team, variable) # needs modified implementation
|
2021-10-21 21:27:35 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
if(test_data["data"] == None):
|
|
|
|
return None
|
|
|
|
|
|
|
|
data = np.array(test_data["data"])
|
|
|
|
data = data[np.isfinite(data)]
|
|
|
|
ranges = list(range(len(data)))
|
|
|
|
|
|
|
|
tests = test_data["tests"]
|
|
|
|
|
2021-10-21 21:29:44 +00:00
|
|
|
results = {}
|
2021-10-21 21:27:35 +00:00
|
|
|
|
|
|
|
if "basic_stats" in tests:
|
|
|
|
results["basic_stats"] = an.basic_stats(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
|
2021-10-21 20:05:07 +00:00
|
|
|
|
|
|
|
def process_data(self, exec_threads):
|
2021-10-21 21:27:35 +00:00
|
|
|
self.results = list(exec_threads.map(self.tests, self.data))
|
2021-10-21 20:05:07 +00:00
|
|
|
|
|
|
|
def push_results(self):
|
2021-10-21 21:27:35 +00:00
|
|
|
short_mapping = {"regression_linear": "lin", "regression_logarithmic": "log", "regression_exponential": "exp", "regression_polynomial": "ply", "regression_sigmoidal": "sig"}
|
|
|
|
i = 0
|
|
|
|
for result in self.results:
|
|
|
|
for variable in result:
|
|
|
|
if variable in short_mapping:
|
|
|
|
short = short_mapping[variable]
|
|
|
|
else:
|
|
|
|
short = variable
|
2021-10-21 21:29:44 +00:00
|
|
|
d.push_team_match_results(self.data[i]["team"], self.data[i]["competition"], self.data[i]["variable"], short, result[variable]) # needs implementation
|
2021-10-21 21:27:35 +00:00
|
|
|
i+=1
|