Include last build time in stats
authorTom Powell <tom@powell.io>
Sun, 4 Nov 2018 02:34:38 +0000 (19:34 -0700)
committerTom Powell <tom@powell.io>
Sun, 4 Nov 2018 02:34:38 +0000 (19:34 -0700)
test.py
ui/app.py
ui/templates/stats.html

diff --git a/test.py b/test.py
index a73f5d3781a5086cef56a891c64880ac257d7df1..f2bf351d6067e6d6660de4f041b503077d10fec8 100644 (file)
--- a/test.py
+++ b/test.py
@@ -105,7 +105,7 @@ class TestWeb(UsesModels):
     def test_get(self):
         build1 = Build(build_id=1, build_date=datetime.datetime.strptime("2018-01-01", "%Y-%m-%d"), build_status="pending", build_version="cm-14.1")
         runner = Runner(runner_name="foobar", runner_id="foobar", runner_sponsor="Me", runner_sponsor_url="You")
-        build2 = Build(build_id=2, build_status="success", build_device="mako", build_version="cm-14.1", build_type="userdebug", build_date=datetime.datetime.strptime("2018-01-01", "%Y-%m-%d"), build_runner=runner)
+        build2 = Build(build_id=2, build_status="success", build_device="mako", build_version="cm-14.1", build_type="userdebug", build_date=datetime.datetime.strptime("2018-01-01", "%Y-%m-%d"), build_runner=runner, build_duration=2)
         db.session.add(build1)
         db.session.add(runner)
         db.session.add(build2)
index 70155486cc5d8cf5fc57e8a82a8578c5e9719760..3a197faff496f9b0cc3397f28fc9410fc3562ab9 100644 (file)
--- a/ui/app.py
+++ b/ui/app.py
@@ -66,6 +66,14 @@ def stats():
         func.sum(models.Build.build_duration)
     ).group_by(models.Build.build_version).all()
 
+    last_build_times = models.Build.query.join(models.Build.build_runner).with_entities(
+        models.Runner.runner_name,
+        models.Build.build_version,
+        models.Build.build_duration
+    ).filter(
+        models.Build.build_status == "success"
+    ).group_by(models.Runner.runner_name, models.Build.build_version).all()
+
     runner_build_status = models.Build.query.join(models.Build.build_runner).with_entities(
         models.Runner.runner_name,
         models.Build.build_status,
@@ -98,6 +106,9 @@ def stats():
             'sum': build_time[5] if build_time[5] else 0,
         }
 
+    for build_time in last_build_times:
+        stats['times'].setdefault(build_time[0], {})[build_time[1]]["last"] = build_time[2]
+
     for build_status in runner_build_status:
         stats['builds']['all'].setdefault(build_status[1], 0)
         stats['builds']['all'][build_status[1]] += build_status[2]
index f34ee8cd568b2095fd925a8dca1a8895f277b277..8e121f06cecedaf076501b1daeb33b08f805255f 100644 (file)
@@ -32,6 +32,7 @@
     <table class="table table-striped">
         <tr>
             <th>Runner</th>
+            <th>Last</th>
             <th>Average</th>
             <th>Minimum</th>
             <th>Maximum</th>
@@ -41,6 +42,7 @@
         {% 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 'last' in stats['times'][runner][version] %}{{(stats['times'][runner][version]['last'] / 60) | round(2)}} minutes{% 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>