rate_of_finished_task.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * 按系统统计的任务完成率。
  4. * Rate of finished task.
  5. *
  6. * 范围:system
  7. * 对象:task
  8. * 目的:rate
  9. * 度量名称:按系统统计的任务完成率
  10. * 单位:%
  11. * 描述:按系统统计的任务完成率是指已完成的任务占相对于任务数量的比例。
  12. * 定义:按系统统计的已完成任务数;按系统统计的任务数;公式:已完成任务数÷任务数;
  13. *
  14. * @copyright Copyright 2009-2025 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  15. * @author Yanyi Cao <caoyanyi@chandao.com>
  16. * @package
  17. * @uses func
  18. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  19. * @Link https://www.zentao.net
  20. */
  21. class rate_of_finished_task extends baseCalc
  22. {
  23. public $dataset = '';
  24. public $fieldList = array();
  25. public $result = array('finished' => 0, 'total' => 0);
  26. public function calculate($row)
  27. {
  28. $this->result['total'] += 1;
  29. if($row->status == 'done' || $row->closedReason == 'done') $this->result['finished'] += 1;
  30. }
  31. public function getResult($options = array())
  32. {
  33. $total = $this->result['total'];
  34. $finished = $this->result['finished'];
  35. $rate = $total == 0 ? 0 : round($finished / $total, 4);
  36. $records = array(array('value' => $rate));
  37. return $this->filterByOptions($records, $options);
  38. }
  39. }