mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-11-13 22:56:18 +00:00
superscript.py v 0.0.1.002
This commit is contained in:
parent
a8be0bab6a
commit
cd44f8a856
Binary file not shown.
@ -3,14 +3,13 @@ import pymongo
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def pull_new_tba_matches(apikey, competition, cutoff = time_last_upd):
|
def pull_new_tba_matches(apikey, competition, cutoff):
|
||||||
api_key= apikey
|
api_key= apikey
|
||||||
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():
|
||||||
if (i["actual_time"]-cutoff >= 0 and i["comp_level"] == "qm"):
|
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"]})
|
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
|
return out
|
||||||
|
|
||||||
def get_team_match_data(apikey, competition, team_num):
|
def get_team_match_data(apikey, competition, team_num):
|
||||||
@ -22,14 +21,11 @@ def get_team_match_data(apikey, 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(apikey, competition, team_num):
|
def get_team_metrics_data(apikey, competition, team_num):
|
||||||
client = pymongo.MongoClient(apikey)
|
client = pymongo.MongoClient(apikey)
|
||||||
db = client.data_scouting
|
db = client.data_processing
|
||||||
mdata = db.pitdata
|
mdata = db.team_metrics
|
||||||
out = {}
|
return mdata.find_one({"competition" : competition, "team": team_num})
|
||||||
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):
|
def unkeyify_2l(layered_dict):
|
||||||
out = {}
|
out = {}
|
||||||
|
@ -3,10 +3,12 @@
|
|||||||
# Notes:
|
# Notes:
|
||||||
# setup:
|
# setup:
|
||||||
|
|
||||||
__version__ = "0.0.1.001"
|
__version__ = "0.0.1.002"
|
||||||
|
|
||||||
# changelog should be viewed using print(analysis.__changelog__)
|
# changelog should be viewed using print(analysis.__changelog__)
|
||||||
__changelog__ = """changelog:
|
__changelog__ = """changelog:
|
||||||
|
0.0.1.002:
|
||||||
|
- started implement of metrics
|
||||||
0.0.1.001:
|
0.0.1.001:
|
||||||
- cleaned up imports
|
- cleaned up imports
|
||||||
0.0.1.000:
|
0.0.1.000:
|
||||||
@ -59,6 +61,8 @@ from analysis import analysis as an
|
|||||||
import data as d
|
import data as d
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
while(True):
|
while(True):
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
@ -70,6 +74,7 @@ def main():
|
|||||||
|
|
||||||
print("loading database keys")
|
print("loading database keys")
|
||||||
apikey = an.load_csv("keys.txt")[0][0]
|
apikey = an.load_csv("keys.txt")[0][0]
|
||||||
|
tbakey = an.load_csv("keys.txt")[1][0]
|
||||||
print("loaded keys")
|
print("loaded keys")
|
||||||
|
|
||||||
print("loading data")
|
print("loading data")
|
||||||
@ -80,6 +85,10 @@ def main():
|
|||||||
results = simpleloop(data, config)
|
results = simpleloop(data, config)
|
||||||
print("finished tests")
|
print("finished tests")
|
||||||
|
|
||||||
|
print("running metrics")
|
||||||
|
metrics = metricsloop(apikey, competition, current_time)
|
||||||
|
print("finished metrics")
|
||||||
|
|
||||||
print("pushing to database")
|
print("pushing to database")
|
||||||
push_to_database(apikey, competition, results, None)
|
push_to_database(apikey, competition, results, None)
|
||||||
print("pushed to database")
|
print("pushed to database")
|
||||||
@ -138,72 +147,8 @@ def push_to_database(apikey, competition, results, metrics):
|
|||||||
|
|
||||||
d.push_team_tests_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(apikey, competition, timestamp): # listener based metrics update
|
||||||
|
|
||||||
pass
|
matches = d.pull_new_tba_matches(apikey, competition, timestamp)
|
||||||
|
|
||||||
"""
|
return
|
||||||
class database:
|
|
||||||
|
|
||||||
data = {}
|
|
||||||
|
|
||||||
elo_starting_score = 1500
|
|
||||||
N = 1500
|
|
||||||
K = 32
|
|
||||||
|
|
||||||
gl2_starting_score = 1500
|
|
||||||
gl2_starting_rd = 350
|
|
||||||
gl2_starting_vol = 0.06
|
|
||||||
|
|
||||||
def __init__(self, team_lookup):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
for team in team_lookup:
|
|
||||||
|
|
||||||
elo = elo_starting_score
|
|
||||||
gl2 = {"score": gl2_starting_score, "rd": gl2_starting_rd, "vol": gl2_starting_vol}
|
|
||||||
ts = Trueskill.Rating()
|
|
||||||
|
|
||||||
data[str(team)] = {"elo": elo, "gl2": gl2, "ts": ts}
|
|
||||||
|
|
||||||
def get_team(self, team):
|
|
||||||
|
|
||||||
return data[team]
|
|
||||||
|
|
||||||
def get_elo(self, team):
|
|
||||||
|
|
||||||
return data[team]["elo"]
|
|
||||||
|
|
||||||
def get_gl2(self, team):
|
|
||||||
|
|
||||||
return data[team]["gl2"]
|
|
||||||
|
|
||||||
def get_ts(self, team):
|
|
||||||
|
|
||||||
return data[team]["ts"]
|
|
||||||
|
|
||||||
def set_team(self, team, ndata):
|
|
||||||
|
|
||||||
data[team] = ndata
|
|
||||||
|
|
||||||
def set_elo(self, team, nelo):
|
|
||||||
|
|
||||||
data[team]["elo"] = nelo
|
|
||||||
|
|
||||||
def set_gl2(self, team, ngl2):
|
|
||||||
|
|
||||||
data[team]["gl2"] = ngl2
|
|
||||||
|
|
||||||
def set_ts(self, team, nts):
|
|
||||||
|
|
||||||
data[team]["ts"] = nts
|
|
||||||
|
|
||||||
def save_database(self, location):
|
|
||||||
|
|
||||||
pickle.dump(data, open(location, "wb"))
|
|
||||||
|
|
||||||
def load_database(self, location):
|
|
||||||
|
|
||||||
data = pickle.load(open(location, "rb"))
|
|
||||||
"""
|
|
||||||
main()
|
|
Loading…
Reference in New Issue
Block a user