From patchwork Mon Jun 18 05:20:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael-Doyle Hudson X-Patchwork-Id: 9377 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 3D75B23EE2 for ; Mon, 18 Jun 2012 05:20:18 +0000 (UTC) Received: from mail-ob0-f180.google.com (mail-ob0-f180.google.com [209.85.214.180]) by fiordland.canonical.com (Postfix) with ESMTP id D352BA18670 for ; Mon, 18 Jun 2012 05:20:17 +0000 (UTC) Received: by obbun3 with SMTP id un3so8967765obb.11 for ; Sun, 17 Jun 2012 22:20:17 -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=M1W/YQ6Q3uLyNz7DAD4WZvDLTV0Ux5mILlKocTfL3CQ=; b=n1x0vVNKi+qV3IJ3yd1fe64CZSbPTevfJQSjsjG/lPsq0LpGA1orfZZRj7ka+3w8jA Qbse/3rJiltUh4GWWSx98Ntg5LsGZ8xmNuOrabUPX+048eQty62y2ani6v/fBnXcWX1B HGyLu499xFTVRlYY0RlBaFxFHRanwjLhxtSzKBWCzyQaZd+nLiD+h1dM4h0jLFx2x4nz A/yxSjsDWcXCcJwmBJfynF3w4b24gRJJvWHih57DW9j8p27/govjdbwuwbf2cjFze8N6 c3s8ERrjMEG/bxzIwhpQUIDG5aMN7dmsMQFNg2VYNa7X+dbnNsSeb35ANII0aIXZXkZK SQUA== Received: by 10.50.163.99 with SMTP id yh3mr7260293igb.53.1339996817152; Sun, 17 Jun 2012 22:20:17 -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 v20csp47632ibb; Sun, 17 Jun 2012 22:20:16 -0700 (PDT) Received: by 10.180.8.41 with SMTP id o9mr21113969wia.0.1339996815850; Sun, 17 Jun 2012 22:20:15 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id m15si19931686wee.147.2012.06.17.22.20.15 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jun 2012 22:20:15 -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 1SgUNr-0008MJ-Aj for ; Mon, 18 Jun 2012 05:20:15 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 44777E0052 for ; Mon, 18 Jun 2012 05:20:15 +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: 182 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 182: 1. Change health job pass and total number statistics method. Message-Id: <20120618052015.27163.70706.launchpad@ackee.canonical.com> Date: Mon, 18 Jun 2012 05:20:15 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15419"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 3285b1b66257e29bfd5644b096daea7695e2a312 X-Gm-Message-State: ALoCoQl/9wbMa1PgZ9IptW6b/x76DxPSA6DjmDlo3/Aq9pENPMgPTQ50gYeYz3vktNlUGJ3qIGYF Merge authors: Spring Zhang (qzhang) Related merge proposals: https://code.launchpad.net/~qzhang/lava-scheduler/simplify-sql-query/+merge/110450 proposed by: Spring Zhang (qzhang) review: Approve - Michael Hudson-Doyle (mwhudson) review: Approve - Andy Doan (doanac) ------------------------------------------------------------ revno: 182 [merge] committer: Michael Hudson-Doyle branch nick: trunk timestamp: Mon 2012-06-18 17:18:20 +1200 message: 1. Change health job pass and total number statistics method. 2. Simplify the SQL query in DeviceTypeTable by mwhudson's code (Spring Zhang) 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-06-14 05:28:44 +0000 +++ lava_scheduler_app/views.py 2012-06-15 03:16:31 +0000 @@ -25,6 +25,7 @@ from django.template import defaultfilters as filters from django.utils.html import escape from django.utils.safestring import mark_safe +from django.db import models from django_tables2 import Attrs, Column @@ -166,7 +167,8 @@ def health_jobs_in_hr(hr=-24): return TestJob.objects.filter(health_check=True, - start_time__gte=(datetime.datetime.now() + relativedelta(hours=hr))) + start_time__gte=(datetime.datetime.now() + + relativedelta(hours=hr))).exclude(status__in=[TestJob.SUBMITTED, TestJob.RUNNING]) def _online_total(): ''' returns a tuple of (num_online, num_not_retired) ''' @@ -213,20 +215,31 @@ raise PermissionDenied() return job +class SumIfSQL(models.sql.aggregates.Aggregate): + is_ordinal = True + sql_function = 'SUM' + sql_template = 'SUM((%(condition)s)::int)' + +class SumIf(models.Aggregate): + name = 'SumIf' + def add_to_query(self, query, alias, col, source, is_summary): + aggregate = SumIfSQL( + col, source=source, is_summary=is_summary, **self.extra) + query.aggregates[alias] = aggregate + class DeviceTypeTable(DataTablesTable): def get_queryset(self): - return DeviceType.objects.all() + return DeviceType.objects.all().annotate( + idle=SumIf('device', condition='status=%s' % Device.IDLE), + offline=SumIf('device', condition='status in (%s,%s)' % ( + Device.OFFLINE, Device.OFFLINING)), + busy=SumIf('device', condition='status=%s' % Device.RUNNING), + ).order_by('name') def render_status(self, record): - idle_num = Device.objects.filter(device_type=record.name, - status=Device.IDLE).count() - offline_num = Device.objects.filter(device_type=record.name, - status__in=[Device.OFFLINE, Device.OFFLINING]).count() - running_num = Device.objects.filter(device_type=record.name, - status=Device.RUNNING).count() - return "%s idle, %s offline, %s busy" % (idle_num, offline_num, - running_num) + return "%s idle, %s offline, %s busy" % (record.idle, record.offline, + record.busy) name = IDLinkColumn("name") status = Column() @@ -255,7 +268,8 @@ device_type = self.params[0] num = health_jobs_in_hr(record).filter( actual_device__in=Device.objects.filter( - device_type=device_type), status=TestJob.INCOMPLETE).count() + device_type=device_type), status__in=[TestJob.INCOMPLETE, + TestJob.CANCELED, TestJob.CANCELING]).count() return num name = Column()