Fix merge conflict, change indentation a bit.
authorAnt Zucaro <azucaro@gmail.com>
Sat, 16 Jun 2012 15:41:48 +0000 (11:41 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Sat, 16 Jun 2012 15:41:48 +0000 (11:41 -0400)
XonStat.egg-info/requires.txt
xonstat/__init__.py
xonstat/models.py
xonstat/views/__init__.py
xonstat/views/game.py
xonstat/views/main.py
xonstat/views/map.py
xonstat/views/player.py
xonstat/views/search.py
xonstat/views/server.py

index 2950c076dd8a670e8470f2433144ab9f37ce02b4..fdef49787cd86fbe8c62a989ff1d795eab1552b6 100644 (file)
@@ -1,4 +1,4 @@
-pyramid
+pyramid>=1.1
 SQLAlchemy
 transaction
 repoze.tm2>=1.0b1
index 3160b7583c2cba36fd2ab88e5b4168ddd952d36d..e7bfba387aeb46b69998a113cf85ded34a0c93a3 100644 (file)
@@ -1,5 +1,6 @@
 import sqlahelper
 from pyramid.config import Configurator
+from pyramid.renderers import JSONP
 from sqlalchemy import engine_from_config
 from xonstat.models import initialize_db
 from xonstat.views import *
@@ -18,6 +19,8 @@ def main(global_config, **settings):
 
     config.add_static_view('static', 'xonstat:static')
 
+    config.add_renderer('jsonp', JSONP(param_name='callback'))
+
     # ROOT ROUTE
     config.add_route("main_index", "/")
     config.add_view(main_index, route_name="main_index", renderer="main_index.mako")
@@ -27,55 +30,77 @@ def main(global_config, **settings):
     config.add_view(stats_submit, route_name="stats_submit")
 
     # PLAYER ROUTES
-    config.add_route("player_game_index", "/player/{player_id:\d+}/games")
-    config.add_view(player_game_index, route_name="player_game_index", renderer="player_game_index.mako")
-
-    config.add_route("player_index", "/players")
-    config.add_view(player_index, route_name="player_index", renderer="player_index.mako")
+    config.add_route("player_game_index",      "/player/{player_id:\d+}/games")
+    config.add_route("player_game_index_json", "/player/{player_id:\d+}/games.json")
+    config.add_view(player_game_index,      route_name="player_game_index",      renderer="player_game_index.mako")
+    config.add_view(player_game_index_json, route_name="player_game_index_json", renderer="jsonp")
 
-    config.add_route("player_info", "/player/{id:\d+}")
-    config.add_view(player_info, route_name="player_info", renderer="player_info.mako")
+    config.add_route("player_info",      "/player/{id:\d+}")
+    config.add_route("player_info_json", "/player/{id:\d+}.json")
+    config.add_view(player_info,      route_name="player_info",      renderer="player_info.mako")
+    config.add_view(player_info_json, route_name="player_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_view(player_accuracy_json, route_name="player_accuracy",      renderer="json")
-    config.add_view(player_accuracy_json, route_name="player_accuracy_json", renderer="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_route("player_index",      "/players")
+    config.add_route("player_index_json", "/players.json")
+    config.add_view(player_index,      route_name="player_index",      renderer="player_index.mako")
+    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")
 
     # GAME ROUTES
-    config.add_route("game_index", "/games")
-    config.add_view(game_index, route_name="game_index", renderer="game_index.mako")
+    config.add_route("game_index",      "/games")
+    config.add_route("game_index_json", "/games.json")
+    config.add_view(game_index,      route_name="game_index",      renderer="game_index.mako")
+    config.add_view(game_index_json, route_name="game_index_json", renderer="jsonp")
 
-    config.add_route("game_info", "/game/{id:\d+}")
-    config.add_view(game_info, route_name="game_info", renderer="game_info.mako")
+    config.add_route("game_info",      "/game/{id:\d+}")
+    config.add_route("game_info_json", "/game/{id:\d+}.json")
+    config.add_view(game_info,      route_name="game_info",      renderer="game_info.mako")
+    config.add_view(game_info_json, route_name="game_info_json", renderer="jsonp")
 
-    config.add_route("rank_index", "/ranks/{game_type_cd:ctf|dm|tdm|duel}")
-    config.add_view(rank_index, route_name="rank_index", renderer="rank_index.mako")
+    config.add_route("rank_index",      "/ranks/{game_type_cd:ctf|dm|tdm|duel}")
+    config.add_route("rank_index_json", "/ranks/{game_type_cd:ctf|dm|tdm|duel}.json")
+    config.add_view(rank_index,      route_name="rank_index",      renderer="rank_index.mako")
+    config.add_view(rank_index_json, route_name="rank_index_json", renderer="jsonp")
 
     # SERVER ROUTES
-    config.add_route("server_index", "/servers")
-    config.add_view(server_index, route_name="server_index", renderer="server_index.mako")
+    config.add_route("server_index",      "/servers")
+    config.add_route("server_index_json", "/servers.json")
+    config.add_view(server_index,      route_name="server_index",      renderer="server_index.mako")
+    config.add_view(server_index_json, route_name="server_index_json", renderer="jsonp")
 
-    config.add_route("server_game_index", "/server/{server_id:\d+}/games/page/{page:\d+}")
-    config.add_view(server_game_index, route_name="server_game_index", renderer="server_game_index.mako")
+    config.add_route("server_game_index",      "/server/{server_id:\d+}/games/page/{page:\d+}")
+    config.add_route("server_game_index_json", "/server/{server_id:\d+}/games.json")
+    config.add_view(server_game_index,      route_name="server_game_index",      renderer="server_game_index.mako")
+    config.add_view(server_game_index_json, route_name="server_game_index_json", renderer="jsonp")
 
-    config.add_route("server_info", "/server/{id:\d+}")
-    config.add_view(server_info, route_name="server_info", renderer="server_info.mako")
+    config.add_route("server_info",      "/server/{id:\d+}")
+    config.add_route("server_info_json", "/server/{id:\d+}.json")
+    config.add_view(server_info,      route_name="server_info",      renderer="server_info.mako")
+    config.add_view(server_info_json, route_name="server_info_json", renderer="jsonp")
 
     # MAP ROUTES
     config.add_route("map_index",      "/maps")
     config.add_route("map_index_json", "/maps.json")
     config.add_view(map_index,      route_name="map_index",      renderer="map_index.mako")
-    config.add_view(map_index_json, route_name="map_index_json", renderer="json")
+    config.add_view(map_index_json, route_name="map_index_json", renderer="jsonp")
 
-    config.add_route("map_info", "/map/{id:\d+}")
-    config.add_view(map_info, route_name="map_info", renderer="map_info.mako")
+    config.add_route("map_info",      "/map/{id:\d+}")
+    config.add_route("map_info_json", "/map/{id:\d+}.json")
+    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")
 
     # SEARCH ROUTES
-    config.add_route("search", "search")
-    config.add_view(search, route_name="search", renderer="search.mako")
+    config.add_route("search",      "search")
+    config.add_route("search_json", "search.json")
+    config.add_view(search,      route_name="search",      renderer="search.mako")
+    config.add_view(search_json, route_name="search_json", renderer="jsonp")
 
     return config.make_wsgi_app()
index 949f90cd9607fea4a6cd05baf86a4f6dd959ca03..39c65868fc0e92b62c0fa34d80c404d18af2244f 100644 (file)
@@ -36,16 +36,25 @@ class Player(object):
     def __repr__(self):
         return "<Player(%s, %s)>" % (self.player_id, self.nick.encode('utf-8'))
 
+    def to_dict(self):
+        return {'player_id':self.player_id, 'name':self.nick.encode('utf-8')}
+
 
 class GameType(object):
     def __repr__(self):
         return "<GameType(%s, %s, %s)>" % (self.game_type_cd, self.descr, self.active_ind)
 
+    def to_dict(self):
+        return {'game_type_cd':self.game_type_cd, 'name':self.descr, 'active':self.active_ind}
+
 
 class Weapon(object):
     def __repr__(self):
         return "<Weapon(%s, %s, %s)>" % (self.weapon_cd, self.descr, self.active_ind)
 
+    def to_dict(self):
+        return {'weapon_cd':self.weapon_cd, 'name':self.descr, 'active':self.active_ind}
+
 
 class Server(object):
     def __init__(self, name=None, hashkey=None, ip_addr=None):
@@ -56,6 +65,9 @@ class Server(object):
     def __repr__(self):
         return "<Server(%s, %s)>" % (self.server_id, self.name.encode('utf-8'))
 
+    def to_dict(self):
+        return {'server_id':self.server_id, 'name':self.name.encode('utf-8')}
+
 
 class Map(object):
     def __init__(self, name=None):
@@ -65,7 +77,7 @@ class Map(object):
         return "<Map(%s, %s, %s)>" % (self.map_id, self.name, self.version)
 
     def to_dict(self):
-        return {'map_id':self.map_id, 'name':self.name}
+        return {'map_id':self.map_id, 'name':self.name, 'version':self.version}
 
 
 class Game(object):
@@ -81,6 +93,9 @@ class Game(object):
     def __repr__(self):
         return "<Game(%s, %s, %s, %s)>" % (self.game_id, self.start_dt, self.game_type_cd, self.server_id)
 
+    def to_dict(self):
+        return {'game_id':self.game_id, 'start':self.start_dt.strftime('%Y-%m-%dT%H:%M:%SZ'), 'game_type_cd':self.game_type_cd, 'server_id':self.server_id}
+
     def fuzzy_date(self):
         return pretty_date(self.start_dt)
 
@@ -199,6 +214,9 @@ class PlayerGameStat(object):
     def __repr__(self):
         return "<PlayerGameStat(%s, %s, %s)>" % (self.player_id, self.game_id, self.create_dt)
 
+    def to_dict(self):
+        return {'player_id':self.player_id, 'game_id':self.game_id, 'create_dt':self.create_dt.strftime('%Y-%m-%dT%H:%M:%SZ')}
+
     def nick_stripped(self):
         if self.nick is None:
             return "Anonymous Player"
@@ -228,16 +246,25 @@ class Achievement(object):
     def __repr__(self):
         return "<Achievement(%s, %s, %s)>" % (self.achievement_cd, self.descr, self.limit)
 
+    def to_dict(self):
+        return {'achievement_cd':self.achievement_cd, 'name':self.descr, 'limit':self.limit}
+
 
 class PlayerAchievement(object):
     def __repr__(self):
         return "<PlayerAchievement(%s, %s)>" % (self.player_id, self.achievement_cd)
 
+    def to_dict(self):
+        return {'player_id':self.player_id, 'achievement_cd':self.achievement_cd}
+
 
 class PlayerWeaponStat(object):
     def __repr__(self):
         return "<PlayerWeaponStat(%s, %s, %s)>" % (self.player_weapon_stats_id, self.player_id, self.game_id)
 
+    def to_dict(self):
+        return {'player_weapon_stats_id':self.player_weapon_stats_id, 'player_id':self.player_id, 'game_id':self.game_id}
+
 
 class Hashkey(object):
     def __init__(self, player_id=None, hashkey=None):
@@ -247,11 +274,17 @@ class Hashkey(object):
     def __repr__(self):
         return "<Hashkey(%s, %s)>" % (self.player_id, self.hashkey)
 
+    def to_dict(self):
+        return {'player_id':self.player_id, 'hashkey':self.hashkey}
+
 
 class PlayerNick(object):
     def __repr__(self):
         return "<PlayerNick(%s, %s)>" % (self.player_id, self.stripped_nick)
 
+    def to_dict(self):
+        return {'player_id':self.player_id, 'name':self.stripped_nick}
+
 
 class PlayerElo(object):
     def __init__(self, player_id=None, game_type_cd=None):
@@ -265,6 +298,9 @@ class PlayerElo(object):
     def __repr__(self):
         return "<PlayerElo(pid=%s, gametype=%s, elo=%s)>" % (self.player_id, self.game_type_cd, self.elo)
 
+    def to_dict(self):
+        return {'player_id':self.player_id, 'game_type_cd':self.game_type_cd, 'elo':self.elo}
+
 
 class PlayerRank(object):
 
@@ -274,10 +310,12 @@ class PlayerRank(object):
         else:
             return html_colors(self.nick)
 
-
     def __repr__(self):
         return "<PlayerRank(pid=%s, gametype=%s, rank=%s)>" % (self.player_id, self.game_type_cd, self.rank)
 
+    def to_dict(self):
+        return {'player_id':self.player_id, 'game_type_cd':self.game_type_cd, 'rank':self.rank}
+
 
 def initialize_db(engine=None):
     DBSession.configure(bind=engine)
index 525d2f9d353357a1edf22b543962e4aa33866c07..f42c7855ec5b245ac92788e67ea27a994d410d18 100644 (file)
@@ -1,8 +1,21 @@
 from xonstat.views.submission import stats_submit
 from xonstat.views.player import player_index, player_info, player_game_index
-from xonstat.views.player import player_accuracy_json, player_damage_json
-from xonstat.views.game import game_index, game_info, rank_index
-from xonstat.views.map import map_info, map_index, map_index_json
+from xonstat.views.player import player_accuracy
+from xonstat.views.player import player_index_json, player_info_json,
+from xonstat.views.player import player_game_index_json, player_accuracy_json
+from xonstat.views.player import player_damage_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.server import server_info, server_game_index, server_index
+from xonstat.views.server import server_info_json, server_game_index_json
+from xonstat.views.server import server_index_json
+
 from xonstat.views.search import search_q, search
-from xonstat.views.main import main_index
+from xonstat.views.search import search_json
+
+from xonstat.views.main   import main_index
index 70bbd58c862325959f10761ac359fea1a76e95f2..6147c5fed1d44d9b4bac3b16c4e9124e1503dbcb 100644 (file)
@@ -31,7 +31,7 @@ def _game_index_data(request):
                 order_by(PlayerGameStat.rank).\
                 order_by(PlayerGameStat.score).all()
 
-    return {'games':games, 
+    return {'games':games,
             'pgstats':pgstats}
 
 
@@ -44,6 +44,15 @@ def game_index(request):
     return _game_index_data(request)
 
 
+def game_index_json(request):
+    """
+    Provides a list of current games, with the associated game stats.
+    These games are ordered by game_id, with the most current ones first.
+    Paginated. JSON.
+    """
+    return [{'status':'not implemented'}]
+
+
 def _game_info_data(request):
     game_id = request.matchdict['id']
     try:
@@ -103,6 +112,13 @@ def game_info(request):
     return _game_info_data(request)
 
 
+def game_info_json(request):
+    """
+    List the game stats (scoreboard) for a particular game. Paginated. JSON.
+    """
+    return [{'status':'not implemented'}]
+
+
 def _rank_index_data(request):
     if request.params.has_key('page'):
         current_page = request.params['page']
@@ -131,3 +147,10 @@ def rank_index(request):
     Provide a list of gametype ranks, paginated.
     """
     return _rank_index_data(request)
+
+
+def rank_index_json(request):
+    """
+    Provide a list of gametype ranks, paginated. JSON.
+    """
+    return [{'status':'not implemented'}]
index 5a8bad4be70aead377dbf2d384af734b831fb4e1..05496e93913e6669fc4f5b4493da576669628dbc 100644 (file)
@@ -133,3 +133,10 @@ def main_index(request):
         mainindex_data['recent_games'].append(('-', '-', '-', '-'))
 
     return mainindex_data
+
+
+def main_index_json(request):
+    """
+    JSON output of the main page information.
+    """
+    return [{'status':'not implemented'}]
index df641222c1680a3e265984efaa76a100021acfcc..a74a220644f6b7b39c1a4b50722b531e7536b835 100644 (file)
@@ -30,7 +30,7 @@ def _map_index_data(request):
 
 def map_index(request):
     """
-    Provides a list of all the current maps. 
+    Provides a list of all the current maps.
     """
     return _map_index_data(request)
 
@@ -39,7 +39,7 @@ def map_index_json(request):
     """
     Provides a JSON-serialized list of all the current maps. 
     """
-    view_data =  _map_index_data(request)
+    view_data = _map_index_data(request)
 
     maps = [m.to_dict() for m in view_data['maps']]
 
@@ -146,3 +146,10 @@ def map_info(request):
         mapinfo_data['top_servers'].append(('-', '-', '-'))
 
     return mapinfo_data
+
+
+def map_info_json(request):
+    """
+    List the information stored about a given map. JSON.
+    """
+    return [{'status':'not implemented'}]
index 9a5457a3074d6667248d9de3bb6e0522213b1db9..d2112515ed82ff1cc911a2b993667d9976fbef69 100644 (file)
@@ -45,6 +45,13 @@ def player_index(request):
     return _player_index_data(request)
 
 
+def player_index_json(request):
+    """
+    Provides a list of all the current players. JSON.
+    """
+    return [{'status':'not implemented'}]
+
+
 def _get_games_played(player_id):
     """
     Provides a breakdown by gametype of the games played by player_id.
@@ -266,6 +273,13 @@ def player_info(request):
     return _player_info_data(request)
 
 
+def player_info_json(request):
+    """
+    Provides detailed information on a specific player. JSON.
+    """
+    return [{'status':'not implemented'}]
+
+
 def _player_game_index_data(request):
     player_id = request.matchdict['player_id']
 
@@ -309,6 +323,15 @@ def player_game_index(request):
     return _player_game_index_data(request)
 
 
+def player_game_index_json(request):
+    """
+    Provides an index of the games in which a particular
+    player was involved. This is ordered by game_id, with
+    the most recent game_ids first. Paginated. JSON.
+    """
+    return [{'status':'not implemented'}]
+
+
 def _player_accuracy_data(request):
     player_id = request.matchdict['id']
     allowed_weapons = ['nex', 'rifle', 'shotgun', 'uzi', 'minstanex']
@@ -346,6 +369,13 @@ def _player_accuracy_data(request):
             }
 
 
+def player_accuracy(request):
+    """
+    Provides the accuracy for the given weapon. (JSON only)
+    """
+    return _player_accuracy_data(request)
+
+
 def player_accuracy_json(request):
     """
     Provides a JSON response representing the accuracy for the given weapon.
index 2a791f331004b81131e302ab7b704a5a626ac03f..13700b6ebfe95cb59218a00b50eb2585573a9327 100644 (file)
@@ -149,3 +149,7 @@ def _search_data(request):
 
 def search(request):
     return _search_data(request)
+
+
+def search_json(request):
+    return [{'status':'not implemented'}]
index 93e5fecc49b3300756c8b84a848a0f3c2b69166d..b2d7c6df442b7cbdd7fb5b3c0294b00c38dc9aa3 100644 (file)
@@ -37,6 +37,13 @@ def server_index(request):
     return _server_index_data(request)
 
 
+def server_index_json(request):
+    """
+    Provides a list of all the current servers. JSON.
+    """
+    return [{'status':'not implemented'}]
+
+
 def _server_info_data(request):
     server_id = request.matchdict['id']
 
@@ -142,6 +149,13 @@ def server_info(request):
     return serverinfo_data
 
 
+def server_info_json(request):
+    """
+    List the stored information about a given server. JSON.
+    """
+    return [{'status':'not implemented'}]
+
+
 def _server_game_index_data(request):
     server_id = request.matchdict['server_id']
     current_page = request.matchdict['page']
@@ -170,3 +184,10 @@ def server_game_index(request):
     List the games played on a given server. Paginated.
     """
     return _server_game_index_data(request)
+
+
+def server_game_index_json(request):
+    """
+    List the games played on a given server. Paginated. JSON.
+    """
+    return [{'status':'not implemented'}]