mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-12-25 17:19:09 +00:00
superscript.pv v 0.0.0.008
data.py created
This commit is contained in:
parent
0d5dea9bc9
commit
09e6dc16f3
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@ data analysis/test.ipynb
|
||||
data analysis/.ipynb_checkpoints/test-checkpoint.ipynb
|
||||
.vscode/settings.json
|
||||
.vscode
|
||||
data analysis/arthur_pull.ipynb
|
||||
|
BIN
data analysis/__pycache__/data.cpython-37.pyc
Normal file
BIN
data analysis/__pycache__/data.cpython-37.pyc
Normal file
Binary file not shown.
55
data analysis/data.py
Normal file
55
data analysis/data.py
Normal file
@ -0,0 +1,55 @@
|
||||
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
|
||||
|
||||
def get_team_match_data(apikey, competition, team_num):
|
||||
client = pymongo.MongoClient(apikey)
|
||||
db = client.data_scouting
|
||||
mdata = db.matchdata
|
||||
out = {}
|
||||
for i in mdata.find({"competition" : competition, "team_scouted": team_num}):
|
||||
out[i['match']] = i['data']
|
||||
return pd.DataFrame(out)
|
||||
|
||||
def get_team_pit_data(apikey, competition, team_num):
|
||||
client = pymongo.MongoClient(apikey)
|
||||
db = client.data_scouting
|
||||
mdata = db.pitdata
|
||||
out = {}
|
||||
for i in mdata.find({"competition" : competition, "team_scouted": team_num}):
|
||||
out[i['match']] = i['data']
|
||||
return pd.DataFrame(out)
|
||||
|
||||
def unkeyify_2l(layered_dict):
|
||||
out = {}
|
||||
for i in layered_dict.keys():
|
||||
add = []
|
||||
sortkey = []
|
||||
for j in layered_dict[i].keys():
|
||||
add.append([j,layered_dict[i][j]])
|
||||
add.sort(key = lambda x: x[0])
|
||||
out[i] = list(map(lambda x: x[1], add))
|
||||
return out
|
||||
|
||||
def get_data_formatted(apikey, competition):
|
||||
client = pymongo.MongoClient(apikey)
|
||||
db = client.data_scouting
|
||||
mdata = db.teamlist
|
||||
x=mdata.find_one({"competition":competition})
|
||||
out = {}
|
||||
for i in x:
|
||||
try:
|
||||
out[int(i)] = unkeyify_2l(get_team_match_data(apikey, competition, int(i)).transpose().to_dict())
|
||||
except:
|
||||
pass
|
||||
return out
|
@ -3,10 +3,14 @@
|
||||
# Notes:
|
||||
# setup:
|
||||
|
||||
__version__ = "0.0.0.007"
|
||||
__version__ = "0.0.0.008"
|
||||
|
||||
# changelog should be viewed using print(analysis.__changelog__)
|
||||
__changelog__ = """changelog:
|
||||
0.0.0.008:
|
||||
- added data import
|
||||
- removed tba import
|
||||
- finished main method
|
||||
0.0.0.007:
|
||||
- added load_config
|
||||
- optimized simpleloop for readibility
|
||||
@ -48,7 +52,7 @@ from analysis import analysis as an
|
||||
from numba import jit
|
||||
import numpy as np
|
||||
import pickle
|
||||
import tba
|
||||
import data as d
|
||||
try:
|
||||
from analysis import trueskill as Trueskill
|
||||
except:
|
||||
@ -56,16 +60,19 @@ except:
|
||||
|
||||
def main():
|
||||
while(True):
|
||||
config = load_config("config.csv")
|
||||
simpleloop(data, config)
|
||||
competition, config = load_config("config.csv")
|
||||
apikey = an.load_csv("keys.txt")[0][0]
|
||||
data = d.get_data_formatted(apikey, competition)
|
||||
results = simpleloop(data, config)
|
||||
print(results)
|
||||
|
||||
def load_config(file):
|
||||
config_vector = {}
|
||||
file = an.load_csv(file)
|
||||
for line in file:
|
||||
config_vector[line[0]] = line[1:]
|
||||
for line in file[2:]:
|
||||
config_vector[line[0]] = line[2:]
|
||||
|
||||
return config_vector
|
||||
return (file[0][0], config_vector)
|
||||
|
||||
def simpleloop(data, tests): # expects 3D array with [Team][Variable][Match]
|
||||
return_vector = {}
|
||||
|
@ -1,11 +0,0 @@
|
||||
import requests
|
||||
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
|
Loading…
Reference in New Issue
Block a user