From b32454b30219ec8f0354a58733e109f102299aa2 Mon Sep 17 00:00:00 2001 From: "Jan D. Behrens" Date: Tue, 28 Aug 2012 18:49:02 +0200 Subject: [PATCH] Fixed bug in "total wins" query - NOTE: other queries (e.g. duel wins) are still flawed! --- xonstat/views/player.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 0bc24b9..a1ff719 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -138,12 +138,22 @@ def _get_total_stats(player_id): filter(PlayerGameStat.create_dt > one_month_ago).\ one() - (total_stats['wins'],) = DBSession.query( - func.count("*")).\ - filter(Game.game_id == PlayerGameStat.game_id).\ - filter(PlayerGameStat.player_id == player_id).\ - filter(Game.winner == PlayerGameStat.team or PlayerGameStat.rank == 1).\ - one() + (total_stats['wins'],) = DBSession.\ + query("total_wins").\ + from_statement( + "select count(*) total_wins " + "from games g, player_game_stats pgs " + "where g.game_id = pgs.game_id " + "and player_id=:player_id " + "and (g.winner = pgs.team or pgs.rank = 1)" + ).params(player_id=player_id).one() + +# (total_stats['wins'],) = DBSession.query( +# func.count("*")).\ +# filter(Game.game_id == PlayerGameStat.game_id).\ +# filter(PlayerGameStat.player_id == player_id).\ +# filter(Game.winner == PlayerGameStat.team or PlayerGameStat.rank == 1).\ +# one() (total_stats['duel_wins'],) = DBSession.query( func.count("*")).\ -- 2.39.2