From patchwork Thu Jun 7 23:44:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Doan X-Patchwork-Id: 9165 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 14F8223E56 for ; Thu, 7 Jun 2012 23:44:14 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id B6B4AA18004 for ; Thu, 7 Jun 2012 23:44:13 +0000 (UTC) Received: by ggnf1 with SMTP id f1so967036ggn.11 for ; Thu, 07 Jun 2012 16:44:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=aj8+G2UIYYDwCgOIHvZEA/IV3Rw1ycxKakaCK9GeCRw=; b=bPu9vChMKMHFdNR9Mcl3B+9gjB45jtseF7Y0EiPnC4CJS/ns3K9ufPGXPZ7xVrlOkD hWm5xVST8JtpUXtQNdoNgxk4X2ka3MDAdX+lNNdMg3K/PUzD7E9qPm4VkFcFzmU8YAG2 kA00EIQ/EPLm3fsCAlYPcMdkzXbR0PjjdV+B0ci4PcKH1ejhO46rZao7eEncuXSr1/Rk 8fzM0k48hvc1VWKH2gI37Tw5AmY4H9imrj10ZweHgYQ2pbVNkG3bxU3uMYO9WPGvPMzs +5Roh1MjZ/NJSGF8GV1aowb0bDGq3RgORg1BptTXtphCC0kOYQS/t5FGSev5blXHSuGB W9qQ== Received: by 10.42.210.193 with SMTP id gl1mr2675557icb.57.1339112653074; Thu, 07 Jun 2012 16:44:13 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp6464ibb; Thu, 7 Jun 2012 16:44:11 -0700 (PDT) Received: by 10.14.47.72 with SMTP id s48mr2344306eeb.130.1339112651147; Thu, 07 Jun 2012 16:44:11 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id o51si7565255wee.12.2012.06.07.16.44.10 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 07 Jun 2012 16:44:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1ScmN8-0007ZU-FD for ; Thu, 07 Jun 2012 23:44:10 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 65804E0030 for ; Thu, 7 Jun 2012 23:44:10 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-scheduler X-Launchpad-Branch: ~linaro-validation/lava-scheduler/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 177 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 177: update query for online/total boards Message-Id: <20120607234410.27684.29255.launchpad@ackee.canonical.com> Date: Thu, 07 Jun 2012 23:44:10 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15353"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 5aef217cd9e365154fc8d0039049426fe9dff356 X-Gm-Message-State: ALoCoQkYWuFFwZPzdzU+fPLpAeJYS4Z3wjgqITipu9BTSH73uBBZkMzeNEJoT47C7c1Jwot+QG5G ------------------------------------------------------------ revno: 177 committer: Andy Doan 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 === 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()),