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")
+ config.add_route("top_maps_by_times_played", "/topmaps")
+ config.add_view(top_maps_by_times_played, route_name="top_maps_by_times_played", renderer="top_maps_by_times_played.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('maps')}
+</%block>
+
+<%block name="title">
+Active Maps Index
+</%block>
+
+% if not top_maps:
+<h2>Sorry, no maps 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;">Map</th>
+ <th style="width:60px;">Games</th>
+ </tr>
+ </thead>
+ <tbody>
+ ##### this is to get around the actual row_number/rank of the map not being in the actual query
+ <% i = 1 + (top_maps.page-1) * 25%>
+ % for (map_id, name, count) in top_maps:
+ <tr>
+ <td>${i}</td>
+ % if map_id != '-':
+ <td class="nostretch" style="max-width:180px;"><a href="${request.route_url('map_info', id=map_id)}" title="Go to the map 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_maps_by_times_played", top_maps.page, top_maps.last_page)}
+ </div> <!-- /span4 -->
+</div> <!-- /row -->
return top_servers
-@cache_region('hourly_term')
-def top_maps_by_times_played(cutoff_days):
+def top_maps_by_times_played_q(cutoff_days):
"""
- The top maps by the amount of times it was played during a date range.
+ Query to retrieve the top maps by the amount of times it was played
+ 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_maps = DBSession.query(Game.map_id, Map.name,
+ top_maps_q = DBSession.query(Game.map_id, Map.name,
func.count()).\
filter(Map.map_id==Game.map_id).\
filter(expr.between(Game.create_dt, cutoff_dt, right_now)).\
order_by(expr.desc(func.count())).\
group_by(Game.map_id).\
- group_by(Map.name).limit(count).all()
+ group_by(Map.name)
+
+ return top_maps_q
+
+
+@cache_region('hourly_term')
+def get_top_maps_by_times_played(cutoff_days):
+ """
+ The top maps by the amount of times it was played during a date range.
+
+ Games older than cutoff_days days old are ignored.
+ """
+ # how many to retrieve
+ count = 10
+
+ top_maps = top_maps_by_times_played_q(cutoff_days).limit(count).all()
return top_maps
top_servers = get_top_servers_by_players(leaderboard_lifetime)
# top maps by total times played
- top_maps = top_maps_by_times_played(leaderboard_lifetime)
+ top_maps = get_top_maps_by_times_played(leaderboard_lifetime)
# recent games played in descending order
rgs = recent_games_q(cutoff=back_then).limit(recent_games_count).all()
top_servers = Page(top_servers_q, current_page, items_per_page=25, url=page_url)
return {'top_servers':top_servers}
+
+
+def top_maps_by_times_played(request):
+ current_page = request.params.get('page', 1)
+
+ cutoff_days = int(request.registry.settings.\
+ get('xonstat.leaderboard_lifetime', 30))
+
+ top_maps_q = top_maps_by_times_played_q(cutoff_days)
+
+ top_maps = Page(top_maps_q, current_page, items_per_page=25, url=page_url)
+
+ return {'top_maps':top_maps}