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):
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,
<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 />
<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>
% 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
% 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">
<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>
% 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>
<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 />
% 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>
% 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>
% 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>
% 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>
% 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>
<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>
<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>
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 = [
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)))