From: Ant Zucaro Date: Thu, 27 Sep 2012 02:16:40 +0000 (-0400) Subject: Localize the last seen time for all game types. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e031b6fdf4edb778b801fc254a80fedced0b4603;p=xonotic%2Fxonstat.git Localize the last seen time for all game types. --- diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index 10ec1ad..8bb282f 100644 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -211,7 +211,7 @@ Player Information

% if g.game_type_cd in overall_stats: - Last Played: ${overall_stats[g.game_type_cd].last_played.strftime('%a, %d %b %Y %H:%M UTC')}
+ Last Played: ${overall_stats[g.game_type_cd].last_played_fuzzy}
% endif Games Played: ${g.games}
diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 29ce3de..87a14cf 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -5,13 +5,14 @@ import re import sqlalchemy as sa import sqlalchemy.sql.functions as func import time +from calendar import timegm from collections import namedtuple from pyramid.response import Response from pyramid.url import current_route_url from sqlalchemy import desc, distinct from webhelpers.paginate import Page, PageURL from xonstat.models import * -from xonstat.util import page_url, to_json +from xonstat.util import page_url, to_json, pretty_date log = logging.getLogger(__name__) @@ -130,6 +131,8 @@ def get_overall_stats(player_id): - total_deaths - k_d_ratio - last_played (last time the player played the game type) + - last_played_epoch (same as above, but in seconds since epoch) + - last_played_fuzzy (same as above, but in relative date) - total_playing_time (total amount of time played the game type) - total_pickups (ctf only) - total_captures (ctf only) @@ -141,8 +144,9 @@ def get_overall_stats(player_id): "overall" game_type_cd which sums the totals and computes the total ratios. """ OverallStats = namedtuple('OverallStats', ['total_kills', 'total_deaths', - 'k_d_ratio', 'last_played', 'total_playing_time', 'total_pickups', - 'total_captures', 'cap_ratio', 'total_carrier_frags', 'game_type_cd']) + 'k_d_ratio', 'last_played', 'last_played_epoch', 'last_played_fuzzy', + 'total_playing_time', 'total_pickups', 'total_captures', 'cap_ratio', + 'total_carrier_frags', 'game_type_cd']) raw_stats = DBSession.query('game_type_cd', 'total_kills', 'total_deaths', 'last_played', 'total_playing_time', @@ -201,6 +205,8 @@ def get_overall_stats(player_id): total_deaths=row.total_deaths, k_d_ratio=k_d_ratio, last_played=row.last_played, + last_played_epoch=timegm(row.last_played.timetuple()), + last_played_fuzzy=pretty_date(row.last_played), total_playing_time=row.total_playing_time, total_pickups=row.total_pickups, total_captures=row.total_captures, @@ -220,6 +226,8 @@ def get_overall_stats(player_id): total_deaths=overall_deaths, k_d_ratio=overall_k_d_ratio, last_played=overall_last_played, + last_played_epoch=timegm(overall_last_played.timetuple()), + last_played_fuzzy=pretty_date(overall_last_played), total_playing_time=overall_playing_time, total_pickups=None, total_captures=None,