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
|
2021-10-22 01:40:56 +00:00
|
|
|
competition = None
|
2021-10-21 20:05:07 +00:00
|
|
|
|
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
|
|
|
|
2021-10-22 01:40:56 +00:00
|
|
|
def __init__(self, config, apikey, tbakey, timestamp, competition):
|
2021-10-21 20:05:07 +00:00
|
|
|
self.config = config
|
|
|
|
self.apikey = apikey
|
|
|
|
self.tbakey = tbakey
|
|
|
|
self.timestamp = timestamp
|
2021-10-22 01:40:56 +00:00
|
|
|
self.competition = competition
|
2021-10-21 20:05:07 +00:00
|
|
|
|
|
|
|
def validate_config(self):
|
2021-10-21 21:58:02 +00:00
|
|
|
return True, ""
|
2021-10-21 20:05:07 +00:00
|
|
|
|
|
|
|
def load_data(self):
|
2021-10-22 01:40:56 +00:00
|
|
|
self.data = d.load_match(self.apikey, self.competition)
|
|
|
|
|
|
|
|
def simplestats(data_test):
|
2021-10-21 21:27:35 +00:00
|
|
|
|
2021-10-22 01:40:56 +00:00
|
|
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
2021-10-21 21:27:35 +00:00
|
|
|
|
2021-10-22 01:40:56 +00:00
|
|
|
data = np.array(data_test[3])
|
2021-10-21 21:27:35 +00:00
|
|
|
data = data[np.isfinite(data)]
|
|
|
|
ranges = list(range(len(data)))
|
|
|
|
|
2021-10-22 01:40:56 +00:00
|
|
|
test = data_test[2]
|
|
|
|
|
|
|
|
if test == "basic_stats":
|
|
|
|
return an.basic_stats(data)
|
|
|
|
|
|
|
|
if test == "historical_analysis":
|
|
|
|
return an.histo_analysis([ranges, data])
|
|
|
|
|
|
|
|
if test == "regression_linear":
|
|
|
|
return an.regression(ranges, data, ['lin'])
|
|
|
|
|
|
|
|
if test == "regression_logarithmic":
|
|
|
|
return an.regression(ranges, data, ['log'])
|
2021-10-21 21:27:35 +00:00
|
|
|
|
2021-10-22 01:40:56 +00:00
|
|
|
if test == "regression_exponential":
|
|
|
|
return an.regression(ranges, data, ['exp'])
|
2021-10-21 21:27:35 +00:00
|
|
|
|
2021-10-22 01:40:56 +00:00
|
|
|
if test == "regression_polynomial":
|
|
|
|
return an.regression(ranges, data, ['ply'])
|
2021-10-21 21:27:35 +00:00
|
|
|
|
2021-10-22 01:40:56 +00:00
|
|
|
if test == "regression_sigmoidal":
|
|
|
|
return an.regression(ranges, data, ['sig'])
|
2021-10-21 20:05:07 +00:00
|
|
|
|
|
|
|
def process_data(self, exec_threads):
|
2021-10-22 01:40:56 +00:00
|
|
|
|
|
|
|
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))
|
2021-10-21 20:05:07 +00:00
|
|
|
|
|
|
|
def push_results(self):
|
2021-10-22 01:40:56 +00:00
|
|
|
|
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"}
|
2021-10-22 01:40:56 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2021-10-21 21:27:35 +00:00
|
|
|
i = 0
|
2021-10-22 01:40:56 +00:00
|
|
|
|
|
|
|
for result in result_filtered:
|
|
|
|
|
|
|
|
filtered = input_vector[i][2]
|
|
|
|
|
|
|
|
try:
|
|
|
|
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
|
|
|
|
|
|
|
|
self.results = return_vector
|
|
|
|
|
|
|
|
d.push_match(self.apikey, self.competition, self.results)
|