diff --git a/module/metric/calc/product/scale/scale_of_annual_finished_story_in_product.php b/module/metric/calc/product/scale/scale_of_annual_finished_story_in_product.php index ee1f86c507..f9b0a187b4 100644 --- a/module/metric/calc/product/scale/scale_of_annual_finished_story_in_product.php +++ b/module/metric/calc/product/scale/scale_of_annual_finished_story_in_product.php @@ -1,7 +1,7 @@ product; + $closedDate = $data->closedDate; + $closedReason = $data->closedReason; + $estimate = $data->estimate; - //public function calculate($data) - //{ - //} + $year = substr($closedDate, 0, 4); - //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] = 0; + + if($closedReason == 'done') $this->result[$product][$year] += $estimate; + } + + 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/product/scale/scale_of_annual_finished_story_in_product.php b/module/metric/test/calc/product/scale/scale_of_annual_finished_story_in_product.php new file mode 100755 index 0000000000..9120a4bd49 --- /dev/null +++ b/module/metric/test/calc/product/scale/scale_of_annual_finished_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=scale_of_annual_finished_story_in_product +cid=1 +pid=1 + +*/ +r(count($calc->getResult())) && p('') && e('371'); // 测试按产品的年度完成需求分组数。 + +r($calc->getResult(array('product' => '16', 'year' => '2019'))) && p('0:value') && e('18'); // 测试2019年产品16关闭的需求规模数。 +r($calc->getResult(array('product' => '78', 'year' => '2020'))) && p('0:value') && e('9'); // 测试2020年产品78关闭的需求规模数。 +r($calc->getResult(array('product' => '999', 'year' => '2021'))) && p('') && e('0'); // 测试不存在的产品的需求规模数。 diff --git a/module/metric/test/calc/product/scale/yaml/count_of_annual_closed_story_in_product/story_create.yaml b/module/metric/test/calc/product/scale/yaml/count_of_annual_closed_story_in_product/story_create.yaml old mode 100644 new mode 100755 diff --git a/module/metric/test/calc/product/scale/yaml/count_of_annual_finished_story_in_product/story_create.yaml b/module/metric/test/calc/product/scale/yaml/count_of_annual_finished_story_in_product/story_create.yaml old mode 100644 new mode 100755 diff --git a/module/metric/test/calc/product/scale/yaml/scale_of_annual_finished_story_in_product/story_close.yaml b/module/metric/test/calc/product/scale/yaml/scale_of_annual_finished_story_in_product/story_close.yaml new file mode 100755 index 0000000000..cc84d4a52f --- /dev/null +++ b/module/metric/test/calc/product/scale/yaml/scale_of_annual_finished_story_in_product/story_close.yaml @@ -0,0 +1,16 @@ +--- +title: zt_story +author: qixinzhi +version: "1.0" +fields: +- field: id + range: 1-10000 +- field: product + range: 1-100{10} +- field: estimate + range: 1-10 +- field: closedDate + range: (-5Y)-(-10M)-(+1w):-1D + type: timestamp + format: YYYY-MM-DD hh:mm:ss +...