Commit 200cbcdf authored by Lukas Burgey's avatar Lukas Burgey

Fix Win ratio per type

parent ea426494
......@@ -531,6 +531,8 @@ class Player(dbmodels.Model):
else:
return 0
def games(self, it):
return Gam
def stats(self, it):
stats = {}
......@@ -735,24 +737,31 @@ class Game(dbmodels.Model):
self.date)
# -- STATIC METHODS --
def participating_players(it):
if it:
return it.participating_players()
else:
return Game.player_list()
def best_player_per_type(it):
return get_cached(modules[__name__], '_best_player_per_type', it)
def _best_player_per_type(it):
def player_list_type(t):
player_list = []
for player in Game.player_list().filter(game_type=t):
player_games = Game.all_games(it)\
.filter(player0=player)\
.filter(game_type=t)
for player in participating_players(it):
player_games = player.played_games(it).filter(game_type=t)
game_count = len(player_games)
if game_count < 1:
continue
win_ratio = Game.win_ratio(
player_games
.values_list('won', flat=True)
)
player_list.append({
'player': player,
'win_ratio': win_ratio,
'game_count': len(player_games),
'game_count': game_count,
})
player_list = sorted(player_list, key=lambda e: (-e['win_ratio'], -e['game_count']))
......
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