Add HTML views for top active players, scoring players, and maps played.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 23 Oct 2016 13:24:34 +0000 (09:24 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 23 Oct 2016 13:24:34 +0000 (09:24 -0400)
xonstat/__init__.py
xonstat/templates/server_top_maps.mako [new file with mode: 0644]
xonstat/templates/server_top_players_index.mako [new file with mode: 0644]
xonstat/templates/server_top_scorers.mako [new file with mode: 0644]
xonstat/views/server.py

index 4071dd5..3f9a43d 100644 (file)
@@ -141,14 +141,20 @@ def main(global_config, **settings):
                     accept="text/json")
 
     config.add_route("server_top_maps", "/server/{id:\d+}/topmaps")
+    config.add_view(view=ServerTopMaps, route_name="server_top_maps", attr="html",
+                    renderer="server_top_maps.mako", accept="text/html")
     config.add_view(view=ServerTopMaps, route_name="server_top_maps", attr="json", renderer="json",
                     accept="text/json")
 
-    config.add_route("server_top_players", "/server/{id:\d+}/topplayers")
+    config.add_route("server_top_players", "/server/{id:\d+}/topactive")
+    config.add_view(view=ServerTopPlayers, route_name="server_top_players", attr="html",
+                    renderer="server_top_players_index.mako", accept="text/html")
     config.add_view(view=ServerTopPlayers, route_name="server_top_players", attr="json",
                     renderer="json", accept="text/json")
 
     config.add_route("server_top_scorers", "/server/{id:\d+}/topscorers")
+    config.add_view(view=ServerTopScorers, route_name="server_top_scorers", attr="html",
+                    renderer="server_top_scorers.mako", accept="text/html")
     config.add_view(view=ServerTopScorers, route_name="server_top_scorers", attr="json",
                     renderer="json", accept="text/json")
 
diff --git a/xonstat/templates/server_top_maps.mako b/xonstat/templates/server_top_maps.mako
new file mode 100644 (file)
index 0000000..9fdfe14
--- /dev/null
@@ -0,0 +1,55 @@
+<%inherit file="base.mako"/>
+<%namespace name="nav" file="nav.mako" />
+
+<%block name="navigation">
+  ${nav.nav('servers')}
+</%block>
+
+<%block name="title">
+  Server Top Map Index
+</%block>
+
+% if not top_maps and last is not None:
+  <h2 class="text-center">Sorry, no more maps!</h2>
+
+% elif not top_maps and last is None:
+  <h2 class="text-center">No maps found. Yikes, get playing!</h2>
+
+% else:
+  <div class="row">
+    <div class="small-12 large-6 large-offset-3 columns">
+      <table class="table-hover table-condensed">
+        <thead>
+          <tr>
+            <th class="small-2">#</th>
+            <th class="small-7">Map</th>
+            <th class="small-3">Times Played</th>
+          </tr>
+        </thead>
+        <tbody>
+        % for tm in top_maps:
+          <tr>
+            <td>${tm.rank}</td>
+            <td class="no-stretch"><a href="${request.route_url('map_info', id=tm.map_id)}" title="Go to the map info page for this map">${tm.name|n}</a></td>
+            <td>${tm.times_played}</td>
+          </tr>
+        % endfor
+        </tbody>
+      </table>
+      <p class="text-center"><small>Note: these figures are from the past 7 days</small>
+    </div>
+  </div>
+
+  % if len(top_maps) == 20:
+    <div class="row">
+      <div class="small-12 large-6 large-offset-3 columns">
+        <ul class="pagination">
+          <li>
+            <a  href="${request.route_url('server_top_maps', id=server_id, _query=query)}" name="Next Page">Next <i class="fa fa-arrow-right"></i></a>
+          </li>
+        </ul>
+      </div>
+    </div>
+  % endif
+
+% endif
diff --git a/xonstat/templates/server_top_players_index.mako b/xonstat/templates/server_top_players_index.mako
new file mode 100644 (file)
index 0000000..3bba6d5
--- /dev/null
@@ -0,0 +1,57 @@
+<%inherit file="base.mako"/>
+<%namespace name="nav" file="nav.mako" />
+
+<%block name="navigation">
+  ${nav.nav('servers')}
+</%block>
+
+<%block name="title">
+  Server Active Players Index
+</%block>
+
+% if not top_players and start is not None:
+  <h2 class="text-center">Sorry, no more active players!</h2>
+
+% elif not top_players and start is None:
+  <h2 class="text-center">No active players found. Yikes, get playing!</h2>
+
+% else:
+  ##### ACTIVE PLAYERS #####
+  <div class="row">
+    <div class="small-12 large-6 large-offset-3 columns">
+      <table class="table-hover table-condensed">
+        <thead>
+          <tr>
+            <th class="small-2">#</th>
+            <th class="small-7">Nick</th>
+            <th class="small-3">Play Time</th>
+          </tr>
+        </thead>
+
+        <tbody>
+        % for tp in top_players:
+          <tr>
+            <td>${tp.rank}</td>
+            <td class="no-stretch"><a href="${request.route_url('player_info', id=tp.player_id)}" title="Go to the player info page for this player">${tp.nick|n}</a></td>
+            <td>${tp.alivetime}</td>
+          </tr>
+        % endfor
+        </tbody>
+      </table>
+      <p class="text-center"><small>Note: these figures are from the past 7 days</small>
+    </div>
+  </div>
+
+  % if len(top_players) == 20:
+    <div class="row">
+      <div class="small-12 large-6 large-offset-3 columns">
+        <ul class="pagination">
+          <li>
+            <a  href="${request.route_url('server_top_players', id=server_id, _query=query)}" name="Next Page">Next <i class="fa fa-arrow-right"></i></a>
+          </li>
+        </ul>
+      </div>
+    </div>
+  % endif
+
+% endif
diff --git a/xonstat/templates/server_top_scorers.mako b/xonstat/templates/server_top_scorers.mako
new file mode 100644 (file)
index 0000000..ade10d5
--- /dev/null
@@ -0,0 +1,55 @@
+<%inherit file="base.mako"/>
+<%namespace name="nav" file="nav.mako" />
+
+<%block name="navigation">
+  ${nav.nav('servers')}
+</%block>
+
+<%block name="title">
+  Server Top Scorer Index
+</%block>
+
+% if not top_scorers and last is not None:
+  <h2 class="text-center">Sorry, no more players!</h2>
+
+% elif not top_scorers and last is None:
+  <h2 class="text-center">No players found. Yikes, get playing!</h2>
+
+% else:
+  <div class="row">
+    <div class="small-12 large-6 large-offset-3 columns">
+      <table class="table-hover table-condensed">
+        <thead>
+          <tr>
+            <th class="small-2">#</th>
+            <th class="small-7">Nick</th>
+            <th class="small-3">Score</th>
+          </tr>
+        </thead>
+        <tbody>
+        % for ts in top_scorers:
+          <tr>
+            <td>${ts.rank}</td>
+            <td class="no-stretch"><a href="${request.route_url('player_info', id=ts.player_id)}" title="Go to the player info page for this player">${ts.nick|n}</a></td>
+            <td>${ts.total_score}</td>
+          </tr>
+        % endfor
+        </tbody>
+      </table>
+      <p class="text-center"><small>Note: these figures are from the past 7 days</small>
+    </div>
+  </div>
+
+  % if len(top_scorers) == 20:
+    <div class="row">
+      <div class="small-12 large-6 large-offset-3 columns">
+        <ul class="pagination">
+          <li>
+            <a  href="${request.route_url('server_top_scorers', id=server_id, _query=query)}" name="Next Page">Next <i class="fa fa-arrow-right"></i></a>
+          </li>
+        </ul>
+      </div>
+    </div>
+  % endif
+
+% endif
index 1b5dc9b..f65cd13 100644 (file)
@@ -16,6 +16,7 @@ log = logging.getLogger(__name__)
 # Defaults
 LEADERBOARD_LIFETIME = 30
 LEADERBOARD_COUNT = 10
+INDEX_COUNT = 20
 RECENT_GAMES_COUNT = 20
 
 
@@ -72,7 +73,7 @@ class ServerInfoBase(object):
 class ServerTopMaps(ServerInfoBase):
     """Returns the top maps played on a given server."""
 
-    def __init__(self, request, limit=LEADERBOARD_COUNT, last=None):
+    def __init__(self, request, limit=INDEX_COUNT, last=None):
         """Common parameter parsing."""
         super(ServerTopMaps, self).__init__(request, limit, last)
 
@@ -106,7 +107,17 @@ class ServerTopMaps(ServerInfoBase):
 
     def html(self):
         """Returns the HTML-ready representation."""
-        return self.top_maps
+
+        # build the query string
+        query = {}
+        if len(self.top_maps) > 1:
+            query['last'] = self.top_maps[-1].rank
+
+        return {
+            "server_id": self.server_id,
+            "top_maps": self.top_maps,
+            "query": query,
+        }
 
     def json(self):
         """For rendering this data using JSON."""
@@ -123,7 +134,7 @@ class ServerTopMaps(ServerInfoBase):
 class ServerTopScorers(ServerInfoBase):
     """Returns the top scorers on a given server."""
 
-    def __init__(self, request, limit=LEADERBOARD_COUNT, last=None):
+    def __init__(self, request, limit=INDEX_COUNT, last=None):
         """Common parameter parsing."""
         super(ServerTopScorers, self).__init__(request, limit, last)
         self.top_scorers = self.raw()
@@ -166,7 +177,17 @@ class ServerTopScorers(ServerInfoBase):
 
         top_scorers = [TopScorer(ts.rank, ts.player_id, html_colors(ts.nick), ts.total_score)
                        for ts in self.top_scorers]
-        return top_scorers
+
+        # build the query string
+        query = {}
+        if len(top_scorers) > 1:
+            query['last'] = top_scorers[-1].rank
+
+        return {
+            "server_id": self.server_id,
+            "top_scorers": top_scorers,
+            "query": query,
+        }
 
     def json(self):
         """For rendering this data using JSON."""
@@ -183,7 +204,7 @@ class ServerTopScorers(ServerInfoBase):
 class ServerTopPlayers(ServerInfoBase):
     """Returns the top players by playing time on a given server."""
 
-    def __init__(self, request, limit=LEADERBOARD_COUNT, last=None):
+    def __init__(self, request, limit=INDEX_COUNT, last=None):
         """Common parameter parsing."""
         super(ServerTopPlayers, self).__init__(request, limit, last)
         self.top_players = self.raw()
@@ -226,7 +247,16 @@ class ServerTopPlayers(ServerInfoBase):
         top_players = [TopPlayer(tp.rank, tp.player_id, html_colors(tp.nick), tp.alivetime)
                        for tp in self.top_players]
 
-        return top_players
+        # build the query string
+        query = {}
+        if len(top_players) > 1:
+            query['last'] = top_players[-1].rank
+
+        return {
+            "server_id": self.server_id,
+            "top_players": top_players,
+            "query": query,
+        }
 
     def json(self):
         """For rendering this data using JSON."""
@@ -273,9 +303,9 @@ class ServerInfo(ServerInfoBase):
         """For rendering this data using something HTML-based."""
         return {
             'server': self.server,
-            'top_players': self.top_players_v.html(),
-            'top_scorers': self.top_scorers_v.html(),
-            'top_maps': self.top_maps_v.html(),
+            'top_players': self.top_players_v.html()["top_players"],
+            'top_scorers': self.top_scorers_v.html()["top_scorers"],
+            'top_maps': self.top_maps_v.html()["top_maps"],
             'recent_games': self.recent_games,
             'lifetime': self.lifetime,
         }