diff mbox

[Branch,~linaro-validation/lava-scheduler/trunk] Rev 177: update query for online/total boards

Message ID 20120607234410.27684.29255.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Andy Doan June 7, 2012, 11:44 p.m. UTC
------------------------------------------------------------
revno: 177
committer: Andy Doan <andy.doan@linaro.org>
branch nick: lava-scheduler
timestamp: Mon 2012-06-04 16:09:38 -0500
message:
  update query for online/total boards
  
  The RETIRED status changes how this should be determined. We can
  also do this in one hit to the database rather than two
modified:
  lava_scheduler_app/views.py


--
lp:lava-scheduler
https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk

You are subscribed to branch lp:lava-scheduler.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_scheduler_app/views.py'
--- lava_scheduler_app/views.py	2012-05-28 09:40:20 +0000
+++ lava_scheduler_app/views.py	2012-06-04 21:09:38 +0000
@@ -8,6 +8,7 @@ 
 
 from django.conf import settings
 from django.core.urlresolvers import reverse
+from django.db.models import Count
 from django.http import (
     HttpResponse,
     HttpResponseBadRequest,
@@ -166,15 +167,24 @@ 
     return TestJob.objects.filter(health_check=True,
            start_time__gte=(datetime.datetime.now() + relativedelta(hours=hr)))
 
+def _online_total():
+    ''' returns a tuple of (num_online, num_not_retired) '''
+    r = Device.objects.all().values('status').annotate(count=Count('status'))
+    offline = total = 0
+    for res in r:
+        if res['status'] in [Device.OFFLINE, Device.OFFLINING]:
+            offline += res['count']
+        if res['status'] != Device.RETIRED:
+            total += res['count']
+
+    return (total-offline,total)
+
 @BreadCrumb("Scheduler", parent=lava_index)
 def index(request):
     return render_to_response(
         "lava_scheduler_app/index.html",
         {
-            'device_status': "%s/%s" % (
-                Device.objects.filter(
-                    status__in=[Device.IDLE, Device.RUNNING]).count(),
-                    Device.objects.count()),
+            'device_status': "%d/%d" % _online_total(),
             'health_check_status': "%s/%s" % (
                 health_jobs_in_hr().filter(status=TestJob.COMPLETE).count(),
                 health_jobs_in_hr().count()),