* Format calculate function and add getStatement for metric.
This commit is contained in:
@@ -50,8 +50,12 @@ class metric extends control
|
||||
}
|
||||
}
|
||||
|
||||
/* 处理无法归类的度量项,直接赋值dao。*/
|
||||
foreach($otherInstances as $instance) $instance->dao = $this->dao;
|
||||
/* 处理无法归类的度量项,使用句柄获取数据源。*/
|
||||
foreach($otherInstances as $instance)
|
||||
{
|
||||
$rows = $instance->getStatement($this->dao)->fetchAll();
|
||||
foreach($rows as $row) $instance->calculate((object)$row);
|
||||
}
|
||||
|
||||
/* 获取度量项的计算结果并保存。*/
|
||||
foreach($metricInstances as $metricObj)
|
||||
|
||||
@@ -64,6 +64,18 @@ class baseMetric
|
||||
*/
|
||||
public $result;
|
||||
|
||||
/**
|
||||
* 获取数据查询句柄。
|
||||
* Get pdo statement of sql query.
|
||||
*
|
||||
* @param object $dao
|
||||
* @access public
|
||||
* @return PDOStatement
|
||||
*/
|
||||
public function getStatement($dao)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算度量项。
|
||||
* Calculate metric.
|
||||
@@ -74,10 +86,7 @@ class baseMetric
|
||||
*/
|
||||
public function calculate($data)
|
||||
{
|
||||
/* 1. 判断过滤条件是否满足,不满足则不计算。*/
|
||||
/* 2. 遍历指标,进行计算。*/
|
||||
/* 2.1 如果指标中包含了分组类型,则在result中维护分组。*/
|
||||
/* 2.2 指标包含了筛选条件,满足筛选条件时记录数据, 否则直接记录数据。*/
|
||||
$this->result += 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +97,7 @@ class baseMetric
|
||||
*/
|
||||
public function getResult()
|
||||
{
|
||||
return (object)array('value' => $this->result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,22 +9,31 @@
|
||||
* @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_developed_story_in_execution
|
||||
class count_of_developed_story_in_execution extends baseMetric
|
||||
{
|
||||
public $dao = null;
|
||||
public $result = array();
|
||||
|
||||
public function getResult()
|
||||
public function getStatement($dao)
|
||||
{
|
||||
$executionCount = $this->dao->select('t2.project,count(t1.id) as count') ->from(TABLE_STORY)->alias('t1')
|
||||
return $dao->select('t2.project,count(t1.id) as value') ->from(TABLE_STORY)->alias('t1')
|
||||
->leftJoin(TABLE_PROJECTSTORY)->alias('t2')->on('t1.id=t2.story')
|
||||
->where('t1.stage')->in('developed,testing,tested,verified,released')
|
||||
->orWhere('(t1.stage')->eq('closed')
|
||||
->andWhere('t1.closedReason')->eq('done')
|
||||
->markRight(1)
|
||||
->groupBy('t2.project')
|
||||
->fetchPairs();
|
||||
unset($executionCount['']);
|
||||
return $executionCount;
|
||||
->groupBy('t2.project');
|
||||
}
|
||||
|
||||
public function calculate($data)
|
||||
{
|
||||
if($data->project == '' || $data->project == 0) return;
|
||||
$this->result[] = $data;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,4 @@ class count_of_closed_execution extends baseMetric
|
||||
{
|
||||
if($data->status == 'closed') $this->result ++;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,15 +14,27 @@ class count_of_closed_execution_in_year extends baseMetric
|
||||
{
|
||||
public $dataset = 'getAllExecutions';
|
||||
|
||||
public $fieldList = array('id');
|
||||
public $fieldList = array('id', 'closedDate', 'status');
|
||||
|
||||
public function calculate($data)
|
||||
{
|
||||
$this->result ++;
|
||||
if($data->status == 'closed')
|
||||
{
|
||||
$closedYear = substr($data->closedDate, 0, 4);
|
||||
if(empty($this->result[$closedYear])) $this->result[$closedYear] = 0;
|
||||
$this->result[$closedYear] ++;
|
||||
}
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
ksort($this->result);
|
||||
$records = array();
|
||||
foreach($this->result as $year => $value)
|
||||
{
|
||||
if($year == '0000') continue;
|
||||
$records[] = (object)array('year' => $year, 'value' => $value);
|
||||
}
|
||||
return $records;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,4 @@ class count_of_doing_execution extends baseMetric
|
||||
{
|
||||
if($data->status == 'doing') $this->result ++;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,4 @@ class count_of_execution extends baseMetric
|
||||
public $dataset = 'getAllExecutions';
|
||||
|
||||
public $fieldList = array('id');
|
||||
|
||||
public function calculate($data)
|
||||
{
|
||||
$this->result ++;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* 每年完成的执行总数。
|
||||
* 每年创建的执行总数。
|
||||
* Count of execution per year.
|
||||
*
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
@@ -14,20 +14,24 @@ class count_of_execution_in_year extends baseMetric
|
||||
{
|
||||
public $dataset = 'getAllExecutions';
|
||||
|
||||
public $fieldList = array('id', 'closedDate', 'status');
|
||||
public $fieldList = array('id', 'openedDate');
|
||||
|
||||
public function calculate($data)
|
||||
{
|
||||
if($data->status == 'closed')
|
||||
{
|
||||
$closedYear = substr($data->closedDate, 0, 10);
|
||||
if(empty($this->result[$closedYear])) $this->result[$closedYear] = 0;
|
||||
$this->result[$closedYear] ++;
|
||||
}
|
||||
$openedYear = substr($data->openedDate, 0, 4);
|
||||
if(empty($this->result[$openedYear])) $this->result[$openedYear] = 0;
|
||||
$this->result[$openedYear] ++;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
ksort($this->result);
|
||||
$records = array();
|
||||
foreach($this->result as $year => $value)
|
||||
{
|
||||
if($year == '0000') continue;
|
||||
$records[] = (object)array('year' => $year, 'value' => $value);
|
||||
}
|
||||
return $records;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,4 @@ class count_of_marker_release extends baseMetric
|
||||
{
|
||||
if(!empty($data->marker) and $data->marker == 1) $this->result ++;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,18 @@
|
||||
class count_of_product extends baseMetric
|
||||
{
|
||||
public $dao = null;
|
||||
public $result = 0;
|
||||
|
||||
public function getResult()
|
||||
public function getStatement($dao)
|
||||
{
|
||||
$record = $this->dao->select('count(id) as count')->from(TABLE_PRODUCT)
|
||||
return $dao->select('count(id) as count')->from(TABLE_PRODUCT)
|
||||
->where('deleted')->eq(0)
|
||||
->andWhere('shadow')->eq(0)
|
||||
->fetch();
|
||||
|
||||
return $record->count;
|
||||
->andWhere('shadow')->eq(0);
|
||||
}
|
||||
|
||||
public function calculate($data)
|
||||
{
|
||||
$this->result = $data->count;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,13 +20,21 @@ class count_of_release_in_year extends baseMetric
|
||||
|
||||
public function calculate($data)
|
||||
{
|
||||
$value = $data->createdDate;
|
||||
if(empty($this->result[$value])) $this->result[$value] = 0;
|
||||
$this->result[$value] ++;
|
||||
$closedYear = substr($data->createdDate, 0, 4);
|
||||
if(empty($this->result[$closedYear])) $this->result[$closedYear] = 0;
|
||||
$this->result[$closedYear] ++;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
ksort($this->result);
|
||||
$records = array();
|
||||
foreach($this->result as $year => $value)
|
||||
{
|
||||
if($year == '0000') continue;
|
||||
$records[] = (object)array('year' => $year, 'value' => $value);
|
||||
}
|
||||
|
||||
return $records;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,4 @@ class count_of_suspended_execution extends baseMetric
|
||||
{
|
||||
if($data->status == 'suspended') $this->result ++;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,4 @@ class count_of_wait_execution extends baseMetric
|
||||
{
|
||||
if($data->status == 'wait') $this->result ++;
|
||||
}
|
||||
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user