mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-11-10 06:54:44 +00:00
beautified
This commit is contained in:
parent
2802d8572c
commit
493b9b19b2
@ -1,7 +1,7 @@
|
|||||||
#Titan Robotics Team 2022: Super Script
|
# Titan Robotics Team 2022: Super Script
|
||||||
#Written by Arthur Lu & Jacob Levine
|
# Written by Arthur Lu & Jacob Levine
|
||||||
#Notes:
|
# Notes:
|
||||||
#setup:
|
# setup:
|
||||||
|
|
||||||
__version__ = "1.0.6.001"
|
__version__ = "1.0.6.001"
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ __changelog__ = """changelog:
|
|||||||
__author__ = (
|
__author__ = (
|
||||||
"Arthur Lu <arthurlu@ttic.edu>, "
|
"Arthur Lu <arthurlu@ttic.edu>, "
|
||||||
"Jacob Levine <jlevine@ttic.edu>,"
|
"Jacob Levine <jlevine@ttic.edu>,"
|
||||||
)
|
)
|
||||||
|
|
||||||
import firebase_admin
|
import firebase_admin
|
||||||
from firebase_admin import credentials
|
from firebase_admin import credentials
|
||||||
@ -60,6 +60,7 @@ import time
|
|||||||
import tbarequest as tba
|
import tbarequest as tba
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
|
|
||||||
def titanservice():
|
def titanservice():
|
||||||
|
|
||||||
print("[OK] loading data")
|
print("[OK] loading data")
|
||||||
@ -67,15 +68,16 @@ def titanservice():
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
source_dir = 'data'
|
source_dir = 'data'
|
||||||
file_list = glob.glob(source_dir + '/*.csv') #supposedly sorts by alphabetical order, skips reading teams.csv because of redundancy
|
# supposedly sorts by alphabetical order, skips reading teams.csv because of redundancy
|
||||||
|
file_list = glob.glob(source_dir + '/*.csv')
|
||||||
data = []
|
data = []
|
||||||
files = [fn for fn in glob.glob('data/*.csv')
|
files = [fn for fn in glob.glob('data/*.csv')
|
||||||
if not (os.path.basename(fn).startswith('scores') or os.path.basename(fn).startswith('teams') or os.path.basename(fn).startswith('match') or os.path.basename(fn).startswith('notes') or os.path.basename(fn).startswith('observationType') or os.path.basename(fn).startswith('teamDBRef'))] #scores will be handled sperately
|
if not (os.path.basename(fn).startswith('scores') or os.path.basename(fn).startswith('teams') or os.path.basename(fn).startswith('match') or os.path.basename(fn).startswith('notes') or os.path.basename(fn).startswith('observationType') or os.path.basename(fn).startswith('teamDBRef'))] # scores will be handled sperately
|
||||||
|
|
||||||
for i in files:
|
for i in files:
|
||||||
data.append(analysis.load_csv(i))
|
data.append(analysis.load_csv(i))
|
||||||
|
|
||||||
#print(files)
|
# print(files)
|
||||||
|
|
||||||
stats = []
|
stats = []
|
||||||
measure_stats = []
|
measure_stats = []
|
||||||
@ -86,111 +88,113 @@ def titanservice():
|
|||||||
|
|
||||||
print("[OK] loaded data in " + str(end - start) + " seconds")
|
print("[OK] loaded data in " + str(end - start) + " seconds")
|
||||||
|
|
||||||
#assumes that team number is in the first column, and that the order of teams is the same across all files
|
# assumes that team number is in the first column, and that the order of teams is the same across all files
|
||||||
#unhelpful comment
|
# unhelpful comment
|
||||||
for measure in data: #unpacks 3d array into 2ds
|
for measure in data: # unpacks 3d array into 2ds
|
||||||
|
|
||||||
measure_stats = []
|
measure_stats = []
|
||||||
|
|
||||||
for i in range(len(measure)): #unpacks into specific teams
|
for i in range(len(measure)): # unpacks into specific teams
|
||||||
|
|
||||||
#ofbest_curve = [None]
|
#ofbest_curve = [None]
|
||||||
#r2best_curve = [None]
|
#r2best_curve = [None]
|
||||||
|
|
||||||
line = measure[i]
|
line = measure[i]
|
||||||
|
|
||||||
#print(line)
|
# print(line)
|
||||||
|
|
||||||
#x = list(range(len(line)))
|
#x = list(range(len(line)))
|
||||||
#eqs, rmss, r2s, overfit = analysis.optimize_regression(x, line, 10, 1)
|
#eqs, rmss, r2s, overfit = analysis.optimize_regression(x, line, 10, 1)
|
||||||
|
|
||||||
#beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "min_overfit")
|
#beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "min_overfit")
|
||||||
|
|
||||||
#print(eqs, rmss, r2s, overfit)
|
#print(eqs, rmss, r2s, overfit)
|
||||||
|
|
||||||
#ofbest_curve.append(beqs)
|
# ofbest_curve.append(beqs)
|
||||||
#ofbest_curve.append(brmss)
|
# ofbest_curve.append(brmss)
|
||||||
#ofbest_curve.append(br2s)
|
# ofbest_curve.append(br2s)
|
||||||
#ofbest_curve.append(boverfit)
|
# ofbest_curve.append(boverfit)
|
||||||
#ofbest_curve.pop(0)
|
# ofbest_curve.pop(0)
|
||||||
|
|
||||||
#print(ofbest_curve)
|
# print(ofbest_curve)
|
||||||
|
|
||||||
#beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "max_r2s")
|
#beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "max_r2s")
|
||||||
|
|
||||||
#r2best_curve.append(beqs)
|
# r2best_curve.append(beqs)
|
||||||
#r2best_curve.append(brmss)
|
# r2best_curve.append(brmss)
|
||||||
#r2best_curve.append(br2s)
|
# r2best_curve.append(br2s)
|
||||||
#r2best_curve.append(boverfit)
|
# r2best_curve.append(boverfit)
|
||||||
#r2best_curve.pop(0)
|
# r2best_curve.pop(0)
|
||||||
|
|
||||||
#print(r2best_curve)
|
# print(r2best_curve)
|
||||||
|
|
||||||
|
measure_stats.append(teams[i] + list(analysis.basic_stats(
|
||||||
measure_stats.append(teams[i] + list(analysis.basic_stats(line, 0, 0)) + list(analysis.histo_analysis(line, 1, -3, 3)))
|
line, 0, 0)) + list(analysis.histo_analysis(line, 1, -3, 3)))
|
||||||
|
|
||||||
stats.append(list(measure_stats))
|
stats.append(list(measure_stats))
|
||||||
nishant = []
|
nishant = []
|
||||||
|
|
||||||
for i in range(len(scores)):
|
for i in range(len(scores)):
|
||||||
|
|
||||||
#print(scores)
|
# print(scores)
|
||||||
|
|
||||||
ofbest_curve = [None]
|
ofbest_curve = [None]
|
||||||
r2best_curve = [None]
|
r2best_curve = [None]
|
||||||
|
|
||||||
line = scores[i]
|
line = scores[i]
|
||||||
|
|
||||||
if len(line) < 4:
|
if len(line) < 4:
|
||||||
|
|
||||||
nishant.append('no_data')
|
nishant.append('no_data')
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#print(line)
|
# print(line)
|
||||||
|
|
||||||
#print(line)
|
# print(line)
|
||||||
|
|
||||||
x = list(range(len(line)))
|
x = list(range(len(line)))
|
||||||
eqs, rmss, r2s, overfit = analysis.optimize_regression(x, line, 10, 1)
|
eqs, rmss, r2s, overfit = analysis.optimize_regression(x, line, 10, 1)
|
||||||
|
|
||||||
beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "min_overfit")
|
beqs, brmss, br2s, boverfit = analysis.select_best_regression(
|
||||||
|
eqs, rmss, r2s, overfit, "min_overfit")
|
||||||
|
|
||||||
#print(eqs, rmss, r2s, overfit)
|
#print(eqs, rmss, r2s, overfit)
|
||||||
|
|
||||||
ofbest_curve.append(beqs)
|
ofbest_curve.append(beqs)
|
||||||
ofbest_curve.append(brmss)
|
ofbest_curve.append(brmss)
|
||||||
ofbest_curve.append(br2s)
|
ofbest_curve.append(br2s)
|
||||||
ofbest_curve.append(boverfit)
|
ofbest_curve.append(boverfit)
|
||||||
ofbest_curve.pop(0)
|
ofbest_curve.pop(0)
|
||||||
|
|
||||||
#print(ofbest_curve)
|
# print(ofbest_curve)
|
||||||
|
|
||||||
beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "max_r2s")
|
beqs, brmss, br2s, boverfit = analysis.select_best_regression(
|
||||||
|
eqs, rmss, r2s, overfit, "max_r2s")
|
||||||
|
|
||||||
r2best_curve.append(beqs)
|
r2best_curve.append(beqs)
|
||||||
r2best_curve.append(brmss)
|
r2best_curve.append(brmss)
|
||||||
r2best_curve.append(br2s)
|
r2best_curve.append(br2s)
|
||||||
r2best_curve.append(boverfit)
|
r2best_curve.append(boverfit)
|
||||||
r2best_curve.pop(0)
|
r2best_curve.pop(0)
|
||||||
|
|
||||||
#print(r2best_curve)
|
# print(r2best_curve)
|
||||||
|
|
||||||
z = len(scores[0]) + 1
|
z = len(scores[0]) + 1
|
||||||
nis_num = []
|
nis_num = []
|
||||||
|
|
||||||
nis_num.append(eval(str(ofbest_curve[0])))
|
nis_num.append(eval(str(ofbest_curve[0])))
|
||||||
nis_num.append(eval(str(r2best_curve[0])))
|
nis_num.append(eval(str(r2best_curve[0])))
|
||||||
|
|
||||||
nis_num.append((eval(ofbest_curve[0]) + eval(r2best_curve[0])) / 2)
|
nis_num.append((eval(ofbest_curve[0]) + eval(r2best_curve[0])) / 2)
|
||||||
|
|
||||||
nishant.append(teams[i] + nis_num)
|
nishant.append(teams[i] + nis_num)
|
||||||
|
|
||||||
json_out = {}
|
json_out = {}
|
||||||
score_out = {}
|
score_out = {}
|
||||||
|
|
||||||
for i in range(len(teams)):
|
for i in range(len(teams)):
|
||||||
score_out[str(teams[i][0])] = (nishant[i])
|
score_out[str(teams[i][0])] = (nishant[i])
|
||||||
|
|
||||||
location = db.collection(u'stats').document(u'stats-noNN')
|
location = db.collection(u'stats').document(u'stats-noNN')
|
||||||
for i in range(len(teams)):
|
for i in range(len(teams)):
|
||||||
@ -199,49 +203,59 @@ def titanservice():
|
|||||||
for j in range(len(files)):
|
for j in range(len(files)):
|
||||||
json_out[str(teams[i][0])] = (stats[j][i])
|
json_out[str(teams[i][0])] = (stats[j][i])
|
||||||
name = os.path.basename(files[j])
|
name = os.path.basename(files[j])
|
||||||
general_general_stats.document(name).set({'stats':json_out.get(teams[i][0])})
|
general_general_stats.document(name).set(
|
||||||
|
{'stats': json_out.get(teams[i][0])})
|
||||||
|
|
||||||
for i in range(len(teams)):
|
for i in range(len(teams)):
|
||||||
nnum = location.collection(teams[i][0]).document(u'nishant_number').set({'nishant':score_out.get(teams[i][0])})
|
nnum = location.collection(teams[i][0]).document(
|
||||||
|
u'nishant_number').set({'nishant': score_out.get(teams[i][0])})
|
||||||
|
|
||||||
|
|
||||||
def pulldata():
|
def pulldata():
|
||||||
teams = analysis.load_csv('data/teams.csv')
|
teams = analysis.load_csv('data/teams.csv')
|
||||||
scores = []
|
scores = []
|
||||||
for i in range(len(teams)):
|
for i in range(len(teams)):
|
||||||
team_scores = []
|
team_scores = []
|
||||||
#print(teams[i][0])
|
# print(teams[i][0])
|
||||||
request_data_object = tba.req_team_matches(teams[i][0], 2019, "UDvKmPjPRfwwUdDX1JxbmkyecYBJhCtXeyVk9vmO2i7K0Zn4wqQPMfzuEINXJ7e5")
|
request_data_object = tba.req_team_matches(
|
||||||
|
teams[i][0], 2019, "UDvKmPjPRfwwUdDX1JxbmkyecYBJhCtXeyVk9vmO2i7K0Zn4wqQPMfzuEINXJ7e5")
|
||||||
json_data = request_data_object.json()
|
json_data = request_data_object.json()
|
||||||
|
|
||||||
for match in range(len(json_data) - 1, -1, -1):
|
for match in range(len(json_data) - 1, -1, -1):
|
||||||
if json_data[match].get('winning_alliance') == "":
|
if json_data[match].get('winning_alliance') == "":
|
||||||
#print(json_data[match])
|
# print(json_data[match])
|
||||||
json_data.remove(json_data[match])
|
json_data.remove(json_data[match])
|
||||||
|
|
||||||
json_data = sorted(json_data, key=lambda k: k.get('actual_time', 0), reverse=False)
|
json_data = sorted(json_data, key=lambda k: k.get(
|
||||||
|
'actual_time', 0), reverse=False)
|
||||||
for j in range(len(json_data)):
|
for j in range(len(json_data)):
|
||||||
if "frc" + teams[i][0] in json_data[j].get('alliances').get('blue').get('team_keys'):
|
if "frc" + teams[i][0] in json_data[j].get('alliances').get('blue').get('team_keys'):
|
||||||
team_scores.append(json_data[j].get('alliances').get('blue').get('score'))
|
team_scores.append(json_data[j].get(
|
||||||
|
'alliances').get('blue').get('score'))
|
||||||
elif "frc" + teams[i][0] in json_data[j].get('alliances').get('red').get('team_keys'):
|
elif "frc" + teams[i][0] in json_data[j].get('alliances').get('red').get('team_keys'):
|
||||||
team_scores.append(json_data[j].get('alliances').get('red').get('score'))
|
team_scores.append(json_data[j].get(
|
||||||
|
'alliances').get('red').get('score'))
|
||||||
scores.append(team_scores)
|
scores.append(team_scores)
|
||||||
|
|
||||||
with open("data/scores.csv", "w+", newline = '') as file:
|
with open("data/scores.csv", "w+", newline='') as file:
|
||||||
writer = csv.writer(file, delimiter = ',')
|
writer = csv.writer(file, delimiter=',')
|
||||||
writer.writerows(scores)
|
writer.writerows(scores)
|
||||||
|
|
||||||
list_teams = teams
|
list_teams = teams
|
||||||
teams=db.collection('data').document('team-2022').collection("Central 2019").get()
|
teams = db.collection('data').document(
|
||||||
full=[]
|
'team-2022').collection("Central 2019").get()
|
||||||
tms=[]
|
full = []
|
||||||
|
tms = []
|
||||||
for team in teams:
|
for team in teams:
|
||||||
|
|
||||||
tms.append(team.id)
|
tms.append(team.id)
|
||||||
reports=db.collection('data').document('team-2022').collection("Central 2019").document(team.id).collection("matches").get()
|
reports = db.collection('data').document(
|
||||||
|
'team-2022').collection("Central 2019").document(team.id).collection("matches").get()
|
||||||
|
|
||||||
for report in reports:
|
for report in reports:
|
||||||
data=[]
|
data = []
|
||||||
data.append(db.collection('data').document('team-2022').collection("Central 2019").document(team.id).collection("matches").document(report.id).get().to_dict())
|
data.append(db.collection('data').document('team-2022').collection("Central 2019").document(
|
||||||
|
team.id).collection("matches").document(report.id).get().to_dict())
|
||||||
full.append(data)
|
full.append(data)
|
||||||
|
|
||||||
quant_keys = []
|
quant_keys = []
|
||||||
@ -267,11 +281,11 @@ def pulldata():
|
|||||||
|
|
||||||
#print(full[i][j].get(key).get('teamDBRef')[5:] in list_teams)
|
#print(full[i][j].get(key).get('teamDBRef')[5:] in list_teams)
|
||||||
|
|
||||||
#print(full[i][j].get(key).get('teamDBRef'))
|
# print(full[i][j].get(key).get('teamDBRef'))
|
||||||
|
|
||||||
#print(list(full[i][j].keys()))
|
# print(list(full[i][j].keys()))
|
||||||
|
|
||||||
#print(list_teams)
|
# print(list_teams)
|
||||||
|
|
||||||
if full[i][j].get(key).get('teamDBRef')[5:] in list_teams:
|
if full[i][j].get(key).get('teamDBRef')[5:] in list_teams:
|
||||||
|
|
||||||
@ -282,7 +296,8 @@ def pulldata():
|
|||||||
|
|
||||||
individual_keys = list(full[i][j].get(key).keys())
|
individual_keys = list(full[i][j].get(key).keys())
|
||||||
|
|
||||||
var[individual_keys[k]] = full[i][j].get(key).get(individual_keys[k])
|
var[individual_keys[k]] = full[i][j].get(
|
||||||
|
key).get(individual_keys[k])
|
||||||
|
|
||||||
out.append(var)
|
out.append(var)
|
||||||
|
|
||||||
@ -316,7 +331,8 @@ def pulldata():
|
|||||||
|
|
||||||
for i in sorted_out:
|
for i in sorted_out:
|
||||||
|
|
||||||
team_index = list_teams.index(sorted_out[sorted_out.index(i)][j_list.index('teamDBRef')][5:])
|
team_index = list_teams.index(
|
||||||
|
sorted_out[sorted_out.index(i)][j_list.index('teamDBRef')][5:])
|
||||||
|
|
||||||
for j in range(len(i)):
|
for j in range(len(i)):
|
||||||
|
|
||||||
@ -324,11 +340,12 @@ def pulldata():
|
|||||||
|
|
||||||
for i in range(len(big_out)):
|
for i in range(len(big_out)):
|
||||||
|
|
||||||
with open('data/' + j_list[i] + '.csv', "w+", newline = '') as file:
|
with open('data/' + j_list[i] + '.csv', "w+", newline='') as file:
|
||||||
|
|
||||||
writer = csv.writer(file, delimiter = ',')
|
writer = csv.writer(file, delimiter=',')
|
||||||
writer.writerows(big_out[i])
|
writer.writerows(big_out[i])
|
||||||
|
|
||||||
|
|
||||||
def service():
|
def service():
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -347,7 +364,8 @@ def service():
|
|||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
if (i != 4):
|
if (i != 4):
|
||||||
print("[WARNING] failed, trying " + str(5 - i - 1) + " more times")
|
print("[WARNING] failed, trying " +
|
||||||
|
str(5 - i - 1) + " more times")
|
||||||
else:
|
else:
|
||||||
print("[ERROR] failed to compute data, skipping")
|
print("[ERROR] failed to compute data, skipping")
|
||||||
fucked = True
|
fucked = True
|
||||||
@ -363,10 +381,11 @@ def service():
|
|||||||
|
|
||||||
print("[OK] waiting: " + str(300 - (end - start)) + " seconds" + "\n")
|
print("[OK] waiting: " + str(300 - (end - start)) + " seconds" + "\n")
|
||||||
|
|
||||||
time.sleep(300 - (end - start)) #executes once every 5 minutes
|
time.sleep(300 - (end - start)) # executes once every 5 minutes
|
||||||
|
|
||||||
|
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
#Use a service account
|
# Use a service account
|
||||||
try:
|
try:
|
||||||
cred = credentials.Certificate('keys/firebasekey.json')
|
cred = credentials.Certificate('keys/firebasekey.json')
|
||||||
except:
|
except:
|
||||||
@ -375,5 +394,5 @@ firebase_admin.initialize_app(cred)
|
|||||||
|
|
||||||
db = firestore.client()
|
db = firestore.client()
|
||||||
|
|
||||||
service() #finally we write something that isn't a function definition
|
service() # finally we write something that isn't a function definition
|
||||||
#titanservice()
|
# titanservice()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#Titan Robotics Team 2022: Super Script
|
# Titan Robotics Team 2022: Super Script
|
||||||
#Written by Arthur Lu & Jacob Levine
|
# Written by Arthur Lu & Jacob Levine
|
||||||
#Notes:
|
# Notes:
|
||||||
#setup:
|
# setup:
|
||||||
|
|
||||||
__version__ = "1.0.6.001"
|
__version__ = "1.0.6.001"
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ __changelog__ = """changelog:
|
|||||||
__author__ = (
|
__author__ = (
|
||||||
"Arthur Lu <arthurlu@ttic.edu>, "
|
"Arthur Lu <arthurlu@ttic.edu>, "
|
||||||
"Jacob Levine <jlevine@ttic.edu>,"
|
"Jacob Levine <jlevine@ttic.edu>,"
|
||||||
)
|
)
|
||||||
|
|
||||||
import firebase_admin
|
import firebase_admin
|
||||||
from firebase_admin import credentials
|
from firebase_admin import credentials
|
||||||
@ -60,6 +60,7 @@ import time
|
|||||||
import tbarequest as tba
|
import tbarequest as tba
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
|
|
||||||
def titanservice():
|
def titanservice():
|
||||||
|
|
||||||
print("[OK] loading data")
|
print("[OK] loading data")
|
||||||
@ -67,15 +68,16 @@ def titanservice():
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
source_dir = 'data'
|
source_dir = 'data'
|
||||||
file_list = glob.glob(source_dir + '/*.csv') #supposedly sorts by alphabetical order, skips reading teams.csv because of redundancy
|
# supposedly sorts by alphabetical order, skips reading teams.csv because of redundancy
|
||||||
|
file_list = glob.glob(source_dir + '/*.csv')
|
||||||
data = []
|
data = []
|
||||||
files = [fn for fn in glob.glob('data/*.csv')
|
files = [fn for fn in glob.glob('data/*.csv')
|
||||||
if not (os.path.basename(fn).startswith('scores') or os.path.basename(fn).startswith('teams') or os.path.basename(fn).startswith('match') or os.path.basename(fn).startswith('notes') or os.path.basename(fn).startswith('observationType') or os.path.basename(fn).startswith('teamDBRef'))] #scores will be handled sperately
|
if not (os.path.basename(fn).startswith('scores') or os.path.basename(fn).startswith('teams') or os.path.basename(fn).startswith('match') or os.path.basename(fn).startswith('notes') or os.path.basename(fn).startswith('observationType') or os.path.basename(fn).startswith('teamDBRef'))] # scores will be handled sperately
|
||||||
|
|
||||||
for i in files:
|
for i in files:
|
||||||
data.append(analysis.load_csv(i))
|
data.append(analysis.load_csv(i))
|
||||||
|
|
||||||
#print(files)
|
# print(files)
|
||||||
|
|
||||||
stats = []
|
stats = []
|
||||||
measure_stats = []
|
measure_stats = []
|
||||||
@ -86,150 +88,158 @@ def titanservice():
|
|||||||
|
|
||||||
print("[OK] loaded data in " + str(end - start) + " seconds")
|
print("[OK] loaded data in " + str(end - start) + " seconds")
|
||||||
|
|
||||||
#assumes that team number is in the first column, and that the order of teams is the same across all files
|
# assumes that team number is in the first column, and that the order of teams is the same across all files
|
||||||
#unhelpful comment
|
# unhelpful comment
|
||||||
#for measure in data: #unpacks 3d array into 2ds
|
# for measure in data: #unpacks 3d array into 2ds
|
||||||
|
|
||||||
#measure_stats = []
|
#measure_stats = []
|
||||||
|
|
||||||
#for i in range(len(measure)): #unpacks into specific teams
|
# for i in range(len(measure)): #unpacks into specific teams
|
||||||
|
|
||||||
#ofbest_curve = [None]
|
#ofbest_curve = [None]
|
||||||
#r2best_curve = [None]
|
#r2best_curve = [None]
|
||||||
|
|
||||||
#line = measure[i]
|
#line = measure[i]
|
||||||
|
|
||||||
#print(line)
|
# print(line)
|
||||||
|
|
||||||
#x = list(range(len(line)))
|
#x = list(range(len(line)))
|
||||||
#eqs, rmss, r2s, overfit = analysis.optimize_regression(x, line, 10, 1)
|
#eqs, rmss, r2s, overfit = analysis.optimize_regression(x, line, 10, 1)
|
||||||
|
|
||||||
#beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "min_overfit")
|
#beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "min_overfit")
|
||||||
|
|
||||||
#print(eqs, rmss, r2s, overfit)
|
#print(eqs, rmss, r2s, overfit)
|
||||||
|
|
||||||
#ofbest_curve.append(beqs)
|
# ofbest_curve.append(beqs)
|
||||||
#ofbest_curve.append(brmss)
|
# ofbest_curve.append(brmss)
|
||||||
#ofbest_curve.append(br2s)
|
# ofbest_curve.append(br2s)
|
||||||
#ofbest_curve.append(boverfit)
|
# ofbest_curve.append(boverfit)
|
||||||
#ofbest_curve.pop(0)
|
# ofbest_curve.pop(0)
|
||||||
|
|
||||||
#print(ofbest_curve)
|
# print(ofbest_curve)
|
||||||
|
|
||||||
#beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "max_r2s")
|
#beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "max_r2s")
|
||||||
|
|
||||||
#r2best_curve.append(beqs)
|
# r2best_curve.append(beqs)
|
||||||
#r2best_curve.append(brmss)
|
# r2best_curve.append(brmss)
|
||||||
#r2best_curve.append(br2s)
|
# r2best_curve.append(br2s)
|
||||||
#r2best_curve.append(boverfit)
|
# r2best_curve.append(boverfit)
|
||||||
#r2best_curve.pop(0)
|
# r2best_curve.pop(0)
|
||||||
|
|
||||||
#print(r2best_curve)
|
# print(r2best_curve)
|
||||||
|
|
||||||
|
#measure_stats.append(teams[i] + list(analysis.basic_stats(line, 0, 0)) + list(analysis.histo_analysis(line, 1, -3, 3)))
|
||||||
|
|
||||||
#measure_stats.append(teams[i] + list(analysis.basic_stats(line, 0, 0)) + list(analysis.histo_analysis(line, 1, -3, 3)))
|
# stats.append(list(measure_stats))
|
||||||
|
|
||||||
#stats.append(list(measure_stats))
|
|
||||||
nishant = []
|
nishant = []
|
||||||
|
|
||||||
for i in range(len(scores)):
|
for i in range(len(scores)):
|
||||||
|
|
||||||
#print(scores)
|
# print(scores)
|
||||||
|
|
||||||
ofbest_curve = [None]
|
ofbest_curve = [None]
|
||||||
r2best_curve = [None]
|
r2best_curve = [None]
|
||||||
|
|
||||||
line = scores[i]
|
line = scores[i]
|
||||||
|
|
||||||
if len(line) < 4:
|
if len(line) < 4:
|
||||||
|
|
||||||
nishant.append('no_data')
|
nishant.append('no_data')
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#print(line)
|
# print(line)
|
||||||
|
|
||||||
#print(line)
|
# print(line)
|
||||||
|
|
||||||
x = list(range(len(line)))
|
x = list(range(len(line)))
|
||||||
eqs, rmss, r2s, overfit = analysis.optimize_regression(x, line, 10, 1)
|
eqs, rmss, r2s, overfit = analysis.optimize_regression(x, line, 10, 1)
|
||||||
|
|
||||||
beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "min_overfit")
|
beqs, brmss, br2s, boverfit = analysis.select_best_regression(
|
||||||
|
eqs, rmss, r2s, overfit, "min_overfit")
|
||||||
|
|
||||||
#print(eqs, rmss, r2s, overfit)
|
#print(eqs, rmss, r2s, overfit)
|
||||||
|
|
||||||
ofbest_curve.append(beqs)
|
ofbest_curve.append(beqs)
|
||||||
ofbest_curve.append(brmss)
|
ofbest_curve.append(brmss)
|
||||||
ofbest_curve.append(br2s)
|
ofbest_curve.append(br2s)
|
||||||
ofbest_curve.append(boverfit)
|
ofbest_curve.append(boverfit)
|
||||||
ofbest_curve.pop(0)
|
ofbest_curve.pop(0)
|
||||||
|
|
||||||
#print(ofbest_curve)
|
# print(ofbest_curve)
|
||||||
|
|
||||||
beqs, brmss, br2s, boverfit = analysis.select_best_regression(eqs, rmss, r2s, overfit, "max_r2s")
|
beqs, brmss, br2s, boverfit = analysis.select_best_regression(
|
||||||
|
eqs, rmss, r2s, overfit, "max_r2s")
|
||||||
|
|
||||||
r2best_curve.append(beqs)
|
r2best_curve.append(beqs)
|
||||||
r2best_curve.append(brmss)
|
r2best_curve.append(brmss)
|
||||||
r2best_curve.append(br2s)
|
r2best_curve.append(br2s)
|
||||||
r2best_curve.append(boverfit)
|
r2best_curve.append(boverfit)
|
||||||
r2best_curve.pop(0)
|
r2best_curve.pop(0)
|
||||||
|
|
||||||
#print(r2best_curve)
|
# print(r2best_curve)
|
||||||
|
|
||||||
z = len(scores[0]) + 1
|
z = len(scores[0]) + 1
|
||||||
nis_num = []
|
nis_num = []
|
||||||
|
|
||||||
nis_num.append(eval(str(ofbest_curve[0])))
|
nis_num.append(eval(str(ofbest_curve[0])))
|
||||||
nis_num.append(eval(str(r2best_curve[0])))
|
nis_num.append(eval(str(r2best_curve[0])))
|
||||||
|
|
||||||
nis_num.append((eval(ofbest_curve[0]) + eval(r2best_curve[0])) / 2)
|
nis_num.append((eval(ofbest_curve[0]) + eval(r2best_curve[0])) / 2)
|
||||||
|
|
||||||
nishant.append(teams[i] + nis_num)
|
nishant.append(teams[i] + nis_num)
|
||||||
|
|
||||||
json_out = {}
|
json_out = {}
|
||||||
score_out = {}
|
score_out = {}
|
||||||
|
|
||||||
for i in range(len(teams)):
|
for i in range(len(teams)):
|
||||||
score_out[str(teams[i][0])] = (nishant[i])
|
score_out[str(teams[i][0])] = (nishant[i])
|
||||||
|
|
||||||
location = db.collection(u'stats').document(u'stats-noNN')
|
location = db.collection(u'stats').document(u'stats-noNN')
|
||||||
#for i in range(len(teams)):
|
# for i in range(len(teams)):
|
||||||
#general_general_stats = location.collection(teams[i][0])
|
#general_general_stats = location.collection(teams[i][0])
|
||||||
|
|
||||||
#for j in range(len(files)):
|
# for j in range(len(files)):
|
||||||
# json_out[str(teams[i][0])] = (stats[j][i])
|
# json_out[str(teams[i][0])] = (stats[j][i])
|
||||||
# name = os.path.basename(files[j])
|
# name = os.path.basename(files[j])
|
||||||
# general_general_stats.document(name).set({'stats':json_out.get(teams[i][0])})
|
# general_general_stats.document(name).set({'stats':json_out.get(teams[i][0])})
|
||||||
|
|
||||||
for i in range(len(teams)):
|
for i in range(len(teams)):
|
||||||
nnum = location.collection(teams[i][0]).document(u'nishant_number').set({'nishant':score_out.get(teams[i][0])})
|
nnum = location.collection(teams[i][0]).document(
|
||||||
|
u'nishant_number').set({'nishant': score_out.get(teams[i][0])})
|
||||||
|
|
||||||
|
|
||||||
def pulldata():
|
def pulldata():
|
||||||
teams = analysis.load_csv('data/teams.csv')
|
teams = analysis.load_csv('data/teams.csv')
|
||||||
scores = []
|
scores = []
|
||||||
for i in range(len(teams)):
|
for i in range(len(teams)):
|
||||||
team_scores = []
|
team_scores = []
|
||||||
#print(teams[i][0])
|
# print(teams[i][0])
|
||||||
request_data_object = tba.req_team_matches(teams[i][0], 2019, "UDvKmPjPRfwwUdDX1JxbmkyecYBJhCtXeyVk9vmO2i7K0Zn4wqQPMfzuEINXJ7e5")
|
request_data_object = tba.req_team_matches(
|
||||||
|
teams[i][0], 2019, "UDvKmPjPRfwwUdDX1JxbmkyecYBJhCtXeyVk9vmO2i7K0Zn4wqQPMfzuEINXJ7e5")
|
||||||
json_data = request_data_object.json()
|
json_data = request_data_object.json()
|
||||||
|
|
||||||
for match in range(len(json_data) - 1, -1, -1):
|
for match in range(len(json_data) - 1, -1, -1):
|
||||||
if json_data[match].get('winning_alliance') == "":
|
if json_data[match].get('winning_alliance') == "":
|
||||||
#print(json_data[match])
|
# print(json_data[match])
|
||||||
json_data.remove(json_data[match])
|
json_data.remove(json_data[match])
|
||||||
|
|
||||||
json_data = sorted(json_data, key=lambda k: k.get('actual_time', 0), reverse=False)
|
json_data = sorted(json_data, key=lambda k: k.get(
|
||||||
|
'actual_time', 0), reverse=False)
|
||||||
for j in range(len(json_data)):
|
for j in range(len(json_data)):
|
||||||
if "frc" + teams[i][0] in json_data[j].get('alliances').get('blue').get('team_keys'):
|
if "frc" + teams[i][0] in json_data[j].get('alliances').get('blue').get('team_keys'):
|
||||||
team_scores.append(json_data[j].get('alliances').get('blue').get('score'))
|
team_scores.append(json_data[j].get(
|
||||||
|
'alliances').get('blue').get('score'))
|
||||||
elif "frc" + teams[i][0] in json_data[j].get('alliances').get('red').get('team_keys'):
|
elif "frc" + teams[i][0] in json_data[j].get('alliances').get('red').get('team_keys'):
|
||||||
team_scores.append(json_data[j].get('alliances').get('red').get('score'))
|
team_scores.append(json_data[j].get(
|
||||||
|
'alliances').get('red').get('score'))
|
||||||
scores.append(team_scores)
|
scores.append(team_scores)
|
||||||
|
|
||||||
with open("data/scores.csv", "w+", newline = '') as file:
|
with open("data/scores.csv", "w+", newline='') as file:
|
||||||
writer = csv.writer(file, delimiter = ',')
|
writer = csv.writer(file, delimiter=',')
|
||||||
writer.writerows(scores)
|
writer.writerows(scores)
|
||||||
|
|
||||||
|
|
||||||
def service():
|
def service():
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -248,7 +258,8 @@ def service():
|
|||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
if (i != 4):
|
if (i != 4):
|
||||||
print("[WARNING] failed, trying " + str(5 - i - 1) + " more times")
|
print("[WARNING] failed, trying " +
|
||||||
|
str(5 - i - 1) + " more times")
|
||||||
else:
|
else:
|
||||||
print("[ERROR] failed to compute data, skipping")
|
print("[ERROR] failed to compute data, skipping")
|
||||||
fucked = True
|
fucked = True
|
||||||
@ -264,10 +275,11 @@ def service():
|
|||||||
|
|
||||||
print("[OK] waiting: " + str(300 - (end - start)) + " seconds" + "\n")
|
print("[OK] waiting: " + str(300 - (end - start)) + " seconds" + "\n")
|
||||||
|
|
||||||
time.sleep(300 - (end - start)) #executes once every 5 minutes
|
time.sleep(300 - (end - start)) # executes once every 5 minutes
|
||||||
|
|
||||||
|
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
#Use a service account
|
# Use a service account
|
||||||
try:
|
try:
|
||||||
cred = credentials.Certificate('keys/firebasekey.json')
|
cred = credentials.Certificate('keys/firebasekey.json')
|
||||||
except:
|
except:
|
||||||
@ -276,5 +288,5 @@ firebase_admin.initialize_app(cred)
|
|||||||
|
|
||||||
db = firestore.client()
|
db = firestore.client()
|
||||||
|
|
||||||
service() #finally we write something that isn't a function definition
|
service() # finally we write something that isn't a function definition
|
||||||
#titanservice()
|
# titanservice()
|
||||||
|
Loading…
Reference in New Issue
Block a user