patched issue in multiprocessing,

moved ConfigurationError to exceptions.py,
made pull use load_config in config.py
This commit is contained in:
Arthur Lu 2022-01-10 20:23:14 +00:00
parent 2f83604e14
commit aed03369c9
4 changed files with 64 additions and 62 deletions

View File

@ -3,6 +3,7 @@ import json
from multiprocessing import Pool from multiprocessing import Pool
import os import os
from cerberus import Validator from cerberus import Validator
from exceptions import ConfigurationError
from data import set_database_config, get_database_config from data import set_database_config, get_database_config
from interface import stderr, stdout, INF, ERR 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): def parse_config_persistent(send, config):
v = Validator(load_validation_schema(), allow_unknown = True) v = Validator(load_validation_schema(), allow_unknown = True)
isValidated = v.validate(config) isValidated = v.validate(config)

View File

@ -2,4 +2,10 @@ class APIError(Exception):
code = None code = None
def __init__(self, str, endpoint): def __init__(self, str, endpoint):
super().__init__(str) super().__init__(str)
self.endpoint = endpoint self.endpoint = endpoint
class ConfigurationError (Exception):
code = None
def __init__(self, str, code):
super().__init__(str)
self.code = code

View File

@ -2,7 +2,7 @@ import abc
import data as d import data as d
import signal import signal
import numpy as np import numpy as np
import tra_analysis as an from tra_analysis import Analysis as an
class Module(metaclass = abc.ABCMeta): class Module(metaclass = abc.ABCMeta):
@ -54,7 +54,7 @@ class Match (Module):
def _load_data(self): def _load_data(self):
self.data = d.load_match(self.apikey, self.competition) 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) signal.signal(signal.SIGINT, signal.SIG_IGN)
@ -103,7 +103,10 @@ class Match (Module):
input_vector.append((team, variable, test, data[team][variable])) input_vector.append((team, variable, test, data[team][variable]))
self.data = input_vector 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): def _push_results(self):

View File

@ -1,66 +1,64 @@
import requests import requests
import json import json
from exceptions import APIError from exceptions import APIError
from config import load_config
def load_config(path):
with open(path, "r") as f:
return json.load(f)
url = "https://titanscouting.epochml.org" 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'] trakey = config_tra['persistent']['key']['tra']
def get_team_competition(): def get_team_competition():
endpoint = '/api/fetchTeamCompetition' endpoint = '/api/fetchTeamCompetition'
params = { params = {
"CLIENT_ID": trakey['CLIENT_ID'], "CLIENT_ID": trakey['CLIENT_ID'],
"CLIENT_SECRET": trakey['CLIENT_SECRET'] "CLIENT_SECRET": trakey['CLIENT_SECRET']
} }
response = requests.request("GET", url + endpoint, params=params) response = requests.request("GET", url + endpoint, params=params)
json = response.json() json = response.json()
if json['success']: if json['success']:
return json['competition'] return json['competition']
else: else:
raise APIError(json, endpoint) raise APIError(json, endpoint)
def get_team(): def get_team():
endpoint = '/api/fetchTeamCompetition' endpoint = '/api/fetchTeamCompetition'
params = { params = {
"CLIENT_ID": trakey['CLIENT_ID'], "CLIENT_ID": trakey['CLIENT_ID'],
"CLIENT_SECRET": trakey['CLIENT_SECRET'] "CLIENT_SECRET": trakey['CLIENT_SECRET']
} }
response = requests.request("GET", url + endpoint, params=params) response = requests.request("GET", url + endpoint, params=params)
json = response.json() json = response.json()
if json['success']: if json['success']:
return json['team'] return json['team']
else: else:
raise APIError(json, endpoint) raise APIError(json, endpoint)
def get_team_match_data(competition, team_num): def get_team_match_data(competition, team_num):
endpoint = '/api/fetchAllTeamMatchData' endpoint = '/api/fetchAllTeamMatchData'
params = { params = {
"competition": competition, "competition": competition,
"teamScouted": team_num, "teamScouted": team_num,
"CLIENT_ID": trakey['CLIENT_ID'], "CLIENT_ID": trakey['CLIENT_ID'],
"CLIENT_SECRET": trakey['CLIENT_SECRET'] "CLIENT_SECRET": trakey['CLIENT_SECRET']
} }
response = requests.request("GET", url + endpoint, params=params) response = requests.request("GET", url + endpoint, params=params)
json = response.json() json = response.json()
if json['success']: if json['success']:
return json['data'][team_num] return json['data'][team_num]
else: else:
raise APIError(json, endpoint) raise APIError(json, endpoint)
def get_teams_at_competition(competition): def get_teams_at_competition(competition):
endpoint = '/api/fetchAllTeamNicknamesAtCompetition' endpoint = '/api/fetchAllTeamNicknamesAtCompetition'
params = { params = {
"competition": competition, "competition": competition,
"CLIENT_ID": trakey['CLIENT_ID'], "CLIENT_ID": trakey['CLIENT_ID'],
"CLIENT_SECRET": trakey['CLIENT_SECRET'] "CLIENT_SECRET": trakey['CLIENT_SECRET']
} }
response = requests.request("GET", url + endpoint, params=params) response = requests.request("GET", url + endpoint, params=params)
json = response.json() json = response.json()
if json['success']: if json['success']:
return list(json['data'].keys()) return list(json['data'].keys())
else: else:
raise APIError(json, endpoint) raise APIError(json, endpoint)