avg_of_compile_time_pipeline.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * 按系统统计的流水线执行平均耗时。
  4. * Avg of compile time pipeline.
  5. *
  6. * 范围:system
  7. * 对象:pipeline
  8. * 目的:rate
  9. * 度量名称:按系统统计的流水线执行数
  10. * 单位:小时
  11. * 描述:按系统统计的流水线执行平均耗时是指在一定时间内的流水线执行时间/执行的数量,通过统计在一定时间范围内每次流水线执行的耗时,并计算出平均值,团队能够深入了解构建和部署过程的性能,及时识别潜在的瓶颈并优化工作流程。
  12. * 定义:系统的流水线执行时间/执行数量 不统计已删除代码库 不统计已删除流水线
  13. *
  14. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  15. * @author liyang <liyang@easycorp.ltd>
  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 avg_of_compile_time_pipeline extends baseCalc
  22. {
  23. public $dataset = 'getCompile';
  24. public $fieldList = array('t1.createdDate', 't1.updateDate');
  25. public $result = array();
  26. public $compileTime = array();
  27. public function calculate($row)
  28. {
  29. $createdDate = $row->createdDate;
  30. $updateDate = $row->updateDate;
  31. $year = $this->getYear($createdDate);
  32. if(!$year) return false;
  33. list($year, $month, $day) = explode('-', $createdDate);
  34. $day = substr($day, 0, 2);
  35. if(!isset($this->result[$year])) $this->result[$year] = array();
  36. if(!isset($this->result[$year][$month])) $this->result[$year][$month] = array();
  37. if(!isset($this->result[$year][$month][$day])) $this->result[$year][$month][$day] = 0;
  38. $date = substr($createdDate, 0, 10);
  39. if(!isset($this->compileTime[$date])) $this->compileTime[$date] = array();
  40. $this->compileTime[$date][] = strtotime($updateDate) - strtotime($createdDate);
  41. }
  42. public function getResult($options = array())
  43. {
  44. foreach($this->compileTime as $date => $data)
  45. {
  46. $avgTime = count($data) ? round(array_sum($data) / count($data), 2) : 0;
  47. list($year, $month, $day) = explode('-', $date);
  48. $this->result[$year][$month][$day] = $avgTime ? $avgTime / 3600 : 0;
  49. }
  50. $records = $this->getRecords(array('year', 'month', 'day', 'value'));
  51. return $this->filterByOptions($records, $options);
  52. }
  53. }