Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id EC065E00948; Fri, 1 Jul 2016 11:19:00 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [209.85.220.42 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id BA0FDE006D2 for ; Fri, 1 Jul 2016 11:18:57 -0700 (PDT) Received: by mail-pa0-f42.google.com with SMTP id hl6so40856599pac.2 for ; Fri, 01 Jul 2016 11:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=mlnojUgNC6p9twMVtrrAoykCPj/kDdEBM2VfnuJ4ctc=; b=x7q6bFhMOUedTpInyGV+NYg2vItRiOQrUxwLeSTh2WUhE/cKlZizcHOf6EO7Q9Dex7 nNw/clbY1DYZSXsR3Mkubv9gfJvOLK2GdF7xLv+AIC0etD8QJ4sbOUgg1fcAN3acc/Pq 1f2dYVKnCtPVsLV2E2C27Jr2xo6VylZq/Tp3pSn97xAVN6YS8aN3wTqKn6o0j9hYr8rt SRKg3gx0bjUb6OdLzTVpKoLf5IJG4m2aB0HSgcgkasLJeB47X/4CARM8GrdRdJ+UFstJ nBjc4k+dDgIRvZ7C6mzEdtQCR2ASbWufoecNhyFDB2eWmWTqM7JqZRCA3LzfIEJUWli9 b+Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mlnojUgNC6p9twMVtrrAoykCPj/kDdEBM2VfnuJ4ctc=; b=GuoySgDjYU0Z7J4aenpLGVkRqWy0G9p46S1INpz4S5r7n+ZOnUfqLbpApLpM8uu9uG ENhfj/F/H+a5CPp71l1ScgBXNILk8kjENLLi3etpJB9BEvvY31HPTGisy5UcXUVmBpJj HX1mVJyrUE72bwPUTxAwcmjpgxwCuVnb1zSbl2jGz/0IUhXlw7ABYtU5JqRrjvlK7q0d QzzOLZEBIQlL98owW9X1XvUBHeO0YMoU2UrRKbIL1N6dr8LwpuNBeQQIQSbq7JV7edIQ luEwWP4IDSJwbZ/9gUZxVTP9GRX+SrUiAUCMyz/UWBS3ylZOzaxifw29rwXV6fpl/Clv 8+Yw== X-Gm-Message-State: ALyK8tL/Imx0jAsU7witC0VgGRYvQVx18lintxAT9twekJErmFPKHJaiOD+u0RSDHHeo0C+N X-Received: by 10.66.166.202 with SMTP id zi10mr34329438pab.42.1467397136619; Fri, 01 Jul 2016 11:18:56 -0700 (PDT) Received: from orion.ger.corp.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by smtp.gmail.com with ESMTPSA id w194sm7250971pfd.58.2016.07.01.11.18.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Jul 2016 11:18:55 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Fri, 1 Jul 2016 19:18:50 +0100 Message-Id: <1467397130-31797-1-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [PATCH] toaster: views Fix most frequently built target in project reporting X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jul 2016 18:19:01 -0000 Clean up and fix the most frequently built targets for the "Most built recipes" section for the project configuration page. [YOCTO #9846] Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/views.py | 42 +++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index c40273c..2db68bd 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -1404,15 +1404,37 @@ if True: pid = prj.id from collections import Counter - freqtargets = [] - try: - btargets = sum(build.target_set.all() for build in Build.objects.filter(project=prj, outcome__lt=Build.IN_PROGRESS)) - brtargets = sum(br.brtarget_set.all() for br in BuildRequest.objects.filter(project = prj, state = BuildRequest.REQ_FAILED)) - freqtargets = [x.target for x in btargets] + [x.target for x in brtargets] - except TypeError: - pass - freqtargets = Counter(freqtargets) - freqtargets = sorted(freqtargets, key = lambda x: freqtargets[x], reverse=True) + + freqtargets = Counter(Target.objects.filter( + Q(build__project=prj), + ~Q(build__outcome=Build.IN_PROGRESS) + ).order_by("target").values_list("target", flat=True)) + + freqtargets = freqtargets.most_common(5) + + # We now have the targets in order of frequency but if there are two + # with the same frequency then we need to make sure those are in + # alphabetical order without losing the frequency ordering + + tmp = [] + switch = None + for i, freqtartget in enumerate(freqtargets): + target, count = freqtartget + try: + target_next, count_next = freqtargets[i+1] + if count == count_next and target > target_next: + switch = target + continue + except IndexError: + pass + + tmp.append(target) + + if switch: + tmp.append(switch) + switch = None + + freqtargets = tmp layers = [{"id": x.layercommit.pk, "orderid": x.pk, "name" : x.layercommit.layer.name, "vcs_url": x.layercommit.layer.vcs_url, "vcs_reference" : x.layercommit.get_vcs_reference(), @@ -1432,7 +1454,7 @@ if True: "layers" : layers, "targets" : [{"target" : x.target, "task" : x.task, "pk": x.pk} for x in prj.projecttarget_set.all()], "variables": [(x.name, x.value) for x in prj.projectvariable_set.all()], - "freqtargets": freqtargets[:5], + "freqtargets": freqtargets, "releases": [{"id": x.pk, "name": x.name, "description":x.description} for x in Release.objects.all()], "project_html": 1, "recipesTypeAheadUrl": reverse('xhr_recipestypeahead', args=(prj.pk,)), -- 2.7.4