diff --git a/module/metric/calc/product/scale/count_of_annual_created_story_in_product.php b/module/metric/calc/product/scale/count_of_annual_created_story_in_product.php index 1fb2a50be5..5a427f24de 100644 --- a/module/metric/calc/product/scale/count_of_annual_created_story_in_product.php +++ b/module/metric/calc/product/scale/count_of_annual_created_story_in_product.php @@ -8,14 +8,12 @@ * 目的:scale * 度量名称:按产品统计的年度新增研发需求数 * 单位:个 - * 描述:产品中创建时间为某年的研发需求的个数求和 -过滤已删除的研发需求 -过滤已删除的产品 + * 描述:产品中创建时间为某年的研发需求的个数求和 过滤已删除的研发需求 过滤已删除的产品 * 度量库: * 收集方式:realtime * * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net) - * @author qixinzhi + * @author zhouxin * @package * @uses func * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html) @@ -23,21 +21,41 @@ */ class count_of_annual_created_story_in_product extends baseCalc { - public $dataset = ''; + public $dataset = 'getStories'; - public $fieldList = array(); + public $fieldList = array('t1.product', 't1.openedDate'); public $result = array(); - //public function getStatement() - //{ - //} + public function calculate($row) + { + $product = $row->product; + $openedDate = $row->openedDate; - //public function calculate($data) - //{ - //} + $year = substr($openedDate, 0, 4); - //public function getResult() - //{ - //} -} \ No newline at end of file + if(empty($year) || $year == '0000') return; + + if(!isset($this->result[$product])) $this->result[$product] = array(); + if(!isset($this->result[$product][$year])) $this->result[$product][$year] = 0; + $this->result[$product][$year] += 1; + } + + public function getResult($options = array()) + { + $records = array(); + foreach($this->result as $product => $years) + { + foreach($years as $year => $value) + { + $records[] = array( + 'product' => $product, + 'year' => $year, + 'value' => $value, + ); + } + } + + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/test/calc/product/scale/count_of_annual_created_story_in_product.php b/module/metric/test/calc/product/scale/count_of_annual_created_story_in_product.php new file mode 100755 index 0000000000..5947c08fc5 --- /dev/null +++ b/module/metric/test/calc/product/scale/count_of_annual_created_story_in_product.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +gen(100); +zdTable('product')->gen(100); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=count_of_annual_created_story_in_product +timeout=0 +cid=1 + +- 测试分组数. @25 + +- 测试2023年产品1,2,3创建的需求数。 + - 第0条的value属性 @4 + - 第1条的value属性 @4 + - 第2条的value属性 @4 + +- 测试2023年产品4,5,6创建的需求数。 + - 第0条的value属性 @4 + - 第1条的value属性 @4 + - 第2条的value属性 @4 + +- 测试不存在的年份创建的需求数。 @0 + +*/ + +r(count($calc->getResult())) && p('') && e('25'); // 测试分组数. +r($calc->getResult(array('product' => '1,2,3', 'year' => '2022,2023'))) && p('0:value;1:value;2:value') && e('4,4,4'); // 测试2023年产品1,2,3创建的需求数。 +r($calc->getResult(array('product' => '4,5,6', 'year' => '2022,2023'))) && p('0:value;1:value;2:value') && e('4,4,4'); // 测试2023年产品4,5,6创建的需求数。 +r($calc->getResult(array('product' => '1,2,3', 'year' => '2022'))) && p('') && e('0'); // 测试不存在的年份创建的需求数。 \ No newline at end of file