From 09e6dc16f305b79b0d1d0c3f0a542af381efa2f1 Mon Sep 17 00:00:00 2001 From: art Date: Tue, 3 Mar 2020 18:02:24 -0600 Subject: [PATCH] superscript.pv v 0.0.0.008 data.py created --- .gitignore | 1 + data analysis/__pycache__/data.cpython-37.pyc | Bin 0 -> 2395 bytes data analysis/data.py | 55 ++++++++++++++++++ data analysis/superscript.py | 21 ++++--- data analysis/tba.py | 11 ---- 5 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 data analysis/__pycache__/data.cpython-37.pyc create mode 100644 data analysis/data.py delete mode 100644 data analysis/tba.py diff --git a/.gitignore b/.gitignore index e5e132ff..e45f14c3 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ data analysis/test.ipynb data analysis/.ipynb_checkpoints/test-checkpoint.ipynb .vscode/settings.json .vscode +data analysis/arthur_pull.ipynb diff --git a/data analysis/__pycache__/data.cpython-37.pyc b/data analysis/__pycache__/data.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..26adb70c8eb795e7b37db5d9c15504b9f8ab095e GIT binary patch literal 2395 zcmcgtJ9FDc5Wd5kq$EFMhfbV0k3vi=F{5-I#S__@6nUtzXXIce;y^r@0u2Jx-O&;? zU?sQy2Pw!hO@2py1KLzBQl(3kZx14EYcv^G0cQ6exVzo^cK5@B<>flV^ZQ?Wd)q!^ zf6`$7Sm=BUQ9nWnCV0xis^uX!V=J_UCF~b0bc7>Zw65@kkJb}`sG;>mT{O@JVo5Bc ztqJ~!wN_r?M7Gl<3-mZ=@(`{16iV=dCwyXQ*5|@1*i9zvo2;;e^U|8wg^e@Zos*R( zYmXmnt!<6;!P*b;_+;%s>!G^WZXX>Tt?Pq$KOMzUnkG@!jn}*RpdAg9_VcgX@$)#- z?UPIGL8Q9}v1+SiFihhXFa3i!60uY*s|;j(IEs~4rQM5l%LxOs?O8l7J)DD9lKUl> zzcC5u*gxO25As3Wj?z(kd+YI5Tju+@PP(eC<;GVV8*56-NXNZ#TSPj#6J=34R*5pB z_2Ia@0)ri6qjTmL!J<4U#shwX%NlxJPGdYaguWTf_R%R=AGkfUiqeiw2C)GM`0~W`Dn%R0U^9&d`y#sE!02xXJGleA zD+oG-)cR(cccWC@N2gkfgKXd**5<)gp)F$()^r>VI{2bOhhiUIK1#AI$$FjnLWHrQ zbfibB)6GR(dMcM1JDtADGm7gl&P2-&{j=bg{8*A>=e=He+eNyGGKIwJ+~K$Q2A5Yc z*QFrQLknDp3DyoenoSX&8K-3KTN9^n`u4<4*u*iVz@Z*C&4A3k!kr z(ArJ5$qw)CGVM;i!kbY+IXlSM22y+&>qIBG%aXxDb@LJKS2_e_>6*N1`K3P`5Av*+ zmyMsOd6*_Bh;o@0b<7rE7S_yav(b5)WTLc&qO5IW&37^y#H~QmjpQ|`GBDP%(V+CY z)nS&{hdr~~h7T8_c#TjrJB=w5?MpaLtw1qA>EU&d`PaE5R`_4xG#8WCVOG9J>IPKH zmp7^ZKB*>D=noT3mz1|?>H|_ALcIx&yiKzok@}d_9a5i=x+t@*EHJ^z1`#rL5h9;q zeo=|U1Vln6!8AHZC4Sro1F#uG3hhlSu!0S7j=v~S@y+>{TNAgik&JFNTYw49Dt{G~ zkK`0!;1}TEmtX^JYhrqg3;WbM1xptel5wTt2ypVkq5q-=NgvNBL0*~nUz37d!rUs& zFGHQ&9%ZQMzgDmRmYRCh{_7N{6VTbkaoW(jG*^mKQFi z(KrV2bVSnCuR~hekr1Iz>#@D${qyY6c;iBp2#UCZA=6hN4!;TlxeSqCVs`P5BnnwX zc!lM9bmY-SgWW+=d?jk*15%3K_PW6*YE|76CWGz zLvI*mB2rb!(vQ^;w((d}WmOlTZEr-6@Rt+_{I&+U7^U%j$|yw%65t<=*9rWfhPUxA DGyn&5 literal 0 HcmV?d00001 diff --git a/data analysis/data.py b/data analysis/data.py new file mode 100644 index 00000000..6649a292 --- /dev/null +++ b/data analysis/data.py @@ -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 \ No newline at end of file diff --git a/data analysis/superscript.py b/data analysis/superscript.py index 9e7eb69d..4ecab30e 100644 --- a/data analysis/superscript.py +++ b/data analysis/superscript.py @@ -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 = {} diff --git a/data analysis/tba.py b/data analysis/tba.py deleted file mode 100644 index 3dfd04fa..00000000 --- a/data analysis/tba.py +++ /dev/null @@ -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 \ No newline at end of file