2020-02-18 17:31:20 +00:00
|
|
|
# Titan Robotics Team 2022: Superscript Script
|
|
|
|
# Written by Arthur Lu & Jacob Levine
|
|
|
|
# Notes:
|
|
|
|
# setup:
|
|
|
|
|
2020-03-04 02:10:29 +00:00
|
|
|
__version__ = "0.0.1.001"
|
2020-02-18 17:31:20 +00:00
|
|
|
|
|
|
|
# changelog should be viewed using print(analysis.__changelog__)
|
|
|
|
__changelog__ = """changelog:
|
2020-03-04 02:10:29 +00:00
|
|
|
0.0.1.001:
|
|
|
|
- cleaned up imports
|
2020-03-04 01:39:58 +00:00
|
|
|
0.0.1.000:
|
|
|
|
- tested working, can push to database
|
2020-03-04 00:40:35 +00:00
|
|
|
0.0.0.009:
|
|
|
|
- tested working
|
|
|
|
- prints out stats for the time being, will push to database later
|
2020-03-04 00:02:24 +00:00
|
|
|
0.0.0.008:
|
|
|
|
- added data import
|
|
|
|
- removed tba import
|
|
|
|
- finished main method
|
2020-03-03 22:01:07 +00:00
|
|
|
0.0.0.007:
|
|
|
|
- added load_config
|
|
|
|
- optimized simpleloop for readibility
|
|
|
|
- added __all__ entries
|
|
|
|
- added simplestats engine
|
|
|
|
- pending testing
|
2020-03-03 21:42:37 +00:00
|
|
|
0.0.0.006:
|
|
|
|
- fixes
|
2020-02-20 01:51:45 +00:00
|
|
|
0.0.0.005:
|
|
|
|
- imported pickle
|
|
|
|
- created custom database object
|
2020-02-20 01:21:48 +00:00
|
|
|
0.0.0.004:
|
|
|
|
- fixed simpleloop to actually return a vector
|
2020-02-19 02:29:22 +00:00
|
|
|
0.0.0.003:
|
|
|
|
- added metricsloop which is unfinished
|
2020-02-19 01:54:09 +00:00
|
|
|
0.0.0.002:
|
|
|
|
- added simpleloop which is untested until data is provided
|
2020-02-18 17:31:20 +00:00
|
|
|
0.0.0.001:
|
|
|
|
- created script
|
|
|
|
- added analysis, numba, numpy imports
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = (
|
|
|
|
"Arthur Lu <learthurgo@gmail.com>",
|
|
|
|
"Jacob Levine <jlevine@imsa.edu>",
|
|
|
|
)
|
|
|
|
|
|
|
|
__all__ = [
|
2020-03-03 22:01:07 +00:00
|
|
|
"main",
|
|
|
|
"load_config",
|
|
|
|
"simpleloop",
|
|
|
|
"simplestats",
|
|
|
|
"metricsloop"
|
2020-02-18 17:31:20 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# imports:
|
|
|
|
|
|
|
|
from analysis import analysis as an
|
2020-03-04 00:02:24 +00:00
|
|
|
import data as d
|
2020-03-04 19:42:54 +00:00
|
|
|
import time
|
2020-02-18 21:25:23 +00:00
|
|
|
|
|
|
|
def main():
|
2020-03-03 22:01:07 +00:00
|
|
|
while(True):
|
2020-03-04 19:42:54 +00:00
|
|
|
current_time = time.time()
|
2020-03-04 19:47:56 +00:00
|
|
|
print("time: " + time)
|
|
|
|
|
2020-03-04 01:39:58 +00:00
|
|
|
print("loading config")
|
2020-03-04 00:02:24 +00:00
|
|
|
competition, config = load_config("config.csv")
|
2020-03-04 01:39:58 +00:00
|
|
|
print("config loaded")
|
2020-03-04 19:47:56 +00:00
|
|
|
|
2020-03-04 01:39:58 +00:00
|
|
|
print("loading database keys")
|
2020-03-04 00:02:24 +00:00
|
|
|
apikey = an.load_csv("keys.txt")[0][0]
|
2020-03-04 01:39:58 +00:00
|
|
|
print("loaded keys")
|
2020-03-04 19:47:56 +00:00
|
|
|
|
2020-03-04 01:39:58 +00:00
|
|
|
print("loading data")
|
2020-03-04 00:02:24 +00:00
|
|
|
data = d.get_data_formatted(apikey, competition)
|
2020-03-04 01:39:58 +00:00
|
|
|
print("loaded data")
|
2020-03-04 19:47:56 +00:00
|
|
|
|
2020-03-04 01:39:58 +00:00
|
|
|
print("running tests")
|
2020-03-04 00:02:24 +00:00
|
|
|
results = simpleloop(data, config)
|
2020-03-04 01:39:58 +00:00
|
|
|
print("finished tests")
|
2020-03-04 19:47:56 +00:00
|
|
|
|
2020-03-04 01:39:58 +00:00
|
|
|
print("pushing to database")
|
2020-03-04 19:42:54 +00:00
|
|
|
push_to_database(apikey, competition, results, None)
|
2020-03-04 01:39:58 +00:00
|
|
|
print("pushed to database")
|
2020-03-03 22:01:07 +00:00
|
|
|
|
|
|
|
def load_config(file):
|
|
|
|
config_vector = {}
|
|
|
|
file = an.load_csv(file)
|
2020-03-04 00:13:03 +00:00
|
|
|
for line in file[1:]:
|
|
|
|
config_vector[line[0]] = line[1:]
|
2020-03-03 22:01:07 +00:00
|
|
|
|
2020-03-04 00:02:24 +00:00
|
|
|
return (file[0][0], config_vector)
|
2020-02-18 21:25:23 +00:00
|
|
|
|
2020-02-19 01:54:09 +00:00
|
|
|
def simpleloop(data, tests): # expects 3D array with [Team][Variable][Match]
|
2020-03-03 21:42:37 +00:00
|
|
|
return_vector = {}
|
2020-02-20 01:53:23 +00:00
|
|
|
for team in data:
|
2020-03-03 21:42:37 +00:00
|
|
|
variable_vector = {}
|
|
|
|
for variable in data[team]:
|
|
|
|
test_vector = {}
|
|
|
|
variable_data = data[team][variable]
|
2020-03-04 00:13:03 +00:00
|
|
|
if(variable in tests):
|
|
|
|
for test in tests[variable]:
|
|
|
|
test_vector[test] = simplestats(variable_data, test)
|
|
|
|
else:
|
|
|
|
pass
|
2020-03-03 21:42:37 +00:00
|
|
|
variable_vector[variable] = test_vector
|
|
|
|
return_vector[team] = variable_vector
|
2020-02-19 01:54:09 +00:00
|
|
|
|
2020-03-03 21:42:37 +00:00
|
|
|
return return_vector
|
2020-02-19 01:54:09 +00:00
|
|
|
|
2020-03-03 21:42:37 +00:00
|
|
|
def simplestats(data, test):
|
2020-02-19 01:54:09 +00:00
|
|
|
|
2020-03-04 00:13:03 +00:00
|
|
|
if(test == "basic_stats"):
|
2020-03-03 21:42:37 +00:00
|
|
|
return an.basic_stats(data)
|
2020-02-19 01:54:09 +00:00
|
|
|
|
2020-03-03 22:01:07 +00:00
|
|
|
if(test == "historical_analysis"):
|
|
|
|
return an.histo_analysis(data)
|
|
|
|
|
|
|
|
if(test == "regression_linear"):
|
|
|
|
return an.regression('cpu', list(range(len(data))), data, ['lin'])
|
|
|
|
|
|
|
|
if(test == "regression_logarithmic"):
|
|
|
|
return an.regression('cpu', list(range(len(data))), data, ['log'])
|
|
|
|
|
|
|
|
if(test == "regression_exponential"):
|
|
|
|
return an.regression('cpu', list(range(len(data))), data, ['exp'])
|
|
|
|
|
|
|
|
if(test == "regression_polynomial"):
|
|
|
|
return an.regression('cpu', list(range(len(data))), data, ['ply'])
|
|
|
|
|
|
|
|
if(test == "regression_sigmoidal"):
|
|
|
|
return an.regression('cpu', list(range(len(data))), data, ['sig'])
|
2020-02-20 01:21:48 +00:00
|
|
|
|
2020-03-04 19:42:54 +00:00
|
|
|
def push_to_database(apikey, competition, results, metrics):
|
2020-03-04 01:39:58 +00:00
|
|
|
|
|
|
|
for team in results:
|
|
|
|
|
2020-03-04 19:42:54 +00:00
|
|
|
d.push_team_tests_data(apikey, competition, team, results[team])
|
2020-03-04 01:39:58 +00:00
|
|
|
|
2020-03-03 21:42:37 +00:00
|
|
|
def metricsloop(group_data, observations, database, tests): # listener based metrics update
|
2020-02-20 01:21:48 +00:00
|
|
|
|
2020-03-03 21:42:37 +00:00
|
|
|
pass
|
2020-02-20 01:21:48 +00:00
|
|
|
|
2020-03-04 19:42:54 +00:00
|
|
|
"""
|
2020-02-20 01:51:45 +00:00
|
|
|
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"))
|
2020-03-04 19:42:54 +00:00
|
|
|
"""
|
2020-02-18 21:25:23 +00:00
|
|
|
main()
|