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}