+ [task#142888,doing,0.3h] add rate metric for task finished rate.

This commit is contained in:
caoyanyi
2025-05-13 14:31:12 +08:00
committed by 刘刚
parent d1c597fba9
commit 0007e4cebe
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* 按系统统计的任务完成率。
* Rate of finished task.
*
* 范围:system
* 对象:task
* 目的:rate
* 度量名称:按系统统计的任务完成率
* 单位:%
* 描述:按系统统计的任务完成率是指已完成的任务占相对于任务数量的比例。
* 定义:按系统统计的已完成任务数;按系统统计的任务数;公式:已完成任务数÷任务数;
*
* @copyright Copyright 2009-2025 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @author Yanyi Cao <caoyanyi@chandao.com>
* @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 rate_of_finished_task extends baseCalc
{
public $dataset = '';
public $fieldList = array();
public $result = array('finished' => 0, 'total' => 0);
public function calculate($row)
{
$this->result['total'] += 1;
if($row->status == 'done' || $row->closedReason == 'done') $this->result['finished'] += 1;
}
public function getResult($options = array())
{
$total = $this->result['total'];
$finished = $this->result['finished'];
$rate = $total == 0 ? 0 : round($finished / $total, 4);
$records = array(array('value' => $rate));
return $this->filterByOptions($records, $options);
}
}