From: Ant Zucaro Date: Mon, 18 Jun 2012 00:35:04 +0000 (-0400) Subject: Change the query group by, return dict instead of Map. X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonstat.git;a=commitdiff_plain;h=ca8cca3e2ff5b88b75140a20f2060074313bac6e Change the query group by, return dict instead of Map. --- diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index f154463..9c8376d 100644 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -190,7 +190,7 @@ Player Information Games Played: ${total_games} (${games_breakdown_str})
% if fav_map is not None: - Favorite Map: ${fav_map.name}
+ Favorite Map: ${fav_map['name']}
% endif

diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 9eaf218..211fe09 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -121,20 +121,24 @@ def _get_fav_map(player_id): as the map that he or she has played the most in the past 90 days. - Returns a map object. + Returns a dictionary with keys for the map's name and id. """ # 90 day window back_then = datetime.datetime.utcnow() - datetime.timedelta(days=90) - fav_map = DBSession.query(Map).\ + raw_fav_map = DBSession.query(Map.name, Map.map_id).\ filter(Game.game_id == PlayerGameStat.game_id).\ filter(Game.map_id == Map.map_id).\ filter(PlayerGameStat.player_id == player_id).\ filter(PlayerGameStat.create_dt > back_then).\ - group_by(Map.map_id).\ + group_by(Map.name, Map.map_id).\ order_by(func.count().desc()).\ limit(1).one() + fav_map = {} + fav_map['name'] = raw_fav_map[0] + fav_map['id'] = raw_fav_map[1] + return fav_map