模板定义
<?php
/**
* [度量项名称]。
* [度量项名称(英文)].
*
* 范围:[范围]
* 对象:[对象]
* 目的:[目的]
* 度量名称:[度量项名称]
* 单位:[单位]
* 描述:[描述度量项的含义]
* 定义:[描述度量项如何定义,计算规则等]
*/
class xxx_of_xxx_in_xxx extends baseCalc
{
/**
* 度量项计算临时结果。
*/
public $result = array();
/**
* 获取自定义数据源pdo句柄。
*/
public function getStatement()
{
return $this->dao->XXX->query();
}
/**
* 计算度量项。
*
* @param object $row 数据源的一行数据
*/
public function calculate($row)
{
* $this->result += 1; }
/**
* 汇总并获取度量项计算结果。
*
* @param array $options 筛选参数,如果不传参,则返回度量项所有数据
*/
public function getResult($options = array())
{
$records = $this->getRecords(array('value'));
return $this->filterByOptions($records, $options);
}
}
示例
<?php
/**
* 按全局统计的年度关闭项目的任务消耗工时数。
* Consume of annual closed project.
*
* 范围:global
* 对象:project
* 目的:hour
* 度量名称:按全局统计的年度关闭项目的任务消耗工时数
* 单位:h
* 描述:按全局统计的年度关闭项目的任务消耗工时数是指在某年度关闭的项目中团队或组织实际花费的总工时数,用于完成任务。该度量项可以用来评估团队或组织在任务执行过程中的工时投入情况和对资源的利用效率。较高的年度关闭项目的任务消耗工时数可能需要审查工作流程和资源分配,以提高工作效率和进度控制。
* 定义:所有项目任务的消耗工时数求和;项目状态为已关闭;关闭时间为某年;过滤已删除的项目;
*/
class consume_of_annual_closed_project extends baseCalc
{
public $dataset = null;
public $fieldList = array();
public $result = array();
public function getStatement()
{
$task = $this->dao->select('SUM(consumed) as consumed, project')
->from(TABLE_TASK)
->where('deleted')->eq('0')
->andWhere('parent')->ne('-1')
->groupBy('project')
->get();
return $this->dao->select('t1.id as project, LEFT(t1.closedDate, 4) as year, t2.consumed')
->from(TABLE_PROJECT)->alias('t1')
->leftJoin("($task)")->alias('t2')->on('t1.id = t2.project')
->where('t1.type')->eq('project')
->andWhere('t1.status')->eq('closed')
->andWhere('t1.deleted')->eq('0')
->andWhere('t1.closedDate IS NOT NULL')
->andWhere('LEFT(t1.closedDate, 4)')->ne('0000')
->query();
}
public function calculate($data)
{
$project = $data->project;
$year = $data->year;
$consumed = $data->consumed;
if(!isset($this->result[$year])) $this->result[$year] = array();
$this->result[$year][$project] = round($consumed, 2);
}
public function getResult($options = array())
{
$records = array();
foreach($this->result as $year => $projects)
{
foreach($projects as $project => $value)
{
$records[] = array('project' => $project, 'year' => $year, 'value' => $value);
}
}
return $this->filterByOptions($records, $options);
}
}