mirror of
https://github.com/titanscouting/tra-superscript.git
synced 2024-11-13 22:56:19 +00:00
merged data and pull functions into Client class,
removed pull.py dep.py, modified existing code to work with new Client class
This commit is contained in:
parent
2ebaddb92c
commit
e04245952a
@ -2,8 +2,6 @@ import json
|
|||||||
from exceptions import ConfigurationError
|
from exceptions import ConfigurationError
|
||||||
from cerberus import Validator
|
from cerberus import Validator
|
||||||
|
|
||||||
from data import set_database_config, get_database_config
|
|
||||||
|
|
||||||
class Configuration:
|
class Configuration:
|
||||||
|
|
||||||
path = None
|
path = None
|
||||||
@ -215,14 +213,14 @@ class Configuration:
|
|||||||
if sync:
|
if sync:
|
||||||
if priority == "local" or priority == "client":
|
if priority == "local" or priority == "client":
|
||||||
logger.info("config-preference set to local/client, loading local config information")
|
logger.info("config-preference set to local/client, loading local config information")
|
||||||
remote_config = get_database_config(client)
|
remote_config = client.get_database_config()
|
||||||
if remote_config != self.config["variable"]:
|
if remote_config != self.config["variable"]:
|
||||||
set_database_config(client, self.config["variable"])
|
client.set_database_config(self.config["variable"])
|
||||||
logger.info("database config was different and was updated")
|
logger.info("database config was different and was updated")
|
||||||
# no change to config
|
# no change to config
|
||||||
elif priority == "remote" or priority == "database":
|
elif priority == "remote" or priority == "database":
|
||||||
logger.info("config-preference set to remote/database, loading remote config information")
|
logger.info("config-preference set to remote/database, loading remote config information")
|
||||||
remote_config = get_database_config(client)
|
remote_config = client.get_database_config()
|
||||||
if remote_config != self.config["variable"]:
|
if remote_config != self.config["variable"]:
|
||||||
self.config["variable"] = remote_config
|
self.config["variable"] = remote_config
|
||||||
self.save_config()
|
self.save_config()
|
||||||
@ -236,7 +234,7 @@ class Configuration:
|
|||||||
# no change to config
|
# no change to config
|
||||||
elif priority == "remote" or priority == "database":
|
elif priority == "remote" or priority == "database":
|
||||||
logger.info("config-preference set to remote/database, loading database config information")
|
logger.info("config-preference set to remote/database, loading database config information")
|
||||||
self.config["variable"] = get_database_config(client)
|
self.config["variable"] = client.get_database_config()
|
||||||
# change variable to match remote without updating local version
|
# change variable to match remote without updating local version
|
||||||
else:
|
else:
|
||||||
raise ConfigurationError("persistent/config-preference field must be \"local\"/\"client\" or \"remote\"/\"database\"")
|
raise ConfigurationError("persistent/config-preference field must be \"local\"/\"client\" or \"remote\"/\"database\"")
|
305
src/data.py
305
src/data.py
@ -1,9 +1,22 @@
|
|||||||
import requests
|
import requests
|
||||||
import pull
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import pymongo
|
||||||
|
from exceptions import APIError
|
||||||
|
|
||||||
def pull_new_tba_matches(apikey, competition, cutoff):
|
class Client:
|
||||||
api_key= apikey
|
|
||||||
|
def __init__(self, config):
|
||||||
|
self.competition = config.competition
|
||||||
|
self.tbakey = config.tba
|
||||||
|
self.mongoclient = pymongo.MongoClient(config.database)
|
||||||
|
self.trakey = config.tra
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.mongoclient.close()
|
||||||
|
|
||||||
|
def pull_new_tba_matches(self, cutoff):
|
||||||
|
competition = self.competition
|
||||||
|
api_key= self.tbakey
|
||||||
x=requests.get("https://www.thebluealliance.com/api/v3/event/"+competition+"/matches/simple", headers={"X-TBA-Auth-Key":api_key})
|
x=requests.get("https://www.thebluealliance.com/api/v3/event/"+competition+"/matches/simple", headers={"X-TBA-Auth-Key":api_key})
|
||||||
out = []
|
out = []
|
||||||
for i in x.json():
|
for i in x.json():
|
||||||
@ -11,7 +24,9 @@ def pull_new_tba_matches(apikey, competition, cutoff):
|
|||||||
out.append({"match" : i['match_number'], "blue" : list(map(lambda x: int(x[3:]), i['alliances']['blue']['team_keys'])), "red" : list(map(lambda x: int(x[3:]), i['alliances']['red']['team_keys'])), "winner": i["winning_alliance"]})
|
out.append({"match" : i['match_number'], "blue" : list(map(lambda x: int(x[3:]), i['alliances']['blue']['team_keys'])), "red" : list(map(lambda x: int(x[3:]), i['alliances']['red']['team_keys'])), "winner": i["winning_alliance"]})
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def get_team_match_data(client, competition, team_num):
|
def get_team_match_data(self, team_num):
|
||||||
|
client = self.mongoclient
|
||||||
|
competition = self.competition
|
||||||
db = client.data_scouting
|
db = client.data_scouting
|
||||||
mdata = db.matchdata
|
mdata = db.matchdata
|
||||||
out = {}
|
out = {}
|
||||||
@ -19,89 +34,21 @@ def get_team_match_data(client, competition, team_num):
|
|||||||
out[i['match']] = i['data']
|
out[i['match']] = i['data']
|
||||||
return pd.DataFrame(out)
|
return pd.DataFrame(out)
|
||||||
|
|
||||||
def get_team_pit_data(client, competition, team_num):
|
def get_team_metrics_data(self, team_num):
|
||||||
db = client.data_scouting
|
client = self.mongoclient
|
||||||
mdata = db.pitdata
|
competition = self.competition
|
||||||
out = {}
|
|
||||||
return mdata.find_one({"competition" : competition, "team_scouted": str(team_num)})["data"]
|
|
||||||
|
|
||||||
def get_team_metrics_data(client, competition, team_num):
|
|
||||||
db = client.data_processing
|
db = client.data_processing
|
||||||
mdata = db.team_metrics
|
mdata = db.team_metrics
|
||||||
return mdata.find_one({"competition" : competition, "team": team_num})
|
return mdata.find_one({"competition" : competition, "team": team_num})
|
||||||
|
|
||||||
def get_match_data_formatted(client, competition):
|
def get_team_pit_data(self, team_num):
|
||||||
teams_at_comp = pull.get_teams_at_competition(competition)
|
client = self.mongoclient
|
||||||
out = {}
|
competition = self.competition
|
||||||
for team in teams_at_comp:
|
db = client.data_scouting
|
||||||
try:
|
mdata = db.pitdata
|
||||||
out[int(team)] = unkeyify_2l(get_team_match_data(client, competition, team).transpose().to_dict())
|
return mdata.find_one({"competition" : competition, "team_scouted": str(team_num)})["data"]
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return out
|
|
||||||
|
|
||||||
def get_metrics_data_formatted(client, competition):
|
def unkeyify_2l(self, layered_dict):
|
||||||
teams_at_comp = pull.get_teams_at_competition(competition)
|
|
||||||
out = {}
|
|
||||||
for team in teams_at_comp:
|
|
||||||
try:
|
|
||||||
out[int(team)] = get_team_metrics_data(client, competition, int(team))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return out
|
|
||||||
|
|
||||||
def get_pit_data_formatted(client, competition):
|
|
||||||
x=requests.get("https://titanscouting.epochml.org/api/fetchAllTeamNicknamesAtCompetition?competition="+competition)
|
|
||||||
x = x.json()
|
|
||||||
x = x['data']
|
|
||||||
x = x.keys()
|
|
||||||
out = {}
|
|
||||||
for i in x:
|
|
||||||
try:
|
|
||||||
out[int(i)] = get_team_pit_data(client, competition, int(i))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return out
|
|
||||||
|
|
||||||
def get_pit_variable_data(client, competition):
|
|
||||||
db = client.data_processing
|
|
||||||
mdata = db.team_pit
|
|
||||||
out = {}
|
|
||||||
return mdata.find()
|
|
||||||
|
|
||||||
def get_pit_variable_formatted(client, competition):
|
|
||||||
temp = get_pit_variable_data(client, competition)
|
|
||||||
out = {}
|
|
||||||
for i in temp:
|
|
||||||
out[i["variable"]] = i["data"]
|
|
||||||
return out
|
|
||||||
|
|
||||||
def push_team_tests_data(client, competition, team_num, data, dbname = "data_processing", colname = "team_tests"):
|
|
||||||
db = client[dbname]
|
|
||||||
mdata = db[colname]
|
|
||||||
mdata.replace_one({"competition" : competition, "team": team_num}, {"_id": competition+str(team_num)+"am", "competition" : competition, "team" : team_num, "data" : data}, True)
|
|
||||||
|
|
||||||
def push_team_metrics_data(client, competition, team_num, data, dbname = "data_processing", colname = "team_metrics"):
|
|
||||||
db = client[dbname]
|
|
||||||
mdata = db[colname]
|
|
||||||
mdata.replace_one({"competition" : competition, "team": team_num}, {"_id": competition+str(team_num)+"am", "competition" : competition, "team" : team_num, "metrics" : data}, True)
|
|
||||||
|
|
||||||
def push_team_pit_data(client, competition, variable, data, dbname = "data_processing", colname = "team_pit"):
|
|
||||||
db = client[dbname]
|
|
||||||
mdata = db[colname]
|
|
||||||
mdata.replace_one({"competition" : competition, "variable": variable}, {"competition" : competition, "variable" : variable, "data" : data}, True)
|
|
||||||
|
|
||||||
def get_analysis_flags(client, flag):
|
|
||||||
db = client.data_processing
|
|
||||||
mdata = db.flags
|
|
||||||
return mdata.find_one({flag:{"$exists":True}})
|
|
||||||
|
|
||||||
def set_analysis_flags(client, flag, data):
|
|
||||||
db = client.data_processing
|
|
||||||
mdata = db.flags
|
|
||||||
return mdata.replace_one({flag:{"$exists":True}}, data, True)
|
|
||||||
|
|
||||||
def unkeyify_2l(layered_dict):
|
|
||||||
out = {}
|
out = {}
|
||||||
for i in layered_dict.keys():
|
for i in layered_dict.keys():
|
||||||
add = []
|
add = []
|
||||||
@ -112,13 +59,95 @@ def unkeyify_2l(layered_dict):
|
|||||||
out[i] = list(map(lambda x: x[1], add))
|
out[i] = list(map(lambda x: x[1], add))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def get_previous_time(client):
|
def get_match_data_formatted(self):
|
||||||
|
teams_at_comp = self.get_teams_at_competition()
|
||||||
|
out = {}
|
||||||
|
for team in teams_at_comp:
|
||||||
|
try:
|
||||||
|
out[int(team)] = self.unkeyify_2l(self.get_team_match_data(team).transpose().to_dict())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return out
|
||||||
|
|
||||||
previous_time = get_analysis_flags(client, "latest_update")
|
def get_metrics_data_formatted(self):
|
||||||
|
competition = self.competition
|
||||||
|
teams_at_comp = self.get_teams_at_competition()
|
||||||
|
out = {}
|
||||||
|
for team in teams_at_comp:
|
||||||
|
try:
|
||||||
|
out[int(team)] = self.get_team_metrics_data(int(team))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return out
|
||||||
|
|
||||||
|
def get_pit_data_formatted(self):
|
||||||
|
client = self.mongoclient
|
||||||
|
competition = self.competition
|
||||||
|
x=requests.get("https://titanscouting.epochml.org/api/fetchAllTeamNicknamesAtCompetition?competition="+competition)
|
||||||
|
x = x.json()
|
||||||
|
x = x['data']
|
||||||
|
x = x.keys()
|
||||||
|
out = {}
|
||||||
|
for i in x:
|
||||||
|
try:
|
||||||
|
out[int(i)] = self.get_team_pit_data(int(i))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return out
|
||||||
|
|
||||||
|
def get_pit_variable_data(self):
|
||||||
|
client = self.mongoclient
|
||||||
|
db = client.data_processing
|
||||||
|
mdata = db.team_pit
|
||||||
|
return mdata.find()
|
||||||
|
|
||||||
|
def get_pit_variable_formatted(self):
|
||||||
|
temp = self.get_pit_variable_data()
|
||||||
|
out = {}
|
||||||
|
for i in temp:
|
||||||
|
out[i["variable"]] = i["data"]
|
||||||
|
return out
|
||||||
|
|
||||||
|
def push_team_tests_data(self, team_num, data, dbname = "data_processing", colname = "team_tests"):
|
||||||
|
client = self.mongoclient
|
||||||
|
competition = self.competition
|
||||||
|
db = client[dbname]
|
||||||
|
mdata = db[colname]
|
||||||
|
mdata.replace_one({"competition" : competition, "team": team_num}, {"_id": competition+str(team_num)+"am", "competition" : competition, "team" : team_num, "data" : data}, True)
|
||||||
|
|
||||||
|
def push_team_metrics_data(self, team_num, data, dbname = "data_processing", colname = "team_metrics"):
|
||||||
|
client = self.mongoclient
|
||||||
|
competition = self.competition
|
||||||
|
db = client[dbname]
|
||||||
|
mdata = db[colname]
|
||||||
|
mdata.replace_one({"competition" : competition, "team": team_num}, {"_id": competition+str(team_num)+"am", "competition" : competition, "team" : team_num, "metrics" : data}, True)
|
||||||
|
|
||||||
|
def push_team_pit_data(self, variable, data, dbname = "data_processing", colname = "team_pit"):
|
||||||
|
client = self.mongoclient
|
||||||
|
competition = self.competition
|
||||||
|
db = client[dbname]
|
||||||
|
mdata = db[colname]
|
||||||
|
mdata.replace_one({"competition" : competition, "variable": variable}, {"competition" : competition, "variable" : variable, "data" : data}, True)
|
||||||
|
|
||||||
|
def get_analysis_flags(self, flag):
|
||||||
|
client = self.mongoclient
|
||||||
|
db = client.data_processing
|
||||||
|
mdata = db.flags
|
||||||
|
return mdata.find_one({flag:{"$exists":True}})
|
||||||
|
|
||||||
|
def set_analysis_flags(self, flag, data):
|
||||||
|
client = self.mongoclient
|
||||||
|
db = client.data_processing
|
||||||
|
mdata = db.flags
|
||||||
|
return mdata.replace_one({flag:{"$exists":True}}, data, True)
|
||||||
|
|
||||||
|
def get_previous_time(self):
|
||||||
|
|
||||||
|
previous_time = self.get_analysis_flags("latest_update")
|
||||||
|
|
||||||
if previous_time == None:
|
if previous_time == None:
|
||||||
|
|
||||||
set_analysis_flags(client, "latest_update", 0)
|
self.set_analysis_flags("latest_update", 0)
|
||||||
previous_time = 0
|
previous_time = 0
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -127,30 +156,30 @@ def get_previous_time(client):
|
|||||||
|
|
||||||
return previous_time
|
return previous_time
|
||||||
|
|
||||||
def set_current_time(client, current_time):
|
def set_current_time(self, current_time):
|
||||||
|
|
||||||
set_analysis_flags(client, "latest_update", {"latest_update":current_time})
|
self.set_analysis_flags("latest_update", {"latest_update":current_time})
|
||||||
|
|
||||||
def get_database_config(client):
|
def get_database_config(self):
|
||||||
|
|
||||||
remote_config = get_analysis_flags(client, "config")
|
remote_config = self.get_analysis_flags("config")
|
||||||
return remote_config["config"] if remote_config != None else None
|
return remote_config["config"] if remote_config != None else None
|
||||||
|
|
||||||
def set_database_config(client, config):
|
def set_database_config(self, config):
|
||||||
|
|
||||||
set_analysis_flags(client, "config", {"config": config})
|
self.set_analysis_flags("config", {"config": config})
|
||||||
|
|
||||||
def load_match(client, competition):
|
def load_match(self):
|
||||||
|
|
||||||
return get_match_data_formatted(client, competition)
|
return self.get_match_data_formatted()
|
||||||
|
|
||||||
def load_metric(client, competition, match, group_name, metrics):
|
def load_metric(self, match, group_name, metrics):
|
||||||
|
|
||||||
group = {}
|
group = {}
|
||||||
|
|
||||||
for team in match[group_name]:
|
for team in match[group_name]:
|
||||||
|
|
||||||
db_data = get_team_metrics_data(client, competition, team)
|
db_data = self.get_team_metrics_data(team)
|
||||||
|
|
||||||
if db_data == None:
|
if db_data == None:
|
||||||
|
|
||||||
@ -172,28 +201,96 @@ def load_metric(client, competition, match, group_name, metrics):
|
|||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def load_pit(client, competition):
|
def load_pit(self):
|
||||||
|
|
||||||
return get_pit_data_formatted(client, competition)
|
return self.get_pit_data_formatted()
|
||||||
|
|
||||||
def push_match(client, competition, results):
|
def push_match(self, results):
|
||||||
|
|
||||||
for team in results:
|
for team in results:
|
||||||
|
|
||||||
push_team_tests_data(client, competition, team, results[team])
|
self.push_team_tests_data(team, results[team])
|
||||||
|
|
||||||
def push_metric(client, competition, metric):
|
def push_metric(self, metric):
|
||||||
|
|
||||||
for team in metric:
|
for team in metric:
|
||||||
|
|
||||||
push_team_metrics_data(client, competition, team, metric[team])
|
self.push_team_metrics_data(team, metric[team])
|
||||||
|
|
||||||
def push_pit(client, competition, pit):
|
def push_pit(self, pit):
|
||||||
|
|
||||||
for variable in pit:
|
for variable in pit:
|
||||||
|
|
||||||
push_team_pit_data(client, competition, variable, pit[variable])
|
self.push_team_pit_data(variable, pit[variable])
|
||||||
|
|
||||||
def check_new_database_matches(client, competition):
|
def check_new_database_matches(self):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
#----- API implementations below -----#
|
||||||
|
|
||||||
|
def get_team_competition(self):
|
||||||
|
trakey = self.trakey
|
||||||
|
url = self.trakey['url']
|
||||||
|
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)
|
||||||
|
|
||||||
|
def get_team(self):
|
||||||
|
trakey = self.trakey
|
||||||
|
url = self.trakey['url']
|
||||||
|
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)
|
||||||
|
|
||||||
|
""" doesn't seem to be functional:
|
||||||
|
def get_team_match_data(self, team_num):
|
||||||
|
trakey = self.trakey
|
||||||
|
url = self.trakey['url']
|
||||||
|
competition = self.competition
|
||||||
|
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)"""
|
||||||
|
|
||||||
|
def get_teams_at_competition(self):
|
||||||
|
trakey = self.trakey
|
||||||
|
url = self.trakey['url']
|
||||||
|
competition = self.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)
|
141
src/dep.py
141
src/dep.py
@ -1,141 +0,0 @@
|
|||||||
# contains deprecated functions, not to be used unless nessasary!
|
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
sample_json = """
|
|
||||||
{
|
|
||||||
"persistent":{
|
|
||||||
"key":{
|
|
||||||
"database":"",
|
|
||||||
"tba":"",
|
|
||||||
"tra":{
|
|
||||||
"CLIENT_ID":"",
|
|
||||||
"CLIENT_SECRET":"",
|
|
||||||
"url": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"config-preference":"local",
|
|
||||||
"synchronize-config":false
|
|
||||||
},
|
|
||||||
"variable":{
|
|
||||||
"max-threads":0.5,
|
|
||||||
"team":"",
|
|
||||||
"event-delay":false,
|
|
||||||
"loop-delay":0,
|
|
||||||
"reportable":true,
|
|
||||||
"teams":[
|
|
||||||
|
|
||||||
],
|
|
||||||
"modules":{
|
|
||||||
"match":{
|
|
||||||
"tests":{
|
|
||||||
"balls-blocked":[
|
|
||||||
"basic_stats",
|
|
||||||
"historical_analysis",
|
|
||||||
"regression_linear",
|
|
||||||
"regression_logarithmic",
|
|
||||||
"regression_exponential",
|
|
||||||
"regression_polynomial",
|
|
||||||
"regression_sigmoidal"
|
|
||||||
],
|
|
||||||
"balls-collected":[
|
|
||||||
"basic_stats",
|
|
||||||
"historical_analysis",
|
|
||||||
"regression_linear",
|
|
||||||
"regression_logarithmic",
|
|
||||||
"regression_exponential",
|
|
||||||
"regression_polynomial",
|
|
||||||
"regression_sigmoidal"
|
|
||||||
],
|
|
||||||
"balls-lower-teleop":[
|
|
||||||
"basic_stats",
|
|
||||||
"historical_analysis",
|
|
||||||
"regression_linear",
|
|
||||||
"regression_logarithmic",
|
|
||||||
"regression_exponential",
|
|
||||||
"regression_polynomial",
|
|
||||||
"regression_sigmoidal"
|
|
||||||
],
|
|
||||||
"balls-lower-auto":[
|
|
||||||
"basic_stats",
|
|
||||||
"historical_analysis",
|
|
||||||
"regression_linear",
|
|
||||||
"regression_logarithmic",
|
|
||||||
"regression_exponential",
|
|
||||||
"regression_polynomial",
|
|
||||||
"regression_sigmoidal"
|
|
||||||
],
|
|
||||||
"balls-started":[
|
|
||||||
"basic_stats",
|
|
||||||
"historical_analyss",
|
|
||||||
"regression_linear",
|
|
||||||
"regression_logarithmic",
|
|
||||||
"regression_exponential",
|
|
||||||
"regression_polynomial",
|
|
||||||
"regression_sigmoidal"
|
|
||||||
],
|
|
||||||
"balls-upper-teleop":[
|
|
||||||
"basic_stats",
|
|
||||||
"historical_analysis",
|
|
||||||
"regression_linear",
|
|
||||||
"regression_logarithmic",
|
|
||||||
"regression_exponential",
|
|
||||||
"regression_polynomial",
|
|
||||||
"regression_sigmoidal"
|
|
||||||
],
|
|
||||||
"balls-upper-auto":[
|
|
||||||
"basic_stats",
|
|
||||||
"historical_analysis",
|
|
||||||
"regression_linear",
|
|
||||||
"regression_logarithmic",
|
|
||||||
"regression_exponential",
|
|
||||||
"regression_polynomial",
|
|
||||||
"regression_sigmoidal"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"metric":{
|
|
||||||
"tests":{
|
|
||||||
"elo":{
|
|
||||||
"score":1500,
|
|
||||||
"N":400,
|
|
||||||
"K":24
|
|
||||||
},
|
|
||||||
"gl2":{
|
|
||||||
"score":1500,
|
|
||||||
"rd":250,
|
|
||||||
"vol":0.06
|
|
||||||
},
|
|
||||||
"ts":{
|
|
||||||
"mu":25,
|
|
||||||
"sigma":8.33
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"pit":{
|
|
||||||
"tests":{
|
|
||||||
"wheel-mechanism":true,
|
|
||||||
"low-balls":true,
|
|
||||||
"high-balls":true,
|
|
||||||
"wheel-success":true,
|
|
||||||
"strategic-focus":true,
|
|
||||||
"climb-mechanism":true,
|
|
||||||
"attitude":true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def load_config(path, config_vector):
|
|
||||||
try:
|
|
||||||
f = open(path, "r")
|
|
||||||
config_vector.update(json.load(f))
|
|
||||||
f.close()
|
|
||||||
return 0
|
|
||||||
except:
|
|
||||||
f = open(path, "w")
|
|
||||||
f.write(sample_json)
|
|
||||||
f.close()
|
|
||||||
return 1
|
|
@ -1,5 +1,4 @@
|
|||||||
import abc
|
import abc
|
||||||
import data as d
|
|
||||||
import signal
|
import signal
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from tra_analysis import Analysis as an
|
from tra_analysis import Analysis as an
|
||||||
@ -28,20 +27,16 @@ class Module(metaclass = abc.ABCMeta):
|
|||||||
class Match (Module):
|
class Match (Module):
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
apikey = None
|
|
||||||
tbakey = None
|
|
||||||
timestamp = None
|
timestamp = None
|
||||||
competition = None
|
client = None
|
||||||
|
|
||||||
data = None
|
data = None
|
||||||
results = None
|
results = None
|
||||||
|
|
||||||
def __init__(self, config, apikey, tbakey, timestamp, competition):
|
def __init__(self, config, timestamp, client):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.apikey = apikey
|
|
||||||
self.tbakey = tbakey
|
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
self.competition = competition
|
self.client = client
|
||||||
|
|
||||||
def validate_config(self):
|
def validate_config(self):
|
||||||
return True, ""
|
return True, ""
|
||||||
@ -52,7 +47,7 @@ class Match (Module):
|
|||||||
self._push_results()
|
self._push_results()
|
||||||
|
|
||||||
def _load_data(self):
|
def _load_data(self):
|
||||||
self.data = d.load_match(self.apikey, self.competition)
|
self.data = self.client.load_match()
|
||||||
|
|
||||||
def _simplestats(self, data_test):
|
def _simplestats(self, data_test):
|
||||||
|
|
||||||
@ -140,25 +135,21 @@ class Match (Module):
|
|||||||
|
|
||||||
self.results = return_vector
|
self.results = return_vector
|
||||||
|
|
||||||
d.push_match(self.apikey, self.competition, self.results)
|
self.client.push_match(self.results)
|
||||||
|
|
||||||
class Metric (Module):
|
class Metric (Module):
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
apikey = None
|
|
||||||
tbakey = None
|
|
||||||
timestamp = None
|
timestamp = None
|
||||||
competition = None
|
client = None
|
||||||
|
|
||||||
data = None
|
data = None
|
||||||
results = None
|
results = None
|
||||||
|
|
||||||
def __init__(self, config, apikey, tbakey, timestamp, competition):
|
def __init__(self, config, timestamp, client):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.apikey = apikey
|
|
||||||
self.tbakey = tbakey
|
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
self.competition = competition
|
self.client = client
|
||||||
|
|
||||||
def validate_config(self):
|
def validate_config(self):
|
||||||
return True, ""
|
return True, ""
|
||||||
@ -169,7 +160,7 @@ class Metric (Module):
|
|||||||
self._push_results()
|
self._push_results()
|
||||||
|
|
||||||
def _load_data(self):
|
def _load_data(self):
|
||||||
self.data = d.pull_new_tba_matches(self.tbakey, self.competition, self.timestamp)
|
self.data = self.client.pull_new_tba_matches(self.timestamp)
|
||||||
|
|
||||||
def _process_data(self):
|
def _process_data(self):
|
||||||
|
|
||||||
@ -183,8 +174,8 @@ class Metric (Module):
|
|||||||
|
|
||||||
for match in matches:
|
for match in matches:
|
||||||
|
|
||||||
red = d.load_metric(self.apikey, self.competition, match, "red", self.config["tests"])
|
red = self.client.load_metric(match, "red", self.config["tests"])
|
||||||
blu = d.load_metric(self.apikey, self.competition, match, "blue", self.config["tests"])
|
blu = self.client.load_metric(match, "blue", self.config["tests"])
|
||||||
|
|
||||||
elo_red_total = 0
|
elo_red_total = 0
|
||||||
elo_blu_total = 0
|
elo_blu_total = 0
|
||||||
@ -262,7 +253,7 @@ class Metric (Module):
|
|||||||
temp_vector.update(red)
|
temp_vector.update(red)
|
||||||
temp_vector.update(blu)
|
temp_vector.update(blu)
|
||||||
|
|
||||||
d.push_metric(self.apikey, self.competition, temp_vector)
|
self.client.push_metric(temp_vector)
|
||||||
|
|
||||||
def _push_results(self):
|
def _push_results(self):
|
||||||
pass
|
pass
|
||||||
@ -270,20 +261,16 @@ class Metric (Module):
|
|||||||
class Pit (Module):
|
class Pit (Module):
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
apikey = None
|
|
||||||
tbakey = None
|
|
||||||
timestamp = None
|
timestamp = None
|
||||||
competition = None
|
client = None
|
||||||
|
|
||||||
data = None
|
data = None
|
||||||
results = None
|
results = None
|
||||||
|
|
||||||
def __init__(self, config, apikey, tbakey, timestamp, competition):
|
def __init__(self, config, timestamp, client):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.apikey = apikey
|
|
||||||
self.tbakey = tbakey
|
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
self.competition = competition
|
self.client = client
|
||||||
|
|
||||||
def validate_config(self):
|
def validate_config(self):
|
||||||
return True, ""
|
return True, ""
|
||||||
@ -294,7 +281,7 @@ class Pit (Module):
|
|||||||
self._push_results()
|
self._push_results()
|
||||||
|
|
||||||
def _load_data(self):
|
def _load_data(self):
|
||||||
self.data = d.load_pit(self.apikey, self.competition)
|
self.data = self.client.load_pit()
|
||||||
|
|
||||||
def _process_data(self):
|
def _process_data(self):
|
||||||
tests = self.config["tests"]
|
tests = self.config["tests"]
|
||||||
@ -309,7 +296,7 @@ class Pit (Module):
|
|||||||
self.results = return_vector
|
self.results = return_vector
|
||||||
|
|
||||||
def _push_results(self):
|
def _push_results(self):
|
||||||
d.push_pit(self.apikey, self.competition, self.results)
|
self.client.push_pit(self.results)
|
||||||
|
|
||||||
class Rating (Module):
|
class Rating (Module):
|
||||||
pass
|
pass
|
||||||
|
63
src/pull.py
63
src/pull.py
@ -1,63 +0,0 @@
|
|||||||
import requests
|
|
||||||
from exceptions import APIError
|
|
||||||
from dep import load_config
|
|
||||||
|
|
||||||
url = "https://titanscouting.epochml.org"
|
|
||||||
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)
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
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)
|
|
@ -148,12 +148,9 @@ __author__ = (
|
|||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
import os, sys, time
|
import sys, time, traceback, warnings
|
||||||
import pymongo # soon to be deprecated
|
|
||||||
import traceback
|
|
||||||
import warnings
|
|
||||||
from config import Configuration, ConfigurationError
|
from config import Configuration, ConfigurationError
|
||||||
from data import get_previous_time, set_current_time, check_new_database_matches
|
from data import Client
|
||||||
from interface import Logger
|
from interface import Logger
|
||||||
from module import Match, Metric, Pit
|
from module import Match, Metric, Pit
|
||||||
|
|
||||||
@ -182,25 +179,24 @@ def main(logger, verbose, profile, debug, config_path):
|
|||||||
|
|
||||||
logger.info("found and loaded config at <" + config_path + ">")
|
logger.info("found and loaded config at <" + config_path + ">")
|
||||||
|
|
||||||
apikey, tbakey = config.database, config.tba
|
client = Client(config)
|
||||||
|
|
||||||
logger.info("found and loaded database and tba keys")
|
|
||||||
|
|
||||||
client = pymongo.MongoClient(apikey)
|
|
||||||
|
|
||||||
logger.info("established connection to database")
|
logger.info("established connection to database")
|
||||||
|
|
||||||
previous_time = get_previous_time(client)
|
previous_time = client.get_previous_time()
|
||||||
|
|
||||||
logger.info("analysis backtimed to: " + str(previous_time))
|
logger.info("analysis backtimed to: " + str(previous_time))
|
||||||
|
|
||||||
config.resolve_config_conflicts(logger, client)
|
config.resolve_config_conflicts(logger, client)
|
||||||
|
|
||||||
config_modules, competition = config.modules, config.competition
|
config_modules, competition = config.modules, config.competition
|
||||||
|
|
||||||
|
client.competition = competition
|
||||||
|
|
||||||
for m in config_modules:
|
for m in config_modules:
|
||||||
if m in modules:
|
if m in modules:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
current_module = modules[m](config_modules[m], client, tbakey, previous_time, competition)
|
current_module = modules[m](config_modules[m], previous_time, client)
|
||||||
valid = current_module.validate_config()
|
valid = current_module.validate_config()
|
||||||
if not valid:
|
if not valid:
|
||||||
continue
|
continue
|
||||||
@ -209,7 +205,7 @@ def main(logger, verbose, profile, debug, config_path):
|
|||||||
if debug:
|
if debug:
|
||||||
logger.save_module_to_file(m, current_module.data, current_module.results) # logging flag check done in logger
|
logger.save_module_to_file(m, current_module.data, current_module.results) # logging flag check done in logger
|
||||||
|
|
||||||
set_current_time(client, loop_start)
|
client.set_current_time(loop_start)
|
||||||
close_all()
|
close_all()
|
||||||
|
|
||||||
logger.info("closed threads and database client")
|
logger.info("closed threads and database client")
|
||||||
@ -227,7 +223,7 @@ def main(logger, verbose, profile, debug, config_path):
|
|||||||
new_match = False
|
new_match = False
|
||||||
while not new_match:
|
while not new_match:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
new_match = check_new_database_matches(client, competition)
|
new_match = client.check_new_database_matches()
|
||||||
logger.info("database returned new matches")
|
logger.info("database returned new matches")
|
||||||
else:
|
else:
|
||||||
loop_delay = float(config["variable"]["loop-delay"])
|
loop_delay = float(config["variable"]["loop-delay"])
|
||||||
|
Loading…
Reference in New Issue
Block a user