]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Use an instance method to format the play time string.
authorAnt Zucaro <azucaro@gmail.com>
Wed, 8 Nov 2017 02:59:03 +0000 (21:59 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 8 Nov 2017 02:59:03 +0000 (21:59 -0500)
xonstat/models/main.py
xonstat/templates/main_index.mako
xonstat/templates/top_servers_index.mako

index 0648623148e500a8e6ceb0284c4c2a80d68a115b..2862a25549714749ad37f7d1f6908a042062b047 100644 (file)
@@ -2,6 +2,7 @@
 Models related to the main index page.
 """
 
+import datetime
 from xonstat.util import html_colors
 
 
@@ -44,6 +45,21 @@ class ActiveServer(object):
         self.server_name = server_name
         self.play_time = play_time
 
+    def play_time_str(self):
+        hour = 3600
+        day = hour * 24
+
+        if not self.play_time:
+            return "0m"
+
+        total_seconds = self.play_time.total_seconds()
+        if total_seconds >= day:
+            return "{}d".format(round(float(total_seconds) / day, 1))
+        elif day > total_seconds >= hour:
+            return "{}h".format(round(float(total_seconds) / hour, 1))
+        else:
+            return "{}m".format(round(float(total_seconds) / 60, 1))
+
     def __repr__(self):
         return "<ActiveServer({0.sort_order}, {0.server_id})>".format(self)
 
index 6641d96aedec7a64b5f1048d5c22fb19785ffecd..75f78540d16d99e9a5e5df88d37aae2aeeffed2c 100644 (file)
         <tr>
           <th class="small-2">#</th>
           <th class="small-7">Server</th>
-          <th class="small-3">Games</th>
+          <th class="small-3">Play Time</th>
         </tr>
       </thead>
       <tbody>
         <tr>
           <td>${ts.sort_order}</td>
           <td class="no-stretch"><a href="${request.route_url('server_info', id=ts.server_id)}" title="Go to the server info page for ${ts.server_name}">${ts.server_name}</a></td>
-          <td>${ts.games}</td>
+          <td>${ts.play_time_str()}</td>
         </tr>
       % endfor
       </tbody>
index 4adba45451ce9a4216b516fd0f978a172c70c956..836e36f1eaed73f02220886ca1fcae46073da87b 100644 (file)
@@ -24,7 +24,7 @@
           <tr>
             <th class="small-2">#</th>
             <th class="small-7">Server</th>
-            <th class="small-3">Games</th>
+            <th class="small-3">Time</th>
           </tr>
         </thead>
         <tbody>
@@ -32,7 +32,7 @@
           <tr>
             <td>${ts.sort_order}</td>
             <td class="no-stretch"><a href="${request.route_url('server_info', id=ts.server_id)}" title="Go to the server info page for ${ts.server_name}">${ts.server_name}</a></td>
-            <td>${ts.games}</td>
+            <td>${ts.play_time_str()}</td>
           </tr>
         % endfor
         </tbody>