diff --git a/module/metric/calc/product/scale/count_of_monthly_created_story_in_product.php b/module/metric/calc/product/scale/count_of_monthly_created_story_in_product.php index 0c0c291182..1b8a0678c7 100644 --- a/module/metric/calc/product/scale/count_of_monthly_created_story_in_product.php +++ b/module/metric/calc/product/scale/count_of_monthly_created_story_in_product.php @@ -1,7 +1,7 @@ product; + $openedDate = $data->openedDate; - //public function calculate($data) - //{ - //} + $year = substr($openedDate, 0, 4); + $month = substr($openedDate, 5, 2); - //public function getResult() - //{ - //} -} \ No newline at end of file + if($year == '0000') return; + + if(!isset($this->result[$product])) $this->result[$product] = array(); + if(!isset($this->result[$product][$year])) $this->result[$product][$year] = array(); + if(!isset($this->result[$product][$year][$month])) $this->result[$product][$year][$month] = 0; + + $this->result[$product][$year][$month] += 1; + } + + public function getResult($options = null) + { + $records = array(); + foreach($this->result as $product => $years) + { + foreach($years as $year => $months) + { + foreach($months as $month => $value) + { + $records[] = array('product' => $product, 'year' => $year, 'month' => $month, 'value' => $value); + } + } + } + + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/test/calc/product/scale/count_of_monthly_created_story_in_product.php b/module/metric/test/calc/product/scale/count_of_monthly_created_story_in_product.php new file mode 100755 index 0000000000..6cd6ad16e3 --- /dev/null +++ b/module/metric/test/calc/product/scale/count_of_monthly_created_story_in_product.php @@ -0,0 +1,23 @@ +#!/usr/bin/env php +gen(200); +zdTable('story')->config('story_close')->gen(5000); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=count_of_monthly_opened_story_in_product +cid=1 +pid=1 + +*/ +r(count($calc->getResult())) && p('') && e('651'); // 测试按产品的月度新增需求分组数。 + +r($calc->getResult(array('product' => '16', 'year' => '2019', 'month' => '06'))) && p('0:value') && e('10'); // 测试2019年6月产品16新增的需求数。 +r($calc->getResult(array('product' => '78', 'year' => '2020', 'month' => '08'))) && p('0:value') && e('10'); // 测试2020年8月产品78新增的需求数。 +r($calc->getResult(array('product' => '999', 'year' => '2021', 'month' => '04'))) && p('') && e('0'); // 测试不存在的产品的需求数。 diff --git a/module/metric/test/calc/product/scale/yaml/count_of_monthly_created_story_in_product/story_close.yaml b/module/metric/test/calc/product/scale/yaml/count_of_monthly_created_story_in_product/story_close.yaml new file mode 100755 index 0000000000..49ba5bbb3e --- /dev/null +++ b/module/metric/test/calc/product/scale/yaml/count_of_monthly_created_story_in_product/story_close.yaml @@ -0,0 +1,14 @@ +--- +title: zt_story +author: qixinzhi +version: "1.0" +fields: +- field: id + range: 1-10000 +- field: product + range: 1-100{10} +- field: openedDate + range: (-5Y)-(-10M)-(+1w):-1D + type: timestamp + format: YYYY-MM-DD hh:mm:ss +...