From cc00e81a3d29431a780df43003814e4915dcdbcc Mon Sep 17 00:00:00 2001 From: qixinzhi Date: Thu, 20 Jul 2023 05:55:38 +0000 Subject: [PATCH] * Finish task#97972. --- .../scale/count_of_annual_delivered_story.php | 36 ++++++++++++++----- .../scale/count_of_annual_delivered_story.php | 26 ++++++++++++++ .../test/yaml/story_stage_closedreason.yaml | 4 +++ 3 files changed, 57 insertions(+), 9 deletions(-) create mode 100755 module/metric/test/calc/global/scale/count_of_annual_delivered_story.php diff --git a/module/metric/calc/global/scale/count_of_annual_delivered_story.php b/module/metric/calc/global/scale/count_of_annual_delivered_story.php index 7eea6219a2..2aafc56d15 100644 --- a/module/metric/calc/global/scale/count_of_annual_delivered_story.php +++ b/module/metric/calc/global/scale/count_of_annual_delivered_story.php @@ -10,7 +10,7 @@ * 单位:个 * 描述:按全局统计的年度交付研发需求数表示每年交付的研发需求的数量。该度量项反映了组织每年交付给用户的研发需求数量,可以用于评估组织的研发需求交付效能和效果。 * 定义:所有的所处阶段为已发布且发布时间为某年或关闭原因为已完成且关闭时间为某年的研发需求个数求和 -过滤已删除的研发需求 + * 过滤已删除的研发需求 * 度量库: * 收集方式:realtime * @@ -23,20 +23,38 @@ */ class count_of_annual_delivered_story extends baseCalc { - public $dataset = null; + public $dataset = 'getDevStories'; - public $fieldList = array(); - - //public funtion getStatement($dao) - //{ - //} + public $fieldList = array('t1.stage', 't1.releasedDate', 't1.closedReason', 't1.closedDate'); public function calculate($data) { + $stage = $data->stage; + $closedReason = $data->closedReason; + $releasedDate = $data->releasedDate; + $closedDate = $data->closedDate; + + $date = null; + if($closedReason == 'done') $date = $closedDate; + if($stage == 'released' && !empty($closedDate)) $date = $releasedDate; + + if($date === null) return; + + $year = substr($date, 0, 4); + if($year == '0000') return; + + if(!isset($this->result[$year])) $this->result[$year] = 0; + + $this->result[$year] += 1; } public function getResult($options = array()) { - return $this->filterByOptions($this->result, $options); + $records = array(); + foreach($this->result as $year => $value) + { + $records[] = array('year' => $year, 'value' => $value); + } + return $this->filterByOptions($records, $options); } -} \ No newline at end of file +} diff --git a/module/metric/test/calc/global/scale/count_of_annual_delivered_story.php b/module/metric/test/calc/global/scale/count_of_annual_delivered_story.php new file mode 100755 index 0000000000..dd168f0deb --- /dev/null +++ b/module/metric/test/calc/global/scale/count_of_annual_delivered_story.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +config('product', $useCommon = true, $levels = 4)->gen(10); +zdTable('story')->config('story_stage_closedreason', $useCommon = true, $levels = 4)->gen(2000); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=count_of_annual_delivered_story +timeout=0 +cid=1 + +*/ + +r(count($calc->getResult())) && p('') && e('10'); // 测试按产品的年度交付研发需求分组数。 + +r($calc->getResult(array('year' => '2019'))) && p('0:value') && e('22'); // 测试2019年交付的研发需求数。 +r($calc->getResult(array('year' => '2019'))) && p('0:value') && e('22'); // 测试2019年交付的研发需求数。 +r($calc->getResult(array('year' => '2020'))) && p('0:value') && e('8'); // 测试2020年交付的研发需求数。 +r($calc->getResult(array('year' => '2020'))) && p('0:value') && e('8'); // 测试2020年交付的研发需求数。 +r($calc->getResult(array('year' => '2021'))) && p('') && e('0'); // 测试不存在的产品的需求数。 diff --git a/module/metric/test/yaml/story_stage_closedreason.yaml b/module/metric/test/yaml/story_stage_closedreason.yaml index 00f3929b97..e30e52e081 100644 --- a/module/metric/test/yaml/story_stage_closedreason.yaml +++ b/module/metric/test/yaml/story_stage_closedreason.yaml @@ -15,6 +15,10 @@ fields: range: "20110101 000000-20210101 230000:10D" type: timestamp format: YYYY-MM-DD hh:mm:ss +- field: releasedDate + range: "20110101 000000-20210101 230000:10D" + type: timestamp + format: YYYY-MM-DD hh:mm:ss - field: estimate range: 1-10{10} - field: stage