diff --git a/module/metric/calc/project/scale/count_of_closed_execution_in_project.php b/module/metric/calc/project/scale/count_of_closed_execution_in_project.php new file mode 100644 index 0000000000..ac8f6e24b5 --- /dev/null +++ b/module/metric/calc/project/scale/count_of_closed_execution_in_project.php @@ -0,0 +1,43 @@ + + * @package + * @uses func + * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html) + * @Link https://www.zentao.net + */ +class count_of_closed_execution_in_project extends baseCalc +{ + public $dataset = 'getExecutions'; + + public $fieldList = array('t1.project', 't1.status'); + + public function calculate($row) + { + $project = $row->project; + $status = $row->status; + + if(!isset($this->result[$project])) $this->result[$project] = 0; + if($status == 'closed') $this->result[$project] += 1; + } + + public function getResult($options = array()) + { + $records = $this->getRecords(array('project', 'value')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/test/calc/project/scale/count_of_closed_execution_in_project.php b/module/metric/test/calc/project/scale/count_of_closed_execution_in_project.php new file mode 100644 index 0000000000..a26feded8a --- /dev/null +++ b/module/metric/test/calc/project/scale/count_of_closed_execution_in_project.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +config('project_close', $useCommon = true, $levels = 4)->gen(10); +zdTable('project')->config('execution', $useCommon = true, $levels = 4)->gen(1000, false); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=count_of_closed_execution_in_project +cid=1 +pid=1 + +*/ + +r(count($calc->getResult())) && p('') && e('6'); // 测试分组数。 + +r($calc->getResult(array('project' => '10'))) && p('0:value') && e('20'); // 测试项目10。