mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-12-27 01:59:08 +00:00
analysis.py v 1.1.12.005
analysis pkg v 1.0.0.002
This commit is contained in:
parent
0d120e572f
commit
49c8bcafde
@ -1,6 +1,6 @@
|
|||||||
Metadata-Version: 2.1
|
Metadata-Version: 2.1
|
||||||
Name: analysis
|
Name: analysis
|
||||||
Version: 1.0.0.1
|
Version: 1.0.0.2
|
||||||
Summary: analysis package developed by Titan Scouting for The Red Alliance
|
Summary: analysis package developed by Titan Scouting for The Red Alliance
|
||||||
Home-page: https://github.com/titanscout2022/tr2022-strategy
|
Home-page: https://github.com/titanscout2022/tr2022-strategy
|
||||||
Author: The Titan Scouting Team
|
Author: The Titan Scouting Team
|
||||||
|
@ -7,10 +7,12 @@
|
|||||||
# current benchmark of optimization: 1.33 times faster
|
# current benchmark of optimization: 1.33 times faster
|
||||||
# setup:
|
# setup:
|
||||||
|
|
||||||
__version__ = "1.1.12.004"
|
__version__ = "1.1.12.005"
|
||||||
|
|
||||||
# changelog should be viewed using print(analysis.__changelog__)
|
# changelog should be viewed using print(analysis.__changelog__)
|
||||||
__changelog__ = """changelog:
|
__changelog__ = """changelog:
|
||||||
|
1.1.12.005:
|
||||||
|
- fixed numba issues by removing numba from elo, glicko2 and trueskill
|
||||||
1.1.12.004:
|
1.1.12.004:
|
||||||
- renamed gliko to glicko
|
- renamed gliko to glicko
|
||||||
1.1.12.003:
|
1.1.12.003:
|
||||||
@ -384,14 +386,12 @@ def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _itera
|
|||||||
|
|
||||||
return regressions
|
return regressions
|
||||||
|
|
||||||
@jit(nopython=True)
|
|
||||||
def elo(starting_score, opposing_score, observed, N, K):
|
def elo(starting_score, opposing_score, observed, N, K):
|
||||||
|
|
||||||
expected = 1/(1+10**((np.array(opposing_score) - starting_score)/N))
|
expected = 1/(1+10**((np.array(opposing_score) - starting_score)/N))
|
||||||
|
|
||||||
return starting_score + K*(np.sum(observed) - np.sum(expected))
|
return starting_score + K*(np.sum(observed) - np.sum(expected))
|
||||||
|
|
||||||
@jit(forceobj=True)
|
|
||||||
def glicko2(starting_score, starting_rd, starting_vol, opposing_score, opposing_rd, observations):
|
def glicko2(starting_score, starting_rd, starting_vol, opposing_score, opposing_rd, observations):
|
||||||
|
|
||||||
player = Glicko2(rating = starting_score, rd = starting_rd, vol = starting_vol)
|
player = Glicko2(rating = starting_score, rd = starting_rd, vol = starting_vol)
|
||||||
@ -400,7 +400,6 @@ def glicko2(starting_score, starting_rd, starting_vol, opposing_score, opposing_
|
|||||||
|
|
||||||
return (player.rating, player.rd, player.vol)
|
return (player.rating, player.rd, player.vol)
|
||||||
|
|
||||||
@jit(forceobj=True)
|
|
||||||
def trueskill(teams_data, observations): # teams_data is array of array of tuples ie. [[(mu, sigma), (mu, sigma), (mu, sigma)], [(mu, sigma), (mu, sigma), (mu, sigma)]]
|
def trueskill(teams_data, observations): # teams_data is array of array of tuples ie. [[(mu, sigma), (mu, sigma), (mu, sigma)], [(mu, sigma), (mu, sigma), (mu, sigma)]]
|
||||||
|
|
||||||
team_ratings = []
|
team_ratings = []
|
||||||
|
@ -7,10 +7,12 @@
|
|||||||
# current benchmark of optimization: 1.33 times faster
|
# current benchmark of optimization: 1.33 times faster
|
||||||
# setup:
|
# setup:
|
||||||
|
|
||||||
__version__ = "1.1.12.004"
|
__version__ = "1.1.12.005"
|
||||||
|
|
||||||
# changelog should be viewed using print(analysis.__changelog__)
|
# changelog should be viewed using print(analysis.__changelog__)
|
||||||
__changelog__ = """changelog:
|
__changelog__ = """changelog:
|
||||||
|
1.1.12.005:
|
||||||
|
- fixed numba issues by removing numba from elo, glicko2 and trueskill
|
||||||
1.1.12.004:
|
1.1.12.004:
|
||||||
- renamed gliko to glicko
|
- renamed gliko to glicko
|
||||||
1.1.12.003:
|
1.1.12.003:
|
||||||
@ -384,14 +386,12 @@ def regression(ndevice, inputs, outputs, args, loss = torch.nn.MSELoss(), _itera
|
|||||||
|
|
||||||
return regressions
|
return regressions
|
||||||
|
|
||||||
@jit(nopython=True)
|
|
||||||
def elo(starting_score, opposing_score, observed, N, K):
|
def elo(starting_score, opposing_score, observed, N, K):
|
||||||
|
|
||||||
expected = 1/(1+10**((np.array(opposing_score) - starting_score)/N))
|
expected = 1/(1+10**((np.array(opposing_score) - starting_score)/N))
|
||||||
|
|
||||||
return starting_score + K*(np.sum(observed) - np.sum(expected))
|
return starting_score + K*(np.sum(observed) - np.sum(expected))
|
||||||
|
|
||||||
@jit(forceobj=True)
|
|
||||||
def glicko2(starting_score, starting_rd, starting_vol, opposing_score, opposing_rd, observations):
|
def glicko2(starting_score, starting_rd, starting_vol, opposing_score, opposing_rd, observations):
|
||||||
|
|
||||||
player = Glicko2(rating = starting_score, rd = starting_rd, vol = starting_vol)
|
player = Glicko2(rating = starting_score, rd = starting_rd, vol = starting_vol)
|
||||||
@ -400,7 +400,6 @@ def glicko2(starting_score, starting_rd, starting_vol, opposing_score, opposing_
|
|||||||
|
|
||||||
return (player.rating, player.rd, player.vol)
|
return (player.rating, player.rd, player.vol)
|
||||||
|
|
||||||
@jit(forceobj=True)
|
|
||||||
def trueskill(teams_data, observations): # teams_data is array of array of tuples ie. [[(mu, sigma), (mu, sigma), (mu, sigma)], [(mu, sigma), (mu, sigma), (mu, sigma)]]
|
def trueskill(teams_data, observations): # teams_data is array of array of tuples ie. [[(mu, sigma), (mu, sigma), (mu, sigma)], [(mu, sigma), (mu, sigma), (mu, sigma)]]
|
||||||
|
|
||||||
team_ratings = []
|
team_ratings = []
|
||||||
|
BIN
analysis-master/dist/analysis-1.0.0.2-py3-none-any.whl
vendored
Normal file
BIN
analysis-master/dist/analysis-1.0.0.2-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
analysis-master/dist/analysis-1.0.0.2.tar.gz
vendored
Normal file
BIN
analysis-master/dist/analysis-1.0.0.2.tar.gz
vendored
Normal file
Binary file not shown.
@ -2,7 +2,7 @@ import setuptools
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="analysis", # Replace with your own username
|
name="analysis", # Replace with your own username
|
||||||
version="1.0.0.001",
|
version="1.0.0.002",
|
||||||
author="The Titan Scouting Team",
|
author="The Titan Scouting Team",
|
||||||
author_email="titanscout2022@gmail.com",
|
author_email="titanscout2022@gmail.com",
|
||||||
description="analysis package developed by Titan Scouting for The Red Alliance",
|
description="analysis package developed by Titan Scouting for The Red Alliance",
|
||||||
|
@ -158,49 +158,121 @@ def push_to_database(apikey, competition, results, metrics):
|
|||||||
|
|
||||||
def metricsloop(tbakey, apikey, competition, timestamp): # listener based metrics update
|
def metricsloop(tbakey, apikey, competition, timestamp): # listener based metrics update
|
||||||
|
|
||||||
|
elo_N = 400
|
||||||
|
elo_K = 24
|
||||||
|
|
||||||
matches = d.pull_new_tba_matches(tbakey, competition, timestamp)
|
matches = d.pull_new_tba_matches(tbakey, competition, timestamp)
|
||||||
|
|
||||||
red = load_metrics(apikey, competition, matches, "red")
|
return_vector = {}
|
||||||
blu = load_metrics(apikey, competition, matches, "blue")
|
|
||||||
|
|
||||||
elo_red_total = 0
|
|
||||||
elo_blu_total = 0
|
|
||||||
|
|
||||||
gl2_red_total = 0
|
|
||||||
gl2_blu_total + 0
|
|
||||||
|
|
||||||
for team in red:
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def load_metrics(apikey, competition, matches, group_name):
|
|
||||||
|
|
||||||
for match in matches:
|
for match in matches:
|
||||||
|
|
||||||
for team in match[group_name]:
|
red = load_metrics(apikey, competition, match, "red")
|
||||||
|
blu = load_metrics(apikey, competition, match, "blue")
|
||||||
|
|
||||||
group = {}
|
elo_red_total = 0
|
||||||
|
elo_blu_total = 0
|
||||||
|
|
||||||
db_data = d.get_team_metrics_data(apikey, competition, team)
|
gl2_red_score_total = 0
|
||||||
|
gl2_blu_score_total = 0
|
||||||
|
|
||||||
if d.get_team_metrics_data(apikey, competition, team) == None:
|
gl2_red_rd_total = 0
|
||||||
|
gl2_blu_rd_total = 0
|
||||||
|
|
||||||
elo = {"score": 1500}
|
gl2_red_vol_total = 0
|
||||||
gl2 = {"score": 1500, "rd": 250, "vol": 0.06}
|
gl2_blu_vol_total = 0
|
||||||
ts = {"mu": 25, "sigma": 25/3}
|
|
||||||
|
|
||||||
d.push_team_metrics_data(apikey, competition, team, {"elo":elo, "gliko2":gl2,"trueskill":ts})
|
for team in red:
|
||||||
|
|
||||||
group[team] = {"elo": elo, "gl2": gl2, "ts": ts}
|
elo_red_total += red[team]["elo"]["score"]
|
||||||
|
|
||||||
else:
|
gl2_red_score_total += red[team]["gl2"]["score"]
|
||||||
|
gl2_red_rd_total += red[team]["gl2"]["rd"]
|
||||||
|
gl2_red_vol_total += red[team]["gl2"]["vol"]
|
||||||
|
|
||||||
metrics = db_data["metrics"]
|
for team in blu:
|
||||||
elo = metrics["elo"]
|
|
||||||
gl2 = metrics["gliko2"]
|
|
||||||
ts = metrics["trueskill"]
|
|
||||||
|
|
||||||
group[team] = {"elo": elo, "gl2": gl2, "ts": ts}
|
elo_blu_total += blu[team]["elo"]["score"]
|
||||||
|
|
||||||
|
gl2_blu_score_total += blu[team]["gl2"]["score"]
|
||||||
|
gl2_blu_rd_total += blu[team]["gl2"]["rd"]
|
||||||
|
gl2_blu_vol_total += blu[team]["gl2"]["vol"]
|
||||||
|
|
||||||
|
red_elo = {"score": elo_red_total / len(red)}
|
||||||
|
blu_elo = {"score": elo_blu_total / len(blu)}
|
||||||
|
|
||||||
|
red_gl2 = {"score": gl2_red_score_total / len(red), "rd": gl2_red_rd_total / len(red), "vol": gl2_red_vol_total / len(red)}
|
||||||
|
blu_gl2 = {"score": gl2_blu_score_total / len(blu), "rd": gl2_blu_rd_total / len(blu), "vol": gl2_blu_vol_total / len(blu)}
|
||||||
|
|
||||||
|
|
||||||
|
if(match["winner"] == "red"):
|
||||||
|
|
||||||
|
observations = {"red": 1, "blue": 0}
|
||||||
|
|
||||||
|
elif(match["winner"] == "blue"):
|
||||||
|
|
||||||
|
observations = {"red": 0, "blue": 1}
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
observations = {"red": 0.5, "blue": 0.5}
|
||||||
|
|
||||||
|
red_elo_delta = an.elo(red_elo["score"], blu_elo["score"], [observations["red"], observations["blue"]], elo_N, elo_K) - red_elo["score"]
|
||||||
|
blu_elo_delta = an.elo(blu_elo["score"], red_elo["score"], [observations["blue"], observations["red"]], elo_N, elo_K) - blu_elo["score"]
|
||||||
|
|
||||||
|
new_red_gl2_score, new_red_gl2_rd, new_red_gl2_vol = an.glicko2(red_gl2["score"], red_gl2["rd"], red_gl2["vol"], [blu_gl2["score"]], [blu_gl2["rd"]], [observations["red"], observations["blue"]])
|
||||||
|
new_blu_gl2_score, new_blu_gl2_rd, new_blu_gl2_vol = an.glicko2(blu_gl2["score"], blu_gl2["rd"], blu_gl2["vol"], [red_gl2["score"]], [red_gl2["rd"]], [observations["blue"], observations["red"]])
|
||||||
|
|
||||||
|
red_gl2_delta = {"score": new_red_gl2_score - red_gl2["score"], "rd": new_red_gl2_rd - red_gl2["rd"], "vol": new_red_gl2_vol - red_gl2["vol"]}
|
||||||
|
blu_gl2_delta = {"score": new_blu_gl2_score - blu_gl2["score"], "rd": new_blu_gl2_rd - blu_gl2["rd"], "vol": new_blu_gl2_vol - blu_gl2["vol"]}
|
||||||
|
|
||||||
|
for team in red:
|
||||||
|
|
||||||
|
red[team]["elo"]["score"] = red[team]["elo"]["score"] + red_elo_delta
|
||||||
|
|
||||||
|
red[team]["gl2"]["score"] = red[team]["gl2"]["score"] + red_gl2_delta["score"]
|
||||||
|
red[team]["gl2"]["rd"] = red[team]["gl2"]["rd"] + red_gl2_delta["rd"]
|
||||||
|
red[team]["gl2"]["vol"] = red[team]["gl2"]["vol"] + red_gl2_delta["vol"]
|
||||||
|
|
||||||
|
for team in blu:
|
||||||
|
|
||||||
|
blu[team]["elo"]["score"] = blu[team]["elo"]["score"] + blu_elo_delta
|
||||||
|
|
||||||
|
blu[team]["gl2"]["score"] = blu[team]["gl2"]["score"] + blu_gl2_delta["score"]
|
||||||
|
blu[team]["gl2"]["rd"] = blu[team]["gl2"]["rd"] + blu_gl2_delta["rd"]
|
||||||
|
blu[team]["gl2"]["vol"] = blu[team]["gl2"]["vol"] + blu_gl2_delta["vol"]
|
||||||
|
|
||||||
|
return_vector.update(red)
|
||||||
|
return_vector.update(blu)
|
||||||
|
|
||||||
|
return return_vector
|
||||||
|
|
||||||
|
def load_metrics(apikey, competition, match, group_name):
|
||||||
|
|
||||||
|
for team in match[group_name]:
|
||||||
|
|
||||||
|
group = {}
|
||||||
|
|
||||||
|
db_data = d.get_team_metrics_data(apikey, competition, team)
|
||||||
|
|
||||||
|
if d.get_team_metrics_data(apikey, competition, team) == None:
|
||||||
|
|
||||||
|
elo = {"score": 1500}
|
||||||
|
gl2 = {"score": 1500, "rd": 250, "vol": 0.06}
|
||||||
|
ts = {"mu": 25, "sigma": 25/3}
|
||||||
|
|
||||||
|
d.push_team_metrics_data(apikey, competition, team, {"elo":elo, "gliko2":gl2,"trueskill":ts})
|
||||||
|
|
||||||
|
group[team] = {"elo": elo, "gl2": gl2, "ts": ts}
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
metrics = db_data["metrics"]
|
||||||
|
elo = metrics["elo"]
|
||||||
|
gl2 = metrics["gliko2"]
|
||||||
|
ts = metrics["trueskill"]
|
||||||
|
|
||||||
|
group[team] = {"elo": elo, "gl2": gl2, "ts": ts}
|
||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user