diff --git a/module/metric/calc.class.php b/module/metric/calc.class.php index 89545291f6..94daae2f47 100644 --- a/module/metric/calc.class.php +++ b/module/metric/calc.class.php @@ -729,4 +729,39 @@ class baseCalc return $executions; } + + /** + * 检查日期。 + * Validate date. + * + * @param string $date + * @access public + * @return bool + */ + public function validateDate(string $date): bool + { + return $this->getYear($date) !== false; + } + + /** + * 按日期递增计数。 + * Count incrementally by date. + * + * @param int $dataID + * @param string $date + * @access public + * @return void + */ + public function incrementDateCount(int $dataID, string $date) + { + $date = substr($date, 0, 10); + list($year, $month, $day) = explode('-', $date); + + if(!isset($this->result[$dataID])) $this->result[$dataID] = array(); + if(!isset($this->result[$dataID][$year])) $this->result[$dataID][$year] = array(); + if(!isset($this->result[$dataID][$year][$month])) $this->result[$dataID][$year][$month] = array(); + if(!isset($this->result[$dataID][$year][$month][$day])) $this->result[$dataID][$year][$month][$day] = 0; + + $this->result[$dataID][$year][$month][$day]++; + } } diff --git a/module/metric/calc/execution/scale/count_of_activated_bug_in_execution.php b/module/metric/calc/execution/scale/count_of_activated_bug_in_execution.php new file mode 100644 index 0000000000..245e643dfe --- /dev/null +++ b/module/metric/calc/execution/scale/count_of_activated_bug_in_execution.php @@ -0,0 +1,44 @@ + + * @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_activated_bug_in_execution extends baseCalc +{ + public $dataset = 'getExecutionBugs'; + + public $fieldList = array('t1.status', 't1.execution'); + + public $result = array(); + + public function calculate($row) + { + $execution = $row->execution; + $status = $row->status; + + if(!isset($this->result[$execution])) $this->result[$execution] = 0; + + if($status == 'active') $this->result[$execution] += 1; + } + + public function getResult($options = array()) + { + $records = $this->getRecords(array('execution', 'value')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/calc/execution/scale/count_of_bug_in_pri_in_execution.php b/module/metric/calc/execution/scale/count_of_bug_in_pri_in_execution.php new file mode 100644 index 0000000000..0085f77bd9 --- /dev/null +++ b/module/metric/calc/execution/scale/count_of_bug_in_pri_in_execution.php @@ -0,0 +1,47 @@ + + * @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_bug_in_pri_in_execution extends baseCalc +{ + public $dataset = 'getExecutionBugs'; + + public $fieldList = array(); + + public $result = array(); + + public function calculate($row) + { + if(!isset($this->result[$row->pri])) $this->result[$row->pri] = array(); + $this->result[$row->pri][$row->id] = $row->id; + } + + public function getResult($options = array()) + { + foreach($this->result as $pri => $bugs) + { + if(!is_array($bugs)) continue; + + $this->result[$pri] = count($bugs); + } + + $records = $this->getRecords(array('pri', 'value')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/calc/execution/scale/count_of_bug_in_resolution_in_execution.php b/module/metric/calc/execution/scale/count_of_bug_in_resolution_in_execution.php new file mode 100644 index 0000000000..bddc3f6c96 --- /dev/null +++ b/module/metric/calc/execution/scale/count_of_bug_in_resolution_in_execution.php @@ -0,0 +1,47 @@ + + * @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_bug_in_resolution_in_execution extends baseCalc +{ + public $dataset = 'getExecutionBugs'; + + public $fieldList = array(); + + public $result = array(); + + public function calculate($row) + { + if(!isset($this->result[$row->resolution])) $this->result[$row->resolution] = array(); + $this->result[$row->resolution][$row->id] = $row->id; + } + + public function getResult($options = array()) + { + foreach($this->result as $resolution => $bugs) + { + if(!is_array($bugs)) continue; + + $this->result[$resolution] = count($bugs); + } + + $records = $this->getRecords(array('resolution', 'value')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/calc/execution/scale/count_of_bug_in_severity_in_execution.php b/module/metric/calc/execution/scale/count_of_bug_in_severity_in_execution.php new file mode 100644 index 0000000000..9d1348d822 --- /dev/null +++ b/module/metric/calc/execution/scale/count_of_bug_in_severity_in_execution.php @@ -0,0 +1,47 @@ + + * @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_bug_in_severity_in_execution extends baseCalc +{ + public $dataset = 'getExecutionBugs'; + + public $fieldList = array(); + + public $result = array(); + + public function calculate($row) + { + if(!isset($this->result[$row->severity])) $this->result[$row->severity] = array(); + $this->result[$row->severity][$row->id] = $row->id; + } + + public function getResult($options = array()) + { + foreach($this->result as $severity => $bugs) + { + if(!is_array($bugs)) continue; + + $this->result[$severity] = count($bugs); + } + + $records = $this->getRecords(array('severity', 'value')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/calc/execution/scale/count_of_bug_in_type_in_execution.php b/module/metric/calc/execution/scale/count_of_bug_in_type_in_execution.php new file mode 100644 index 0000000000..3bee4e3180 --- /dev/null +++ b/module/metric/calc/execution/scale/count_of_bug_in_type_in_execution.php @@ -0,0 +1,47 @@ + + * @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_bug_in_type_in_execution extends baseCalc +{ + public $dataset = 'getExecutionBugs'; + + public $fieldList = array(); + + public $result = array(); + + public function calculate($row) + { + if(!isset($this->result[$row->type])) $this->result[$row->type] = array(); + $this->result[$row->type][$row->id] = $row->id; + } + + public function getResult($options = array()) + { + foreach($this->result as $type => $bugs) + { + if(!is_array($bugs)) continue; + + $this->result[$type] = count($bugs); + } + + $records = $this->getRecords(array('type', 'value')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/calc/execution/scale/count_of_daily_closed_bug_in_execution.php b/module/metric/calc/execution/scale/count_of_daily_closed_bug_in_execution.php new file mode 100644 index 0000000000..9210cca76c --- /dev/null +++ b/module/metric/calc/execution/scale/count_of_daily_closed_bug_in_execution.php @@ -0,0 +1,40 @@ + + * @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_daily_closed_bug_in_execution extends baseCalc +{ + public $dataset = 'getExecutionBugs'; + + public $fieldList = array('t1.execution', 't1.status', 't1.closedDate'); + + public $result = array(); + + public function calculate($row) + { + if($row->status != 'closed' || !$this->validateDate($row->closedDate)) return false; + $this->incrementDateCount($row->execution, $row->closedDate); + } + + public function getResult($options = array()) + { + $records = $this->getRecords(array('execution', 'year', 'month', 'day')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/calc/execution/scale/count_of_daily_created_bug_in_execution.php b/module/metric/calc/execution/scale/count_of_daily_created_bug_in_execution.php new file mode 100644 index 0000000000..a7c1f43708 --- /dev/null +++ b/module/metric/calc/execution/scale/count_of_daily_created_bug_in_execution.php @@ -0,0 +1,40 @@ + + * @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_daily_created_bug_in_execution extends baseCalc +{ + public $dataset = 'getExecutionBugs'; + + public $fieldList = array('t1.execution', 't1.openedDate'); + + public $result = array(); + + public function calculate($row) + { + if(!$this->validateDate($row->openedDate)) return false; + $this->incrementDateCount($row->execution, $row->openedDate); + } + + public function getResult($options = array()) + { + $records = $this->getRecords(array('execution', 'year', 'month', 'day', 'value')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/calc/execution/scale/count_of_daily_resolved_bug_in_execution.php b/module/metric/calc/execution/scale/count_of_daily_resolved_bug_in_execution.php new file mode 100644 index 0000000000..86036e1f74 --- /dev/null +++ b/module/metric/calc/execution/scale/count_of_daily_resolved_bug_in_execution.php @@ -0,0 +1,41 @@ + + * @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_daily_resolved_bug_in_execution extends baseCalc +{ + public $dataset = 'getExecutionBugs'; + + public $fieldList = array('t1.execution', 't1.status', 't1.resolvedDate'); + + public $result = array(); + + public function calculate($row) + { + if($row->status == 'active' || !$this->validateDate($row->resolvedDate)) return false; + $this->incrementDateCount($row->execution, $row->resolvedDate); + } + + public function getResult($options = array()) + { + $records = $this->getRecords(array('execution', 'year', 'month', 'day', 'value')); + + return $this->filterByOptions($records, $options); + } +}