From: Jan D. Behrens Date: Sat, 4 Aug 2012 20:46:21 +0000 (+0200) Subject: Implemented feature #1228: X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=48ba8b7579c20fa17812b200fea2973287f8b260;p=xonotic%2Fxonstat.git Implemented feature #1228: Show weekly/monthly timer on the player_info page - http://dev.xonotic.org/issues/1228 Also added "suicides" to kill/death statistics (number only, no ratio) --- diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index c01ff1a..444d97f 100644 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -189,7 +189,15 @@ Player Information Last Seen: ${recent_games[0][1].fuzzy_date()}
- Playing Time: ${total_stats['alivetime']}
+ Playing Time: ${total_stats['alivetime']} hours + % if total_stats['alivetime'] > total_stats['alivetime_month']: + % if total_stats['alivetime_month'] > total_stats['alivetime_week']: + (${total_stats['alivetime_month']} hours this month; ${total_stats['alivetime_week']} hours this week) + % else: + (${total_stats['alivetime_month']} hours this month) + % endif + % endif +
<% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in games_breakdown]) %> Games Played: ${total_games} (${games_breakdown_str})
@@ -230,7 +238,7 @@ Player Information % endif % if total_stats['kills'] > 0 and total_stats['deaths'] > 0: - Kill Ratio: ${round(float(total_stats['kills'])/total_stats['deaths'], 3)} (${total_stats['kills']} kills, ${total_stats['deaths']} deaths)
+ Kill Ratio: ${round(float(total_stats['kills'])/total_stats['deaths'], 3)} (${total_stats['kills']} kills, ${total_stats['deaths']} deaths, ${total_stats['suicides']} suicides)
% endif % if elos_display is not None and len(elos_display) > 0: diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 5f211d3..443e9d5 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -83,30 +83,45 @@ def _get_total_stats(player_id): kills = how many kills a player has over all games deaths = how many deaths a player has over all games + suicides = how many suicides a player has over all games alivetime = how long a player has played over all games + alivetime_week = how long a player has played over all games in the last week + alivetime_month = how long a player has played over all games in the last month + wins = how many games a player has won If any of the above are None, they are set to 0. """ + # 7 and 30 day windows + one_week_ago = datetime.datetime.utcnow() - datetime.timedelta(days=7) + one_month_ago = datetime.datetime.utcnow() - datetime.timedelta(days=30) + total_stats = {} - (total_stats['kills'], total_stats['deaths'], total_stats['alivetime']) = DBSession.\ - query("total_kills", "total_deaths", "total_alivetime").\ - from_statement( - "select sum(kills) total_kills, " - "sum(deaths) total_deaths, " - "sum(alivetime) total_alivetime " - "from player_game_stats " - "where player_id=:player_id" - ).params(player_id=player_id).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['kills'], total_stats['deaths'], total_stats['suicides'], total_stats['alivetime'],) = DBSession.query( + func.sum(PlayerGameStat.kills), + func.sum(PlayerGameStat.deaths), + func.sum(PlayerGameStat.suicides), + func.sum(PlayerGameStat.alivetime)).\ + filter(PlayerGameStat.player_id == player_id).\ + one() + + (total_stats['alivetime_week'],) = DBSession.query( + func.sum(PlayerGameStat.alivetime)).\ + filter(PlayerGameStat.player_id == player_id).\ + filter(PlayerGameStat.create_dt > one_week_ago).\ + one() + + (total_stats['alivetime_month'],) = DBSession.query( + func.sum(PlayerGameStat.alivetime)).\ + filter(PlayerGameStat.player_id == 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() for (key,value) in total_stats.items(): if value == None: