Commit 31144f1c authored by Lukas Burgey's avatar Lukas Burgey

Add glicko2 to STATS

parent e4d5a340
......@@ -20,6 +20,7 @@ STAT_DESCRIPTION = {}
# stats
STATS = [
'elo',
'glicko2',
'points',
'pointsperpart',
......@@ -127,16 +128,19 @@ def _elo_history():
return elo_ratings
def glicko2_history():
return get_cached(modules[__name__], '_glicko2_history')
# hidden method with computation
def _glicko2_history():
glicko2 = Glicko2(800, 100, 0.1, 1.2)
players = Player.objects.all()
ratings = _glicko2(players=players, periods=_get_rating_periods(), glicko2=glicko2)
ratings = __glicko2(players=players, periods=_get_rating_periods(), glicko2=glicko2)
ratings_return = {}
for player in players:
ratings_return[player] = [rating.rating for rating in ratings[player]]
return ratings_return
def _glicko2(players, periods, glicko2):
def __glicko2(players, periods, glicko2):
ratings = {}
for player in players:
......@@ -302,11 +306,15 @@ class Player(dbmodels.Model):
return Game.objects.all().order_by('date')
STAT_DESCRIPTION['elo_history'] = "Elo history", "EloH"
STAT_DESCRIPTION['glicko2_history'] = "Glicko2 history", "Gl2H"
STAT_DESCRIPTION['elo'] = "Elo rating", "Elo"
def elo(self, it):
return elo_history()[self][-1]
STAT_DESCRIPTION['glicko2_history'] = "Glicko2 history", "GL2H"
STAT_DESCRIPTION['glicko2'] = "Glicko2 rating", "GL2"
def glicko2(self, it):
return glicko2_history()[self][-1]
STAT_DESCRIPTION['streaks'] = "Streaks","Str"
def streaks(self, it):
played_games = self.played_games(it).values_list('won', flat=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment