count_of_delayed_finished_task.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * 按系统统计的每日完成任务数。
  4. * Count of delayed finished task which finished.
  5. *
  6. * 范围:task
  7. * 对象:task
  8. * 目的:scale
  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 count_of_delayed_finished_task extends baseCalc
  22. {
  23. public $dataset = '';
  24. public $fieldList = array();
  25. public $result = array();
  26. public $dateCounts = array();
  27. public $startDate = '';
  28. public $endDate = '';
  29. public function calculate($row)
  30. {
  31. if(!empty($row->executionStartDate) && empty($this->startDate)) $this->startDate = $row->executionStartDate;
  32. if(!empty($row->executionEndDate) && empty($this->endDate)) $this->endDate = $row->executionEndDate;
  33. if(empty($row->finishedDate)) return false;
  34. $finishedDate = substr($row->finishedDate, 0, 10);
  35. if(!isset($this->dateCounts[$finishedDate])) $this->dateCounts[$finishedDate] = 0;
  36. $this->dateCounts[$finishedDate] ++;
  37. }
  38. public function getDatesBetween($startDate, $endDate)
  39. {
  40. $current = strtotime($startDate);
  41. $end = strtotime($endDate);
  42. $dates = [];
  43. while($current <= $end)
  44. {
  45. $dates[date('Y-m-d', $current)] = 0;
  46. $current += 86400;
  47. }
  48. return $dates;
  49. }
  50. public function getResult($options = array())
  51. {
  52. $dateList = $this->getDatesBetween($this->startDate, $this->endDate);
  53. foreach($dateList as $date => $value)
  54. {
  55. if(isset($this->dateCounts[$date])) $value = $this->dateCounts[$date];
  56. $this->result[$date] = $value;
  57. }
  58. $records = $this->getRecords(array('date', 'value'));
  59. return $this->filterByOptions($records, $options);
  60. }
  61. }