mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-11-10 06:54:44 +00:00
refactors
This commit is contained in:
parent
b5718a500a
commit
94dd51566a
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,3 +16,4 @@ data analysis/.ipynb_checkpoints/test-checkpoint.ipynb
|
||||
.vscode
|
||||
data analysis/arthur_pull.ipynb
|
||||
data analysis/keys.txt
|
||||
data analysis/check_for_new_matches.ipynb
|
Binary file not shown.
@ -1,16 +1,17 @@
|
||||
import requests
|
||||
import pymongo
|
||||
import pandas as pd
|
||||
def req_event_matches(eventkey,apikey):
|
||||
headers={'X-TBA-Auth-Key':apikey}
|
||||
r=requests.get('https://www.thebluealliance.com/api/v3/event/'+eventkey+'/matches/simple', headers=headers)
|
||||
return r
|
||||
def get_match_data(request):
|
||||
if request.status_code == 200:
|
||||
x=[]
|
||||
for i in sorted(request.json(), key=lambda i: i['actual_time']):
|
||||
x.append([[i['alliances']['red']['team_keys'], i['alliances']['blue']['team_keys']],i['winning_alliance']])
|
||||
return x
|
||||
import time
|
||||
|
||||
def pull_new_tba_matches(apikey, competition, cutoff = time_last_upd):
|
||||
api_key= apikey
|
||||
x=requests.get("https://www.thebluealliance.com/api/v3/event/"+competition+"/matches/simple", headers={"X-TBA-Auth_Key":api_key})
|
||||
out = []
|
||||
for i in x.json():
|
||||
if (i["actual_time"]-cutoff >= 0 and i["comp_level"] == "qm"):
|
||||
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"]})
|
||||
time_last_upd = time.time()
|
||||
return out
|
||||
|
||||
def get_team_match_data(apikey, competition, team_num):
|
||||
client = pymongo.MongoClient(apikey)
|
||||
@ -54,8 +55,14 @@ def get_data_formatted(apikey, competition):
|
||||
pass
|
||||
return out
|
||||
|
||||
def push_team_data(apikey, competition, team_num, data):
|
||||
def push_team_tests_data(apikey, competition, team_num, data, dbname = "data_processing", colname = "team_tests"):
|
||||
client = pymongo.MongoClient(apikey)
|
||||
db = client.data_processing
|
||||
mdata = db.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(apikey, competition, team_num, data, dbname = "data_processing", colname = "team_metrics"):
|
||||
client = pymongo.MongoClient(apikey)
|
||||
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)
|
@ -57,9 +57,12 @@ __all__ = [
|
||||
|
||||
from analysis import analysis as an
|
||||
import data as d
|
||||
import time
|
||||
|
||||
def main():
|
||||
while(True):
|
||||
current_time = time.time()
|
||||
print("time is: " + time)
|
||||
print("loading config")
|
||||
competition, config = load_config("config.csv")
|
||||
print("config loaded")
|
||||
@ -73,7 +76,7 @@ def main():
|
||||
results = simpleloop(data, config)
|
||||
print("finished tests")
|
||||
print("pushing to database")
|
||||
push_to_database(apikey, competition, results)
|
||||
push_to_database(apikey, competition, results, None)
|
||||
print("pushed to database")
|
||||
|
||||
def load_config(file):
|
||||
@ -124,16 +127,17 @@ def simplestats(data, test):
|
||||
if(test == "regression_sigmoidal"):
|
||||
return an.regression('cpu', list(range(len(data))), data, ['sig'])
|
||||
|
||||
def push_to_database(apikey, competition, results):
|
||||
def push_to_database(apikey, competition, results, metrics):
|
||||
|
||||
for team in results:
|
||||
|
||||
d.push_team_data(apikey, competition, team, results[team])
|
||||
d.push_team_tests_data(apikey, competition, team, results[team])
|
||||
|
||||
def metricsloop(group_data, observations, database, tests): # listener based metrics update
|
||||
|
||||
pass
|
||||
|
||||
"""
|
||||
class database:
|
||||
|
||||
data = {}
|
||||
@ -196,5 +200,5 @@ class database:
|
||||
def load_database(self, location):
|
||||
|
||||
data = pickle.load(open(location, "rb"))
|
||||
|
||||
"""
|
||||
main()
|
Loading…
Reference in New Issue
Block a user