diff --git a/module/metric/calc/prod/scale/count_of_annual_created_requirement_in_product.php b/module/metric/calc/prod/scale/count_of_annual_created_requirement_in_product.php index 3c899f7684..adff3466b3 100644 --- a/module/metric/calc/prod/scale/count_of_annual_created_requirement_in_product.php +++ b/module/metric/calc/prod/scale/count_of_annual_created_requirement_in_product.php @@ -1,7 +1,7 @@ product; + $type = $data->type; + $openedDate = $data->openedDate; - //public function calculate($data) - //{ - //} + $year = substr($openedDate, 0, 4); + if($year == '0000') return; - //public function getResult() - //{ - //} -} \ No newline at end of file + 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 = null) + { + $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/prod/scale/count_of_annual_created_requirement_in_product.php b/module/metric/test/calc/prod/scale/count_of_annual_created_requirement_in_product.php new file mode 100755 index 0000000000..9b7f05352c --- /dev/null +++ b/module/metric/test/calc/prod/scale/count_of_annual_created_requirement_in_product.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +config('story_create')->gen(5000); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=count_of_annual_created_requirement_in_product +cid=1 +pid=1 + +*/ + +r(count($calc->getResult())) && p('') && e('232'); // 测试按产品的年度新增用户需求分组数。 +r($calc->getResult(array('product' => '78', 'year' => '2021'))) && p('0:value') && e('10'); // 测试2021年产品78新增的用户需求数。 +r($calc->getResult(array('product' => '84', 'year' => '2022'))) && p('0:value') && e('0'); // 测试2022年产品84新增的用户需求数。 +r($calc->getResult(array('product' => '999', 'year' => '2021'))) && p('') && e('0'); // 测试不存在的产品的用户需求数。 diff --git a/module/metric/test/calc/prod/scale/yaml/count_of_annual_created_requirement_in_product/story_create.yaml b/module/metric/test/calc/prod/scale/yaml/count_of_annual_created_requirement_in_product/story_create.yaml new file mode 100755 index 0000000000..433d7c78b7 --- /dev/null +++ b/module/metric/test/calc/prod/scale/yaml/count_of_annual_created_requirement_in_product/story_create.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: (-10Y)-(-1M)-(+1w):-1D + type: timestamp + format: YYYY-MM-DD hh:mm:ss +...