From ae97ec2eb8fdde0362f49370c023fe6ee8ece2b5 Mon Sep 17 00:00:00 2001 From: qixinzhi Date: Thu, 27 Jul 2023 08:40:54 +0000 Subject: [PATCH] * Finish task#98387. --- .../scale/scale_of_monthly_closed_story.php | 9 +----- ...mp => scale_of_monthly_finished_story.php} | 32 ++++++++++++------- .../scale/scale_of_monthly_finished_story.php | 26 +++++++++++++++ 3 files changed, 48 insertions(+), 19 deletions(-) rename module/metric/calc/global/scale/{scale_of_monthly_finished_story.php.tmp => scale_of_monthly_finished_story.php} (55%) create mode 100755 module/metric/test/calc/global/scale/scale_of_monthly_finished_story.php diff --git a/module/metric/calc/global/scale/scale_of_monthly_closed_story.php b/module/metric/calc/global/scale/scale_of_monthly_closed_story.php index ca60b85db2..886be81401 100644 --- a/module/metric/calc/global/scale/scale_of_monthly_closed_story.php +++ b/module/metric/calc/global/scale/scale_of_monthly_closed_story.php @@ -45,14 +45,7 @@ class scale_of_monthly_closed_story extends baseCalc public function getResult($options = array()) { - $records = array(); - foreach($this->result as $year => $months) - { - foreach($months as $month => $value) - { - $records[] = array('year' => $year, 'month' => $month, 'value' => $value); - } - } + $records = $this->getRecords(array('year', 'month', 'value')); return $this->filterByOptions($records, $options); } } diff --git a/module/metric/calc/global/scale/scale_of_monthly_finished_story.php.tmp b/module/metric/calc/global/scale/scale_of_monthly_finished_story.php similarity index 55% rename from module/metric/calc/global/scale/scale_of_monthly_finished_story.php.tmp rename to module/metric/calc/global/scale/scale_of_monthly_finished_story.php index 9a8942d624..253d5af465 100644 --- a/module/metric/calc/global/scale/scale_of_monthly_finished_story.php.tmp +++ b/module/metric/calc/global/scale/scale_of_monthly_finished_story.php @@ -10,9 +10,9 @@ * 单位:个 * 描述:按全局统计的月度完成研发需求规模数表示某月度完成的研发需求的规模总数。该度量项反映了组织每月完成的研发需求的规模总数,可以用于评估组织的研发需求规模管理和效果。 * 定义:所有的研发需求规模数求和 -关闭时间为某年某月 -关闭原因为已完成 -过滤已删除的研发需求 + * 关闭时间为某年某月 + * 关闭原因为已完成 + * 过滤已删除的研发需求 * 度量库: * 收集方式:realtime * @@ -25,20 +25,30 @@ */ class scale_of_monthly_finished_story extends baseCalc { - public $dataset = null; + public $dataset = 'getDevStories'; - public $fieldList = array(); + public $fieldList = array('t1.closedDate', 't1.closedReason', 't1.estimate'); - //public funtion getStatement($dao) - //{ - //} + public $result = array(); - public function calculate($data) + public function calculate($row) { + if(empty($row->closedDate) || $row->closedReason != 'done') return false; + + $year = substr($row->closedDate, 0, 4); + $month = substr($row->closedDate, 5, 2); + + if($year == '0000') return false; + + if(!isset($this->result[$year])) $this->result[$year] = array(); + if(!isset($this->result[$year][$month])) $this->result[$year][$month] = 0; + + $this->result[$year][$month] += $row->estimate; } public function getResult($options = array()) { - return $this->filterByOptions($this->result, $options); + $records = $this->getRecords(array('year', 'month', 'value')); + return $this->filterByOptions($records, $options); } -} \ No newline at end of file +} diff --git a/module/metric/test/calc/global/scale/scale_of_monthly_finished_story.php b/module/metric/test/calc/global/scale/scale_of_monthly_finished_story.php new file mode 100755 index 0000000000..1bd4967dbe --- /dev/null +++ b/module/metric/test/calc/global/scale/scale_of_monthly_finished_story.php @@ -0,0 +1,26 @@ +#!/usr/bin/env php +config('product', $useCommon = true, $levels = 4)->gen(10); +zdTable('story')->config('story_status_closedreason', $useCommon = true, $levels = 4)->gen(1000); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=scale_of_monthly_finished_story +cid=1 +pid=1 + +*/ + +r(count($calc->getResult())) && p('') && e('38'); // 测试按产品的月度完成需求分组数。 + +r($calc->getResult(array('year' => '2019', 'month' => '01'))) && p('0:value') && e('0'); // 测试2019年1月完成的需求数。 +r($calc->getResult(array('year' => '2019', 'month' => '06'))) && p('0:value') && e('5'); // 测试2019年6月完成的需求数。 +r($calc->getResult(array('year' => '2020', 'month' => '08'))) && p('0:value') && e('1'); // 测试2020年8月完成的需求数。 +r($calc->getResult(array('year' => '2020', 'month' => '10'))) && p('0:value') && e('1'); // 测试2020年10月完成的需求数。 +r($calc->getResult(array('year' => '2021', 'month' => '04'))) && p('') && e('0'); // 测试不存在的产品的需求数。