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