Fix stats template, don't error on missing runner stats
authorTom Powell <tom@powell.io>
Sun, 4 Nov 2018 01:48:45 +0000 (18:48 -0700)
committerTom Powell <tom@powell.io>
Sun, 4 Nov 2018 01:48:45 +0000 (18:48 -0700)
ui/app.py
ui/templates/stats.html

index dc7895e3fa72ca990d0af2b55c2e7603f0e90d19..70155486cc5d8cf5fc57e8a82a8578c5e9719760 100644 (file)
--- a/ui/app.py
+++ b/ui/app.py
@@ -127,7 +127,9 @@ def web_runner(runner):
 
 @app.route('/stats')
 def web_stats():
-    return render_template('stats.html', stats=stats())
+    stats_ = stats()
+    runners = ['all'] + [x for x in sorted(stats_['builds'].keys()) if x != 'all']
+    return render_template('stats.html', stats=stats_, runners=runners)
 
 @app.route("/runners/")
 def web_runners():
index 96b9bfb28ca09cfc8632ce4c4b77f1fc883156bd..f34ee8cd568b2095fd925a8dca1a8895f277b277 100644 (file)
@@ -5,6 +5,7 @@
 {% from "bootstrap/pagination.html" import render_pagination %}
 {% block content %}
 {% set statuses = stats['builds']['all'].keys() | sort %}
+
     <div class="container">
     Status
     <table class="table table-striped">
             <th>{{status | title}}</th>
             {% endfor %}
         </tr>
-        {% for runner in stats['builds'].keys() | sort %}
+        {% for runner in runners %}
+        {% if runner in stats['builds'] %}
         <tr>
             <td>{% if runner != 'all' %}<a href="/runners/{{runner}}">{{runner}}</a>{% else %}{{runner}}{% endif %}</td>
             {% for status in statuses %}
             <td>{{stats['builds'].get(runner).get(status, 0)}}</td>
             {% endfor %}
         </tr>
+        {% endif %}
         {% endfor %}
     </table>
 
             <th>Maximum</th>
             <th>Total</th>
         </tr>
-        {% for runner in stats['builds'].keys() | sort %}
+        {% for runner in runners %}
+        {% if runner in stats['times'] and version in stats['times'][runner] %}
         <tr>
-            <td>{% if runner != 'all' %}<a href="/runners/{runner}">{{runner}}</a>{% else %}{{runner}}{% endif %}</td>
+            <td>{% if runner != 'all' %}<a href="/runners/{{runner}}">{{runner}}</a>{% else %}{{runner}}{% endif %}</td>
             <td>{{(stats['times'][runner][version]['avg'] / 60) | round(2)}} minutes</td>
             <td>{{(stats['times'][runner][version]['min'] / 60) | round(2)}} minutes</td>
             <td>{{(stats['times'][runner][version]['max'] / 60) | round(2)}} minutes</td>
             <td>{{(stats['times'][runner][version]['sum'] / 60 / 60 / 24) | round(2)}} days </td>
         </tr>
+        {% endif %}
         {% endfor %}
     </table>
     {% endfor %}