]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Use relative time everywhere, but add hover with absolute time.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 2 Sep 2012 17:08:36 +0000 (13:08 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 2 Sep 2012 17:08:36 +0000 (13:08 -0400)
Use "fuzzy" dates everywhere (e.g. "an hour ago"), but allow for
a hover showing the absolute UTC time when needed. This is done
with a span and a title attribute.

xonstat/models.py
xonstat/templates/game_info.mako
xonstat/templates/main_index.mako
xonstat/templates/map_index.mako
xonstat/templates/map_info.mako
xonstat/templates/player_index.mako
xonstat/templates/player_info.mako
xonstat/templates/search.mako
xonstat/templates/server_index.mako
xonstat/templates/server_info.mako
xonstat/util.py

index 84a64ea9a665fc6c9d49e52f12c041d8d48bca17..6de2fa05666948a0bd9fcde785a0c1bf83fab754 100644 (file)
@@ -67,6 +67,9 @@ class Server(object):
     def to_dict(self):
         return {'server_id':self.server_id, 'name':self.name.encode('utf-8')}
 
+    def fuzzy_date(self):
+        return pretty_date(self.create_dt)
+
 
 class Map(object):
     def __init__(self, name=None):
@@ -78,6 +81,8 @@ class Map(object):
     def to_dict(self):
         return {'map_id':self.map_id, 'name':self.name, 'version':self.version}
 
+    def fuzzy_date(self):
+        return pretty_date(self.create_dt)
 
 class Game(object):
     def __init__(self, game_id=None, start_dt=None, game_type_cd=None, 
index 67446bc079a9705d6179aa92bc754d0b7e6e905c..19234e9ec42aa41f516d24d55d623872bdc349e2 100644 (file)
@@ -31,7 +31,7 @@ Game Information
   <div class="span6">
     <h2>Game Detail</h2>
     <p>
-      Played on: ${game.start_dt.strftime('%m/%d/%Y at %I:%M %p')}<br />
+      Played: ${game.fuzzy_date()} (${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')})<br />
       Game Type: ${game.game_type_cd}<br />
       Server: <a href="${request.route_url("server_info", id=server.server_id)}" name="Server info page for ${server.name}">${server.name}</a><br />
       Map: <a href="${request.route_url("map_info", id=map.map_id)}" name="Map info page for ${map.name}">${map.name}</a><br />
index c731a0eecdef44d7e7f8e52a2cc85fb7e3159400..3b9d4537974ec98684d8b0b741b7766862f6a144 100644 (file)
@@ -226,7 +226,7 @@ Leaderboard
           <td class="gt_icon"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td>
           <td><a href="${request.route_url('server_info', id=server.server_id)}" title="Go to the detail page for this server">${server.name}</a></td>
           <td><a href="${request.route_url('map_info', id=map.map_id)}" title="Go to the map detail page for this map">${map.name}</a></td>
-          <td>${game.start_dt.strftime('%m/%d/%Y %H:%M')}</td>
+          <td><span title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td>
           <td>
             % if pgstat.player_id > 2:
             <a href="${request.route_url('player_info', id=pgstat.player_id)}" title="Go to the player info page for this player">${pgstat.nick_html_colors()|n}</a></td>
index bb297ee6a20f3f0462e4e5642a2f1d949d9ae553..49a97c6a9ada0f295673b66466ea0991e23eccf2 100644 (file)
@@ -29,7 +29,7 @@ Map Index
     % for map in maps:
       <tr>
         <td><a href="${request.route_url("map_info", id=map.map_id)}" title="Go to this map's info page">${map.name}</a></th>
-        <td>${map.create_dt.strftime('%m/%d/%Y at %H:%M')}</td>
+        <td><span title="${map.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${map.fuzzy_date()}</span></td>
     </td>
       </tr>
     % endfor
index 7e975c152221b0b9baa0094b1fec5296dc634560..21b85896fbd86f827c998555ce5deff6f016d696 100644 (file)
@@ -21,7 +21,7 @@ ${parent.title()}
 % else:
 <h2>${gmap.name}</h2>
 <p>
-  Added on ${gmap.create_dt.strftime('%m/%d/%Y at %H:%M')}
+  Added <span title="${gmap.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${gmap.fuzzy_date()}</span>
 </p>
 <div class="row">
   <div class="span4">
@@ -126,7 +126,7 @@ ${parent.title()}
         <tr>
           <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=game.game_id)}" title="View detailed information about this game">View</a></td>
           <td class="gt_icon"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td>
-          <td>${game.start_dt.strftime('%m/%d/%Y %H:%M')}</td>
+          <td><span title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td>
           <td>
             % if pgstat.player_id > 2:
             <a href="${request.route_url('player_info', id=pgstat.player_id)}" title="Go to the player info page for this player">${pgstat.nick_html_colors()|n}</a>
index 2ef7d5c481c4a164588be1e1cdf7689d7c7de02a..78848d73ae46b3b25625cf5783fff5abbcee8c04 100644 (file)
@@ -29,7 +29,7 @@ Player Index
     % for player in players:
       <tr>
         <td><a href="${request.route_url("player_info", id=player.player_id)}" title="Go to this player's info page">${player.nick_html_colors()|n}</a></th>
-        <td>${player.joined_pretty_date()}</th>
+        <td><span title="${player.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${player.joined_pretty_date()}</span></th>
       </tr>
     % endfor
     </table>
index 19835094182d57d79b3df596054e7dfd672396e0..f1237d0a5adbde244ddcd8f7c154ea0405ff724a 100644 (file)
@@ -182,7 +182,7 @@ Player Information
     <p>
       Member Since: <small>${player.create_dt.strftime('%m/%d/%Y at %I:%M %p')} </small><br />
 
-      Last Seen: <small>${recent_games[0][1].fuzzy_date()} </small><br />
+      Last Seen: <small><span title="${recent_games[0][1].create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${recent_games[0][1].fuzzy_date()}</span> </small><br />
 
       Playing Time: <small>${total_stats['alivetime']} </small><br />
 
@@ -402,7 +402,7 @@ Player Information
             % endif
           % endif
            </td>
-           <td>${game.fuzzy_date()}</td>
+           <td><span title="${game.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td>
         </tr>
       % endfor
       </tbody>
index a7d54547f9947b5dba33df6d3fe7033f0018b8f8..45223b25f2e9adb44a18ba5451c2b11bc2043e4c 100644 (file)
@@ -47,7 +47,7 @@
     % for player in results:
     <tr>
         <td><a href="${request.route_url("player_info", id=player.player_id)}" name="Player info page for player #${player.player_id}">${player.nick_html_colors()|n}</a></td>
-        <td>${player.joined_pretty_date()}</td>
+        <td><span title="${player.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${player.joined_pretty_date()}</span></td>
     </tr>
     % endfor
 </table>
@@ -63,7 +63,7 @@
     % for server in results:
     <tr>
         <td><a href="${request.route_url("server_info", id=server.server_id)}" name="Server info page for server #${server.server_id}">${server.name}</a></td>
-        <td>${server.create_dt.strftime('%m/%d/%Y at %I:%M %p')}</td>
+        <td><span title="${server.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${server.fuzzy_date()}</span></td>
     </tr>
     % endfor
 </table>
@@ -79,7 +79,7 @@
     % for map in results:
     <tr>
         <td><a href="${request.route_url("map_info", id=map.map_id)}" name="Map info page for map #${map.map_id}">${map.name}</a></td>
-        <td>${map.create_dt.strftime('%m/%d/%Y at %I:%M %p')}</td>
+        <td><span title="${map.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${map.fuzzy_date()}</span></td>
     </tr>
     % endfor
 </table>
         <th></th>
         <th>Map</th>
         <th>Server</th>
-        <th>Played On</th>
+        <th>Time</th>
     </tr>
     % for (game, server, gmap) in results:
     <tr>
         <td><a class="btn btn-primary btn-small" href="${request.route_url("game_info", id=game.game_id)}" name="Game info page for game #${game.game_id}">View</a></td>
         <td><a href="${request.route_url("map_info", id=gmap.map_id)}" name="Map info page for map #${gmap.map_id}">${gmap.name}</a></td>
         <td><a href="${request.route_url("server_info", id=server.server_id)}" name="Server info page for server #${server.server_id}">${server.name}</a></td>
-        <td>${game.create_dt.strftime('%m/%d/%Y at %I:%M %p')}</td>
+        <td><span title="${game.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td>
     </tr>
     % endfor
 </table>
index bc2b37843fdfdb91f73bb758f951b2aebfeb38d9..755994739adfd8494e846476c41dd5ae6a0880a6 100644 (file)
@@ -29,7 +29,7 @@ Server Index
     % for server in servers:
       <tr>
         <td><a href="${request.route_url("server_info", id=server.server_id)}" title="Go to this server's info page">${server.name}</a></th>
-        <td>${server.create_dt.strftime('%m/%d/%Y at %H:%M')}</td>
+        <td><span title="${server.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${server.fuzzy_date()}</span></td>
       </tr>
     % endfor
     </table>
index 2c8d4963b505bed9e0fefb5c2824b6ca6380ed15..96875ca0315f86f50614d7fd505d5a2b44fb0687 100644 (file)
@@ -22,7 +22,7 @@ Server Information
     <p>
       IP Address: ${server.ip_addr} <br />
       Revision: ${server.revision} <br />
-      Added on ${server.create_dt.strftime('%m/%d/%Y at %I:%M %p')} <br />
+      Added <span title="${server.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${server.fuzzy_date()}</span> <br />
     </p>
   </div>
 </div>
@@ -139,7 +139,7 @@ Server Information
           <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=game.game_id)}" title="View detailed information about this game">View</a></td>
           <td class="gt_icon"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td>
           <td><a href="${request.route_url('map_info', id=map.map_id)}" title="Go to the map detail page for this map">${map.name}</a></td>
-          <td>${game.start_dt.strftime('%m/%d/%Y %H:%M')}</td>
+          <td><span title="${game.start_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td>
           <td>
           % if pgstat.player_id > 2:
             <a href="${request.route_url('player_info', id=pgstat.player_id)}" title="Go to the player info page for this player">${pgstat.nick_html_colors()|n}</a>
index 1bea47c94d8100e3047464dc6601657d010d9de3..f9aa1d5c07f96135f47cfdc71d2972bb3b693ec1 100644 (file)
@@ -1,7 +1,7 @@
 import re
 from colorsys import rgb_to_hls, hls_to_rgb
 from cgi import escape as html_escape
-from datetime import datetime
+from datetime import datetime, timedelta
 
 # Map of special chars to ascii from Darkplace's console.c.
 _qfont_table = [
@@ -113,53 +113,41 @@ def page_url(page):
 
 
 def pretty_date(time=False):
-    """
-    Get a datetime object or a int() Epoch timestamp and return a
-    pretty string like 'an hour ago', 'Yesterday', '3 months ago',
-    'just now', etc
-    """
+    '''Returns a human-readable relative date.'''
     now = datetime.utcnow()
     if type(time) is int:
         diff = now - datetime.fromtimestamp(time)
     elif isinstance(time,datetime):
-        diff = now - time 
+        diff = now - time
     elif not time:
+        print "not a time value"
         diff = now - now
-    second_diff = diff.seconds
-    day_diff = diff.days
-
-    if day_diff < 0:
-        return ''
-
-    if day_diff == 0:
-        if second_diff < 10:
-            return "just now"
-        if second_diff < 60:
-            return str(second_diff) + " seconds ago"
-        if second_diff < 120:
-            return  "a minute ago"
-        if second_diff < 3600:
-            return str( second_diff / 60 ) + " minutes ago"
-        if second_diff < 7200:
-            return "an hour ago"
-        if second_diff < 86400:
-            return str( second_diff / 3600 ) + " hours ago"
-    if day_diff == 1:
-        return "Yesterday"
-    if day_diff < 7:
-        return str(day_diff) + " days ago"
-    if day_diff < 31:
-        if day_diff/7 == 1:
-            return "a week ago"
-        else:
-            return str(day_diff/7) + " weeks ago"
-    if day_diff < 365:
-        if day_diff/30 == 1:
-            return "a month ago"
-        else:
-            return str(day_diff/30) + " months ago"
+
+    dim = round(diff.seconds/60.0 + diff.days*1440.0)
+
+    if dim == 0:
+        return "less than a minute ago"
+    elif dim == 1:
+        return "1 minute ago"
+    elif dim >= 2 and dim <= 44:
+        return "{0} minutes ago".format(int(dim))
+    elif dim >= 45 and dim <= 89:
+        return "about 1 hour ago"
+    elif dim >= 90 and dim <= 1439:
+        return "about {0} hours ago".format(int(round(dim/60.0)))
+    elif dim >= 1440 and dim <= 2519:
+        return "1 day ago"
+    elif dim >= 2520 and dim <= 43199:
+        return "{0} days ago".format(int(round(dim/1440.0)))
+    elif dim >= 43200 and dim <= 86399:
+        return "about 1 month ago"
+    elif dim >= 86400 and dim <= 525599:
+        return "{0} months ago".format(int(round(dim/43200.0)))
+    elif dim >= 525600 and dim <= 655199:
+        return "about 1 year ago"
+    elif dim >= 655200 and dim <= 914399:
+        return "over 1 year ago"
+    elif dim >= 914400 and dim <= 1051199:
+        return "almost 2 years ago"
     else:
-        if day_diff/365 == 1:
-            return "a year ago"
-        else:
-            return str(day_diff/365) + " years ago"
+        return "about {0} years ago".format(int(round(dim/525600.0)))