config.add_route("top_players_by_time", "/topactive")
config.add_view(top_players_by_time, route_name="top_players_by_time", renderer="top_players_by_time.mako")
+ config.add_route("top_servers_by_players", "/topservers")
+ config.add_view(top_servers_by_players, route_name="top_servers_by_players", renderer="top_servers_by_players.mako")
+
# GAME ROUTES
config.add_route("game_info", "/game/{id:\d+}")
config.add_view(game_info, route_name="game_info", renderer="game_info.mako")
--- /dev/null
+<%inherit file="base.mako"/>
+<%namespace name="nav" file="nav.mako" />
+<%namespace file="navlinks.mako" import="navlinks" />
+
+<%block name="navigation">
+${nav.nav('servers')}
+</%block>
+
+<%block name="title">
+Active Servers Index
+</%block>
+
+% if not top_servers:
+<h2>Sorry, no servers yet. Get playing!</h2>
+
+% else:
+##### ACTIVE SERVERS #####
+ <div class="span6 offset3">
+ <table class="table table-hover table-condensed">
+ <thead>
+ <tr>
+ <th style="width:40px;">#</th>
+ <th style="width:180px;">Server</th>
+ <th style="width:60px;">Games</th>
+ </tr>
+ </thead>
+ <tbody>
+ ##### this is to get around the actual row_number/rank of the server not being in the actual query
+ <% i = 1 + (top_servers.page-1) * 25%>
+ % for (server_id, name, count) in top_servers.items:
+ <tr>
+ <td>${i}</td>
+ % if server_id != '-':
+ <td class="nostretch" style="max-width:180px;"><a href="${request.route_url('server_info', id=server_id)}" title="Go to the server info page for ${name}">${name}</a></td>
+ % else:
+ <td class="nostretch" style="max-width:180px;">${name}</td>
+ % endif
+ <td>${count}</td>
+ </tr>
+ <% i = i+1 %>
+ % endfor
+ </tbody>
+ </table>
+ <p class="note">*figures are from the past 7 days</p>
+ </div> <!-- /span4 -->
+% endif
+
+${navlinks("top_servers_by_players", top_servers.page, top_servers.last_page)}
+ </div> <!-- /span4 -->
+</div> <!-- /row -->
return top_players
-@cache_region('hourly_term')
-def top_servers_by_players(cutoff_days):
+def top_servers_by_players_q(cutoff_days):
"""
- The top servers by the amount of players active during a date range.
+ Query to get the top servers by the amount of players active
+ during a date range.
Games older than cutoff_days days old are ignored.
"""
- # how many to retrieve
- count = 10
-
# only games played during this range are considered
right_now = datetime.utcnow()
cutoff_dt = right_now - timedelta(days=cutoff_days)
- top_servers = DBSession.query(Server.server_id, Server.name,
+ top_servers_q = DBSession.query(Server.server_id, Server.name,
func.count()).\
filter(Game.server_id==Server.server_id).\
filter(expr.between(Game.create_dt, cutoff_dt, right_now)).\
order_by(expr.desc(func.count(Game.game_id))).\
group_by(Server.server_id).\
- group_by(Server.name).limit(count).all()
+ group_by(Server.name)
+
+ return top_servers_q
+
+
+@cache_region('hourly_term')
+def get_top_servers_by_players(cutoff_days):
+ """
+ The top servers by the amount of players active during a date range.
+
+ Games older than cutoff_days days old are ignored.
+ """
+ # how many to retrieve
+ count = 10
+
+ top_servers = top_servers_by_players_q(cutoff_days).limit(count).all()
return top_servers
top_players = get_top_players_by_time(leaderboard_lifetime)
# top servers by number of total players played
- top_servers = top_servers_by_players(leaderboard_lifetime)
+ top_servers = get_top_servers_by_players(leaderboard_lifetime)
# top maps by total times played
top_maps = top_maps_by_times_played(leaderboard_lifetime)
for (player_id, nick, score) in top_players.items]
return {'top_players':top_players}
+
+
+def top_servers_by_players(request):
+ current_page = request.params.get('page', 1)
+
+ cutoff_days = int(request.registry.settings.\
+ get('xonstat.leaderboard_lifetime', 30))
+
+ top_servers_q = top_servers_by_players_q(cutoff_days)
+
+ top_servers = Page(top_servers_q, current_page, items_per_page=25, url=page_url)
+
+ return {'top_servers':top_servers}