rate_of_test_finished_task.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_test_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. if($row->type != 'test') return;
  29. $this->result['total'] += 1;
  30. if($row->status == 'done' || $row->closedReason == 'done') $this->result['finished'] += 1;
  31. }
  32. public function getResult($options = array())
  33. {
  34. $total = $this->result['total'];
  35. $finished = $this->result['finished'];
  36. $rate = $total == 0 ? 0 : round($finished / $total, 4);
  37. $records = array(array('value' => $rate));
  38. return $this->filterByOptions($records, $options);
  39. }
  40. }