config.add_view(player_elo_info_json, route_name="player_elo_info_json", renderer="jsonp")
config.add_route("player_accuracy", "/player/{id:\d+}/accuracy")
- config.add_route("player_accuracy_json", "/player/{id:\d+}/accuracy.json")
+ #config.add_route("player_accuracy_json", "/player/{id:\d+}/accuracy.json")
config.add_view(player_accuracy_json, route_name="player_accuracy", renderer="jsonp")
- config.add_view(player_accuracy_json, route_name="player_accuracy_json", renderer="jsonp")
+ #config.add_view(player_accuracy_json, route_name="player_accuracy_json", renderer="jsonp")
config.add_route("player_index", "/players")
config.add_route("player_index_json", "/players.json")
config.add_view(player_index_json, route_name="player_index_json", renderer="jsonp")
config.add_route("player_damage", "/player/{id:\d+}/damage")
- config.add_view(player_damage_json, route_name="player_damage",
- renderer="json")
+ config.add_view(player_damage_json, route_name="player_damage", renderer="jsonp")
+
+ config.add_route("player_captimes", "/player/{id:\d+}/captimes")
+ config.add_route("player_captimes_json", "/player/{id:\d+}/captimes.json")
+ config.add_view(player_captimes, route_name="player_captimes", renderer="player_captimes.mako")
+ config.add_view(player_captimes_json, route_name="player_captimes_json", renderer="jsonp")
# GAME ROUTES
config.add_route("game_index", "/games")
config.add_view(map_info, route_name="map_info", renderer="map_info.mako")
config.add_view(map_info_json, route_name="map_info_json", renderer="jsonp")
+ config.add_route("map_captimes", "/map/{id:\d+}/captimes")
+ config.add_route("map_captimes_json", "/map/{id:\d+}/captimes.json")
+ config.add_view(map_captimes, route_name="map_captimes", renderer="map_captimes.mako")
+ config.add_view(map_captimes_json, route_name="map_captimes_json", renderer="jsonp")
+
# SEARCH ROUTES
config.add_route("search", "search")
config.add_route("search_json", "search.json")
--- /dev/null
+<%inherit file="base.mako"/>
+<%namespace name="nav" file="nav.mako" />
+
+<%block name="title">
+Map captimes
+</%block>
+
+
+<div class="row">
+ <div class="span12">
+
+ <h2>${map.name}</h2>
+ <p><a href="${map_url}">Back to map info page</a></p>
+
+ <h3>Fastest flag capture times:</h3>
+
+ <table class="table table-bordered table-condensed">
+ <thead>
+ <tr>
+ <th>Game</th>
+ <th>Captime</th>
+ <th>Nick</th>
+ <th>Server</th>
+ <th>Date</th>
+ </tr>
+ </thead>
+ <tbody>
+ % for ct in captimes:
+ <tr>
+ <td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=ct.game_id)}" title="View detailed information about this game">view</a></td>
+ <td>${ct.fastest_cap.total_seconds()} seconds</td>
+ <td><span class="nick">${ct.player_nick_html|n}</span></td>
+ <td><a href="${request.route_url('server_info', id=ct.server_id)}" title="Go to the detail page for this server">${ct.server_name}</a></td>
+ <td><span class="abstime" data-epoch="${ct.create_dt_epoch}" title="${ct.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${ct.create_dt_fuzzy}</span></td>
+ % endfor
+ </tbody>
+ </table>
+
+ </div>
+</div>
--- /dev/null
+<%inherit file="base.mako"/>
+<%namespace name="nav" file="nav.mako" />
+
+<%block name="title">
+Player captimes
+</%block>
+
+<div class="row">
+ <div class="span12">
+
+ <h2><span class="nick">${player.nick_html_colors()|n}</span></h2>
+ <p><a href="${player_url}">Back to player info page</a></p>
+
+ <h3>Fastest flag capture times:</h3>
+
+ <table class="table table-bordered table-condensed">
+ <thead>
+ <tr>
+ <th>Game</th>
+ <th>Captime</th>
+ ##<th>Nick</th>
+ <th>Map</th>
+ <th>Server</th>
+ <th>Date</th>
+ </tr>
+ </thead>
+ <tbody>
+ % for ct in captimes:
+ <tr>
+ <td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=ct.game_id)}" title="View detailed information about this game">view</a></td>
+ <td>${ct.fastest_cap.total_seconds()} seconds</td>
+ ##<td><span class="nick">${ct.html_nick|n}</span></td>
+ <td><a href="${request.route_url('map_info', id=ct.map_id)}" title="Go to the detail page for this map">${ct.map_name}</a></td>
+ <td><a href="${request.route_url('server_info', id=ct.server_id)}" title="Go to the detail page for this server">${ct.server_name}</a></td>
+ <td><span class="abstime" data-epoch="${ct.create_dt_epoch}" title="${ct.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${ct.create_dt_fuzzy}</span></td>
+ % endfor
+ </tbody>
+ </table>
+
+ </div>
+</div>
from xonstat.views.player import player_game_index_json, player_accuracy_json
from xonstat.views.player import player_damage_json, player_hashkey_info_json
from xonstat.views.player import player_hashkey_info_text, player_elo_info_json
+from xonstat.views.player import player_captimes, player_captimes_json
from xonstat.views.game import game_index, game_info, rank_index
from xonstat.views.game import game_index_json, game_info_json, rank_index_json
from xonstat.views.map import map_info, map_index
from xonstat.views.map import map_info_json, map_index_json
+from xonstat.views.map import map_captimes, map_captimes_json
from xonstat.views.server import server_info, server_game_index, server_index
from xonstat.views.server import server_info_json, server_game_index_json
def map_index_json(request):
"""
- Provides a JSON-serialized list of all the current maps.
+ Provides a JSON-serialized list of all the current maps.
"""
view_data = _map_index_data(request)
def _map_info_data(request):
map_id = request.matchdict['id']
- try:
+ try:
leaderboard_lifetime = int(
request.registry.settings['xonstat.leaderboard_lifetime'])
except:
filter(Game.game_id == PlayerGameStat.game_id).\
filter(Game.map_id == map_id).\
filter(Player.player_id > 2).\
- filter(PlayerGameStat.create_dt >
+ filter(PlayerGameStat.create_dt >
(datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\
order_by(expr.desc(func.sum(PlayerGameStat.score))).\
group_by(Player.nick).\
for (player_id, nick, score) in top_scorers]
# top players by playing time
- top_players = DBSession.query(Player.player_id, Player.nick,
+ top_players = DBSession.query(Player.player_id, Player.nick,
func.sum(PlayerGameStat.alivetime)).\
filter(Player.player_id == PlayerGameStat.player_id).\
filter(Game.game_id == PlayerGameStat.game_id).\
filter(Game.map_id == map_id).\
filter(Player.player_id > 2).\
- filter(PlayerGameStat.create_dt >
+ filter(PlayerGameStat.create_dt >
(datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\
order_by(expr.desc(func.sum(PlayerGameStat.alivetime))).\
group_by(Player.nick).\
for (player_id, nick, score) in top_players]
# top servers using/playing this map
- top_servers = DBSession.query(Server.server_id, Server.name,
+ top_servers = DBSession.query(Server.server_id, Server.name,
func.count(Game.game_id)).\
filter(Game.server_id == Server.server_id).\
filter(Game.map_id == map_id).\
- filter(Game.create_dt >
+ filter(Game.create_dt >
(datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\
order_by(expr.desc(func.count(Game.game_id))).\
group_by(Server.name).\
List the information stored about a given map. JSON.
"""
return [{'status':'not implemented'}]
+
+
+def map_captimes_data(request):
+ map_id = int(request.matchdict['id'])
+
+ MapCaptimes = namedtuple('PlayerCaptimes', ['fastest_cap', 'create_dt', 'create_dt_epoch', 'create_dt_fuzzy',
+ 'player_id', 'player_nick', 'player_nick_stripped', 'player_nick_html',
+ 'game_id', 'server_id', 'server_name'])
+
+ dbquery = DBSession.query('fastest_cap', 'create_dt', 'player_id', 'game_id',
+ 'server_id', 'server_name', 'player_nick').\
+ from_statement(
+ "SELECT ct.fastest_cap, "
+ "ct.create_dt, "
+ "ct.player_id, "
+ "ct.game_id, "
+ "g.server_id, "
+ "s.name server_name, "
+ "pgs.nick player_nick "
+ "FROM player_map_captimes ct, "
+ "games g, "
+ "maps m, "
+ "servers s, "
+ "player_game_stats pgs "
+ "WHERE ct.map_id = :map_id "
+ "AND g.game_id = ct.game_id "
+ "AND g.server_id = s.server_id "
+ "AND m.map_id = ct.map_id "
+ "AND pgs.player_id = ct.player_id "
+ "AND pgs.game_id = ct.game_id "
+ "ORDER BY ct.fastest_cap "
+ ).params(map_id=map_id).all()
+
+ mmap = DBSession.query(Map).filter_by(map_id=map_id).one()
+
+ map_captimes = []
+ for row in dbquery:
+ map_captimes.append(MapCaptimes(
+ fastest_cap=row.fastest_cap,
+ create_dt=row.create_dt,
+ create_dt_epoch=timegm(row.create_dt.timetuple()),
+ create_dt_fuzzy=pretty_date(row.create_dt),
+ player_id=row.player_id,
+ player_nick=row.player_nick,
+ player_nick_stripped=strip_colors(row.player_nick),
+ player_nick_html=html_colors(row.player_nick),
+ game_id=row.game_id,
+ server_id=row.server_id,
+ server_name=row.server_name,
+ ))
+
+ return {
+ 'captimes':map_captimes,
+ 'map_id':map_id,
+ 'map_url':request.route_url('map_info', id=map_id),
+ 'map':mmap,
+ }
+
+def map_captimes(request):
+ return map_captimes_data(request)
+
+def map_captimes_json(request):
+ return map_captimes_data(request)
from sqlalchemy import desc, distinct
from webhelpers.paginate import Page, PageURL
from xonstat.models import *
-from xonstat.util import page_url, to_json, pretty_date, datetime_seconds
+from xonstat.util import page_url, to_json, pretty_date, datetime_seconds, html_colors
from xonstat.views.helpers import RecentGame, recent_games_q
log = logging.getLogger(__name__)
map_id=row.map_id,
times_played=row.times_played,
game_type_cd=row.game_type_cd)
-
+
# if we aren't given a favorite game_type_cd
# then the overall favorite is the one we've
# played the most
The key to the dictionary is the game type code. There is also an
"overall" game_type_cd which is the overall best rank.
- """
+ """
Rank = namedtuple('Rank', ['rank', 'max_rank', 'percentile', 'game_type_cd'])
raw_ranks = DBSession.query("game_type_cd", "rank", "max_rank").\
# Determine the raw accuracy (hit, fired) numbers for $games games
# This is then enumerated to create parameters for a flot graph
- raw_accs = DBSession.query(PlayerWeaponStat.game_id,
+ raw_accs = DBSession.query(PlayerWeaponStat.game_id,
PlayerWeaponStat.hit, PlayerWeaponStat.fired).\
filter(PlayerWeaponStat.player_id == player_id).\
filter(PlayerWeaponStat.weapon_cd == weapon_cd).\
# Determine the damage efficiency (hit, fired) numbers for $games games
# This is then enumerated to create parameters for a flot graph
- raw_dmgs = DBSession.query(PlayerWeaponStat.game_id,
+ raw_dmgs = DBSession.query(PlayerWeaponStat.game_id,
PlayerWeaponStat.actual, PlayerWeaponStat.hit).\
filter(PlayerWeaponStat.player_id == player_id).\
filter(PlayerWeaponStat.weapon_cd == weapon_cd).\
"""
# All player_info fields are converted into JSON-formattable dictionaries
- player_info = player_info_data(request)
+ player_info = player_info_data(request)
player = player_info['player'].to_dict()
games = len(accs)
return {
- 'player_id':player_id,
- 'player_url':request.route_url('player_info', id=player_id),
- 'weapon':weapon_cd,
- 'games':games,
- 'avg':avg,
+ 'player_id':player_id,
+ 'player_url':request.route_url('player_info', id=player_id),
+ 'weapon':weapon_cd,
+ 'games':games,
+ 'avg':avg,
'accs':accs
}
games = len(dmgs)
return {
- 'player_id':player_id,
- 'player_url':request.route_url('player_info', id=player_id),
- 'weapon':weapon_cd,
- 'games':games,
- 'avg':avg,
+ 'player_id':player_id,
+ 'player_url':request.route_url('player_info', id=player_id),
+ 'weapon':weapon_cd,
+ 'games':games,
+ 'avg':avg,
'dmgs':dmgs
}
'version': 1,
'elos': elos,
}]
+
+def player_captimes_data(request):
+ player_id = int(request.matchdict['id'])
+ if player_id <= 2:
+ player_id = -1;
+
+ #player_captimes = DBSession.query(PlayerCaptime).\
+ # filter(PlayerCaptime.player_id==player_id).\
+ # order_by(PlayerCaptime.fastest_cap).\
+ # all()
+
+ PlayerCaptimes = namedtuple('PlayerCaptimes', ['fastest_cap', 'create_dt', 'create_dt_epoch', 'create_dt_fuzzy',
+ 'player_id', 'game_id', 'map_id', 'map_name', 'server_id', 'server_name'])
+
+ dbquery = DBSession.query('fastest_cap', 'create_dt', 'player_id', 'game_id', 'map_id',
+ 'map_name', 'server_id', 'server_name').\
+ from_statement(
+ "SELECT ct.fastest_cap, "
+ "ct.create_dt, "
+ "ct.player_id, "
+ "ct.game_id, "
+ "ct.map_id, "
+ "m.name map_name, "
+ "g.server_id, "
+ "s.name server_name "
+ "FROM player_map_captimes ct, "
+ "games g, "
+ "maps m, "
+ "servers s "
+ "WHERE ct.player_id = :player_id "
+ "AND g.game_id = ct.game_id "
+ "AND g.server_id = s.server_id "
+ "AND m.map_id = ct.map_id "
+ #"ORDER BY ct.fastest_cap "
+ "ORDER BY ct.create_dt desc"
+ ).params(player_id=player_id).all()
+
+ player = DBSession.query(Player).filter_by(player_id=player_id).one()
+
+ player_captimes = []
+ for row in dbquery:
+ player_captimes.append(PlayerCaptimes(
+ fastest_cap=row.fastest_cap,
+ create_dt=row.create_dt,
+ create_dt_epoch=timegm(row.create_dt.timetuple()),
+ create_dt_fuzzy=pretty_date(row.create_dt),
+ player_id=row.player_id,
+ game_id=row.game_id,
+ map_id=row.map_id,
+ map_name=row.map_name,
+ server_id=row.server_id,
+ server_name=row.server_name,
+ ))
+
+ return {
+ 'captimes':player_captimes,
+ 'player_id':player_id,
+ 'player_url':request.route_url('player_info', id=player_id),
+ 'player':player,
+ }
+
+def player_captimes(request):
+ return player_captimes_data(request)
+
+def player_captimes_json(request):
+ return player_captimes_data(request)