diff --git a/src/cli/config.py b/src/cli/config.py index 3160c4b..900d151 100644 --- a/src/cli/config.py +++ b/src/cli/config.py @@ -3,6 +3,7 @@ import json from multiprocessing import Pool import os from cerberus import Validator +from exceptions import ConfigurationError from data import set_database_config, get_database_config from interface import stderr, stdout, INF, ERR @@ -134,12 +135,6 @@ sample_json = """ } """ -class ConfigurationError (Exception): - code = None - def __init__(self, str, code): - super().__init__(str) - self.code = code - def parse_config_persistent(send, config): v = Validator(load_validation_schema(), allow_unknown = True) isValidated = v.validate(config) diff --git a/src/cli/exceptions.py b/src/cli/exceptions.py index 891668b..13d4103 100644 --- a/src/cli/exceptions.py +++ b/src/cli/exceptions.py @@ -2,4 +2,10 @@ class APIError(Exception): code = None def __init__(self, str, endpoint): super().__init__(str) - self.endpoint = endpoint \ No newline at end of file + self.endpoint = endpoint + +class ConfigurationError (Exception): + code = None + def __init__(self, str, code): + super().__init__(str) + self.code = code \ No newline at end of file diff --git a/src/cli/module.py b/src/cli/module.py index e6ef29a..763a348 100644 --- a/src/cli/module.py +++ b/src/cli/module.py @@ -2,7 +2,7 @@ import abc import data as d import signal import numpy as np -import tra_analysis as an +from tra_analysis import Analysis as an class Module(metaclass = abc.ABCMeta): @@ -54,7 +54,7 @@ class Match (Module): def _load_data(self): self.data = d.load_match(self.apikey, self.competition) - def _simplestats(data_test): + def _simplestats(self, data_test): signal.signal(signal.SIGINT, signal.SIG_IGN) @@ -103,7 +103,10 @@ 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)) + self.results = [] + for test_var_data in self.data: + self.results.append(self._simplestats(test_var_data)) def _push_results(self): diff --git a/src/cli/pull.py b/src/cli/pull.py index db2772f..5a95de6 100644 --- a/src/cli/pull.py +++ b/src/cli/pull.py @@ -1,66 +1,64 @@ import requests import json from exceptions import APIError - -def load_config(path): - with open(path, "r") as f: - return json.load(f) +from config import load_config url = "https://titanscouting.epochml.org" -config_tra = load_config("config.json") +config_tra = {} +load_config("config.json", config_tra) trakey = config_tra['persistent']['key']['tra'] def get_team_competition(): - endpoint = '/api/fetchTeamCompetition' - params = { - "CLIENT_ID": trakey['CLIENT_ID'], - "CLIENT_SECRET": trakey['CLIENT_SECRET'] - } - response = requests.request("GET", url + endpoint, params=params) - json = response.json() - if json['success']: - return json['competition'] - else: - raise APIError(json, endpoint) + endpoint = '/api/fetchTeamCompetition' + params = { + "CLIENT_ID": trakey['CLIENT_ID'], + "CLIENT_SECRET": trakey['CLIENT_SECRET'] + } + response = requests.request("GET", url + endpoint, params=params) + json = response.json() + if json['success']: + return json['competition'] + else: + raise APIError(json, endpoint) def get_team(): - endpoint = '/api/fetchTeamCompetition' - params = { - "CLIENT_ID": trakey['CLIENT_ID'], - "CLIENT_SECRET": trakey['CLIENT_SECRET'] - } - response = requests.request("GET", url + endpoint, params=params) - json = response.json() - if json['success']: - return json['team'] - else: - raise APIError(json, endpoint) + endpoint = '/api/fetchTeamCompetition' + params = { + "CLIENT_ID": trakey['CLIENT_ID'], + "CLIENT_SECRET": trakey['CLIENT_SECRET'] + } + response = requests.request("GET", url + endpoint, params=params) + json = response.json() + if json['success']: + return json['team'] + else: + raise APIError(json, endpoint) def get_team_match_data(competition, team_num): - endpoint = '/api/fetchAllTeamMatchData' - params = { - "competition": competition, - "teamScouted": team_num, - "CLIENT_ID": trakey['CLIENT_ID'], - "CLIENT_SECRET": trakey['CLIENT_SECRET'] - } - response = requests.request("GET", url + endpoint, params=params) - json = response.json() - if json['success']: - return json['data'][team_num] - else: - raise APIError(json, endpoint) + endpoint = '/api/fetchAllTeamMatchData' + params = { + "competition": competition, + "teamScouted": team_num, + "CLIENT_ID": trakey['CLIENT_ID'], + "CLIENT_SECRET": trakey['CLIENT_SECRET'] + } + response = requests.request("GET", url + endpoint, params=params) + json = response.json() + if json['success']: + return json['data'][team_num] + else: + raise APIError(json, endpoint) def get_teams_at_competition(competition): - endpoint = '/api/fetchAllTeamNicknamesAtCompetition' - params = { - "competition": competition, - "CLIENT_ID": trakey['CLIENT_ID'], - "CLIENT_SECRET": trakey['CLIENT_SECRET'] - } - response = requests.request("GET", url + endpoint, params=params) - json = response.json() - if json['success']: - return list(json['data'].keys()) - else: - raise APIError(json, endpoint) \ No newline at end of file + endpoint = '/api/fetchAllTeamNicknamesAtCompetition' + params = { + "competition": competition, + "CLIENT_ID": trakey['CLIENT_ID'], + "CLIENT_SECRET": trakey['CLIENT_SECRET'] + } + response = requests.request("GET", url + endpoint, params=params) + json = response.json() + if json['success']: + return list(json['data'].keys()) + else: + raise APIError(json, endpoint) \ No newline at end of file