</div>
</%block>
+% if len(ranks) < 3:
<div class="row">
+ <div class="span12">
+ <p style="text-align: center;"><i class="icon-white icon-info-sign"> </i> You don't seem to have any ranks yet.</p>
+ </div> <!-- span12 -->
+</div> <!-- row -->
+% else:
+<div class="row">
+% for rs in ranks[:3]:
+ % if len(rs) > 0:
<div class="span4">
- ##### DUEL RANKS #####
- <h3>Duel Ranks</h3>
- <table class="table table-bordered table-condensed">
- <thead>
- <tr>
- <th>#</th>
- <th>Nick</th>
- <th>Elo</th>
- </tr>
- </thead>
- <tbody>
- <% i = 1 %>
- % for (player_id, nick, elo) in duel_ranks:
- <tr>
- <td>${i}</td>
- % if player_id != '-':
- <td><a href="${request.route_url('player_info', id=player_id)}" title="Go to the player info page for this player">${nick|n}</a></td>
- % else:
- <td>${nick|n}</td>
- % endif
- % if elo != '-':
- <td>${round(elo, 3)}</td>
- % else:
- <td>${elo}</td>
- % endif
- </tr>
- <% i = i+1 %>
- % endfor
- </tbody>
- </table>
- <p class="note"><a href="${request.route_url('rank_index', page=1, game_type_cd='duel')}" title="See more duel rankings">More...</a></p>
- </div> <!-- /span4 -->
- <div class="span4">
- ##### CTF RANKS #####
+ % if rs[0].game_type_cd == 'duel':
+ <h3>Duel Ranks</h3>
+ % elif rs[0].game_type_cd == 'ctf':
<h3>CTF Ranks</h3>
+ % elif rs[0].game_type_cd == 'dm':
+ <h3>DM Ranks</h3>
+ % endif
+
<table class="table table-bordered table-condensed">
<thead>
<tr>
</thead>
<tbody>
<% i = 1 %>
- % for (player_id, nick, elo) in ctf_ranks:
+ % for r in rs:
<tr>
<td>${i}</td>
- % if player_id != '-':
- <td><a href="${request.route_url('player_info', id=player_id)}" title="Go to the player info page for this player">${nick|n}</a></td>
- % else:
- <td>${nick|n}</td>
- % endif
- % if elo != '-':
- <td>${round(elo, 3)}</td>
- % else:
- <td>${elo}</td>
- % endif
+ <td><a href="${request.route_url('player_info', id=r.player_id)}" title="Go to the player info page for this player">${r.nick_html_colors()|n}</a></td>
+ <td>${round(r.elo, 3)}</td>
</tr>
<% i = i+1 %>
% endfor
</tbody>
</table>
- <p class="note"><a href="${request.route_url('rank_index', page=1, game_type_cd='ctf')}" title="See more CTF rankings">More...</a></p>
+ <p class="note"><a href="${request.route_url('rank_index', page=1, game_type_cd=rs[0].game_type_cd)}" title="See more ${rs[0].game_type_cd} rankings">More...</a></p>
</div> <!-- /span4 -->
+ % endif
+
+% endfor
+</div> <!-- row -->
+% endif
- <div class="span4">
- ##### DM RANKS #####
- <h3>DM Ranks</h3>
- <table class="table table-bordered table-condensed">
- <thead>
- <tr>
- <th>#</th>
- <th>Nick</th>
- <th>Elo</th>
- </tr>
- </thead>
- <tbody>
- <% i = 1 %>
- % for (player_id, nick, elo) in dm_ranks:
- <tr>
- <td>${i}</td>
- % if player_id != '-':
- <td><a href="${request.route_url('player_info', id=player_id)}" title="Go to the player info page for this player">${nick|n}</a></td>
- % else:
- <td>${nick|n}</td>
- % endif
- % if elo != '-':
- <td>${round(elo, 3)}</td>
- % else:
- <td>${elo}</td>
- % endif
- </tr>
- <% i = i+1 %>
- % endfor
- </tbody>
- </table>
- <p class="note"><a href="${request.route_url('rank_index', page=1, game_type_cd='dm')}" title="See more deathmatch rankings">More...</a></p>
- </div> <!-- /span4 -->
-</div> <!-- /row -->
<div class="row">
<div class="span4">
import sqlalchemy.sql.functions as func
import sqlalchemy.sql.expression as expr
from beaker.cache import cache_regions, cache_region
+from collections import namedtuple
from datetime import datetime, timedelta
from pyramid.response import Response
from xonstat.models import *
return summary_stats
+@cache_region('hourly_term')
+def get_ranks(game_type_cd):
+ """
+ """
+ # how many ranks we want to fetch
+ leaderboard_count = 10
+
+ # only a few game modes are actually ranked
+ if game_type_cd not in 'duel' 'dm' 'ctf' 'tdm':
+ return None
+
+ ranks = DBSession.query(PlayerRank).\
+ filter(PlayerRank.game_type_cd==game_type_cd).\
+ order_by(PlayerRank.rank).\
+ limit(leaderboard_count).all()
+
+ return ranks
+
def _main_index_data(request):
try:
leaderboard_lifetime = int(
except:
summary_stats = None
- # top ranked duelers
- duel_ranks = DBSession.query(PlayerRank.player_id, PlayerRank.nick,
- PlayerRank.elo).\
- filter(PlayerRank.game_type_cd=='duel').\
- order_by(PlayerRank.rank).\
- limit(leaderboard_count).all()
-
- duel_ranks = [(player_id, html_colors(nick), elo) \
- for (player_id, nick, elo) in duel_ranks]
-
- # top ranked CTF-ers
- ctf_ranks = DBSession.query(PlayerRank.player_id, PlayerRank.nick,
- PlayerRank.elo).\
- filter(PlayerRank.game_type_cd=='ctf').\
- order_by(PlayerRank.rank).\
- limit(leaderboard_count).all()
-
- ctf_ranks = [(player_id, html_colors(nick), elo) \
- for (player_id, nick, elo) in ctf_ranks]
-
- # top ranked DM-ers
- dm_ranks = DBSession.query(PlayerRank.player_id, PlayerRank.nick,
- PlayerRank.elo).\
- filter(PlayerRank.game_type_cd=='dm').\
- order_by(PlayerRank.rank).\
- limit(leaderboard_count).all()
-
- dm_ranks = [(player_id, html_colors(nick), elo) \
- for (player_id, nick, elo) in dm_ranks]
+ # the three top ranks tables
+ ranks = []
+ for gtc in ['duel', 'ctf', 'dm']:
+ rank = get_ranks(gtc)
+ if len(rank) != 0:
+ ranks.append(rank)
right_now = datetime.utcnow()
back_then = datetime.utcnow() - timedelta(days=leaderboard_lifetime)
'top_servers':top_servers,
'top_maps':top_maps,
'recent_games':recent_games,
- 'duel_ranks':duel_ranks,
- 'ctf_ranks':ctf_ranks,
- 'dm_ranks':dm_ranks,
+ 'ranks':ranks,
'summary_stats':summary_stats,
}
leaderboard_count = 10
recent_games_count = 20
- for i in range(leaderboard_count-len(mainindex_data['duel_ranks'])):
- mainindex_data['duel_ranks'].append(('-', '-', '-'))
-
- for i in range(leaderboard_count-len(mainindex_data['ctf_ranks'])):
- mainindex_data['ctf_ranks'].append(('-', '-', '-'))
-
- for i in range(leaderboard_count-len(mainindex_data['dm_ranks'])):
- mainindex_data['dm_ranks'].append(('-', '-', '-'))
-
for i in range(leaderboard_count-len(mainindex_data['top_players'])):
mainindex_data['top_players'].append(('-', '-', '-'))