From 31cc08a6e095bd64a59a316a4a47e47a9bb646d1 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Thu, 15 Mar 2012 07:16:08 -0400 Subject: [PATCH] Add an itemized breakdown of the games played by a player. This is so we can see how many of each type of game type that the player has played. It will look like ( ). --- xonstat/templates/player_info.mako | 3 ++- xonstat/views/player.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index befb2d3..1482ae9 100755 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -23,7 +23,8 @@ Player Information Member Since: ${player.create_dt.strftime('%m/%d/%Y at %I:%M %p')}
Last Seen: ${recent_games[0][1].fuzzy_date()}
Playing Time: ${game_stats['total_alivetime']}
- Games Played: ${game_stats['total_games_played']}
+ <% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in games_breakdown]) %> + Games Played: ${total_games} (${games_breakdown_str})
Average Rank: ${game_stats['avg_rank']}
% if elos_display is not None and len(elos_display) > 0: Elo: diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 7fcfd62..9bdb6ed 100755 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -2,6 +2,7 @@ import datetime import logging import re import sqlalchemy as sa +import sqlalchemy.sql.functions as func import time from pyramid.response import Response from pyramid.url import current_route_url @@ -46,6 +47,27 @@ def player_index(request): } +def games_played(player_id): + """ + Provides a breakdown by gametype of the games played by player_id. + + Returns a tuple containing (total_games, games_breakdown), where + total_games is the absolute number of games played by player_id + and games_breakdown is an array containing (game_type_cd, # games) + """ + games_played = DBSession.query(Game.game_type_cd, func.count()).\ + filter(Game.game_id == PlayerGameStat.game_id).\ + filter(PlayerGameStat.player_id == player_id).\ + group_by(Game.game_type_cd).\ + order_by(func.count().desc()).all() + + total = 0 + for (game_type_cd, games) in games_played: + total += games + + return (total, games_played) + + def player_info(request): """ Provides detailed information on a specific player @@ -58,6 +80,8 @@ def player_info(request): player = DBSession.query(Player).filter_by(player_id=player_id).\ filter(Player.active_ind == True).one() + (total_games, games_breakdown) = games_played(player.player_id) + elos = DBSession.query(PlayerElo).filter_by(player_id=player_id).\ filter(PlayerElo.game_type_cd.in_(['ctf','duel','dm'])).\ order_by(PlayerElo.elo.desc()).all() @@ -136,12 +160,16 @@ def player_info(request): weapon_stats = None game_stats = None recent_games = None + total_games = None + games_breakdown = None return {'player':player, 'elos_display':elos_display, 'recent_games':recent_games, 'weapon_stats':weapon_stats, - 'game_stats':game_stats} + 'game_stats':game_stats, + 'total_games':total_games, + 'games_breakdown':games_breakdown} def player_game_index(request): -- 2.39.2