From 9f6b568e5e486b39e8c556570c73db28db3590cb Mon Sep 17 00:00:00 2001 From: qixinzhi Date: Thu, 20 Jul 2023 08:06:18 +0000 Subject: [PATCH] * Finish task#98218. --- .../scale/count_of_severe_bug_in_product.php | 41 +++++++++++-------- .../scale/count_of_severe_bug_in_product.php | 24 +++++++++++ module/metric/test/yaml/bug_severity.yaml | 26 ++++++++++++ 3 files changed, 75 insertions(+), 16 deletions(-) create mode 100755 module/metric/test/calc/product/scale/count_of_severe_bug_in_product.php create mode 100644 module/metric/test/yaml/bug_severity.yaml diff --git a/module/metric/calc/product/scale/count_of_severe_bug_in_product.php b/module/metric/calc/product/scale/count_of_severe_bug_in_product.php index 785fd9c1a3..528085354f 100644 --- a/module/metric/calc/product/scale/count_of_severe_bug_in_product.php +++ b/module/metric/calc/product/scale/count_of_severe_bug_in_product.php @@ -9,10 +9,10 @@ * 度量名称:按产品统计的严重程度为1、2级的Bug数 * 单位:个 * 描述:复用: -按产品统计的严重程度为1级的Bug数 -按产品统计的严重程度为2级的Bug数 -公式: -按产品统计的严重程度为1、2级的Bug数=按产品统计的严重程度为1级的Bug数+按产品统计的严重程度为2级的Bug数 + * 按产品统计的严重程度为1级的Bug数 + * 按产品统计的严重程度为2级的Bug数 + * 公式: + * 按产品统计的严重程度为1、2级的Bug数=按产品统计的严重程度为1级的Bug数+按产品统计的严重程度为2级的Bug数 * 度量库: * 收集方式:realtime * @@ -25,21 +25,30 @@ */ class count_of_severe_bug_in_product extends baseCalc { - public $dataset = ''; + public $dataset = 'getBugs'; - public $fieldList = array(); + public $fieldList = array('t1.severity', 't1.product'); public $result = array(); - //public function getStatement() - //{ - //} + public function calculate($data) + { + $severity = $data->severity; + $product = $data->product; - //public function calculate($data) - //{ - //} + if(!isset($this->result[$product])) $this->result[$product] = 0; - //public function getResult() - //{ - //} -} \ No newline at end of file + if($severity == '1' || $severity == '2') $this->result[$product] += 1; + } + + public function getResult($options = array()) + { + $records = array(); + foreach($this->result as $product => $value) + { + $records[] = array('product' => $product, 'value' => $value); + } + + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/test/calc/product/scale/count_of_severe_bug_in_product.php b/module/metric/test/calc/product/scale/count_of_severe_bug_in_product.php new file mode 100755 index 0000000000..8497dd6a8c --- /dev/null +++ b/module/metric/test/calc/product/scale/count_of_severe_bug_in_product.php @@ -0,0 +1,24 @@ +#!/usr/bin/env php +config('product', $useCommon = true, $levels = 4)->gen(10); +zdTable('bug')->config('bug_severity', $useCommon = true, $levels = 4)->gen(1000); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=count_of_severe_bug_in_product +cid=1 +pid=1 + +*/ + +r(count($calc->getResult())) && p('') && e('5'); // 测试严重程度1、2级bug按产品分组数。 +r($calc->getResult(array('product' => '1'))) && p('0:value') && e('36'); // 测试产品1严重程度1、2级的bug数。 +r($calc->getResult(array('product' => '3'))) && p('0:value') && e('40'); // 测试产品3严重程度1、2级的bug数。 +r($calc->getResult(array('product' => '4'))) && p('0:value') && e('0'); // 测试已删除产品4严重程度1、2级的bug数。 +r($calc->getResult(array('product' => '999'))) && p('') && e('0'); // 测试不存在的产品严重程度1、2级的bug数。 diff --git a/module/metric/test/yaml/bug_severity.yaml b/module/metric/test/yaml/bug_severity.yaml new file mode 100644 index 0000000000..fb4de0e5bb --- /dev/null +++ b/module/metric/test/yaml/bug_severity.yaml @@ -0,0 +1,26 @@ +--- +title: zt_bug +author: qixinzhi +version: "1.0" +fields: +- field: id + range: 1-10000 +- field: product + range: 1-10{8} +- field: openedDate + range: "20100101 000000-20210101 230000:10D" + type: timestamp + format: YYYY-MM-DD hh:mm:ss +- field: resolvedDate + range: "20110101 000000-20210101 230000:10D" + type: timestamp + format: YYYY-MM-DD hh:mm:ss +- field: closedDate + range: "20120101 000000-20220101 230000:10D" + type: timestamp + format: YYYY-MM-DD hh:mm:ss +- field: severity + range: 1{10},2{10},3{5},4{3} +- field: deleted + range: 0{4},1{4} +...