* Add getRecords function for calc.

This commit is contained in:
qixinzhi
2023-07-21 08:54:19 +00:00
parent e1b512a168
commit 6ccd8dee4f
3 changed files with 39 additions and 26 deletions
+37
View File
@@ -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;
}
}
@@ -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);
}
}
@@ -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);
}
}