diff --git a/module/metric/calc.class.php b/module/metric/calc.class.php index b1a865afc4..095a82db1b 100644 --- a/module/metric/calc.class.php +++ b/module/metric/calc.class.php @@ -206,4 +206,41 @@ class baseCalc { return $this->getStatement()->fetchAll(); } + + /** + * 转换计算结果数组为度量记录数据数组。 + * Get records from result. + * + * @param array $keyNames + * @access public + * @return array + */ + public function getRecords($keyNames) + { + if(empty($keyNames)) return $this->result; + + $records = array(); + $keyName = array_shift($keyNames); + foreach($this->result as $key => $value) $records[] = array($keyName => $key, 'value' => $value); + + while($keyName = array_shift($keyNames)) + { + if($keyName == 'value') break; + + $newRecords = array(); + foreach($records as $record) + { + foreach($record['value'] as $key => $value) + { + $record[$keyName] = $key; + $record['value'] = $value; + $newRecords[] = $record; + } + } + + $records = $newRecords; + } + + return $records; + } } diff --git a/module/metric/calc/global/hour/consume_of_monthly_closed_project.php b/module/metric/calc/global/hour/consume_of_monthly_closed_project.php index 95de296fae..bddda73967 100644 --- a/module/metric/calc/global/hour/consume_of_monthly_closed_project.php +++ b/module/metric/calc/global/hour/consume_of_monthly_closed_project.php @@ -66,17 +66,7 @@ class consume_of_monthly_closed_project extends baseCalc public function getResult($options = array()) { - $records = array(); - foreach($this->result as $year => $months) - { - foreach($months as $month => $projects) - { - foreach($projects as $project => $value) - { - $records[] = array('project' => $project, 'year' => $year, 'month' => $month, 'value' => $value); - } - } - } + $records = $this->getRecords(array('year', 'month', 'project', 'value')); return $this->filterByOptions($records, $options); } } diff --git a/module/metric/calc/product/scale/count_of_daily_closed_bug_in_product.php b/module/metric/calc/product/scale/count_of_daily_closed_bug_in_product.php index 94ab8be0d9..73ef17a69c 100644 --- a/module/metric/calc/product/scale/count_of_daily_closed_bug_in_product.php +++ b/module/metric/calc/product/scale/count_of_daily_closed_bug_in_product.php @@ -44,21 +44,7 @@ class count_of_daily_closed_bug_in_product extends baseCalc public function getResult($options = array()) { - $records = array(); - foreach($this->result as $product => $years) - { - foreach($years as $year => $months) - { - foreach($months as $month => $days) - { - foreach($days as $day => $value) - { - $records[] = array('product' => $product, 'year' => $year, 'month' => $month, 'day' => $day, 'value' => $value); - } - } - } - } - + $records = $this->getRecords(array('product', 'year', 'month', 'day')); return $this->filterByOptions($records, $options); } }