rate_of_success_pipeline.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * 按系统统计的流水线执行成功率。
  4. * Rate of success 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 rate_of_success_pipeline extends baseCalc
  22. {
  23. public $dataset = 'getCompile';
  24. public $fieldList = array('t1.status', 't1.createdDate');
  25. public $result = array();
  26. public $successCompile = array();
  27. public function calculate($row)
  28. {
  29. $createdDate = $row->createdDate;
  30. $year = $this->getYear($createdDate);
  31. if(!$year) return false;
  32. list($year, $month, $day) = explode('-', $createdDate);
  33. $day = substr($day, 0, 2);
  34. if(!isset($this->result[$year])) $this->result[$year] = array();
  35. if(!isset($this->result[$year][$month])) $this->result[$year][$month] = array();
  36. if(!isset($this->result[$year][$month][$day])) $this->result[$year][$month][$day] = 0;
  37. $this->result[$year][$month][$day] += 1;
  38. $date = substr($createdDate, 0, 10);
  39. if(!isset($this->successCompile[$date])) $this->successCompile[$date] = 0;
  40. if($row->status == 'success') $this->successCompile[$date] += 1;
  41. }
  42. public function getResult($options = array())
  43. {
  44. foreach($this->successCompile as $date => $successCount)
  45. {
  46. list($year, $month, $day) = explode('-', $date);
  47. $count = $this->result[$year][$month][$day];
  48. $this->result[$year][$month][$day] = $count ? round($successCount / $count, 4) : 0;
  49. }
  50. $records = $this->getRecords(array('year', 'month', 'day', 'value'));
  51. return $this->filterByOptions($records, $options);
  52. }
  53. }