sv_weekly_in_waterfall.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * 按瀑布项目统计的截止本周的进度偏差率。
  4. * Sv weekly in waterfall.
  5. *
  6. * 范围:project
  7. * 对象:task
  8. * 目的:rate
  9. * 度量名称:按瀑布项目统计的截止本周的进度偏差率
  10. * 单位:%
  11. * 描述:按瀑布项目统计的截止本周的进度偏差率是用来衡量项目截止本周的进度与计划进度之间的差异。它通过计算已完成的工作量与计划工作量之间的差异来评估项目的进展情况。
  12. * 定义:复用: 按瀑布项目统计的截止本周已完成任务工作的预计工时(EV) 、按瀑布项目统计的截止本周的任务的计划完成工时(PV),公式: 按瀑布项目统计的截止本周的进度偏差率=(EV-PV)/PV*100%
  13. *
  14. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  15. * @author qixinzhi <qixinzhi@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 sv_weekly_in_waterfall extends baseCalc
  22. {
  23. public $result = array();
  24. public $reuse = true;
  25. public $reuseMetrics = array('pv' => 'pv_of_weekly_task_in_waterfall', 'ev' => 'ev_of_weekly_finished_task_in_waterfall');
  26. public $reuseRule = '({ev} - {pv}) / {pv}';
  27. public function calculate($metrics)
  28. {
  29. $pvs = $metrics['pv'];
  30. $evs = $metrics['ev'];
  31. if(empty($pvs) || empty($evs)) return false;
  32. $all = array_merge($pvs, $evs);
  33. $projects = array_column($all, 'project', 'project');
  34. $years = array_column($all, 'year', 'year');
  35. $weeks = array_column($all, 'week', 'week');
  36. $pvs = $this->generateUniqueKey($pvs);
  37. $evs = $this->generateUniqueKey($evs);
  38. foreach($projects as $project)
  39. {
  40. foreach($years as $year)
  41. {
  42. foreach($weeks as $week)
  43. {
  44. $key = "{$project}_{$year}_{$week}";
  45. $pv = isset($pvs[$key]) ? $pvs[$key] : 0;
  46. $ev = isset($evs[$key]) ? $evs[$key] : 0;
  47. if($pv == 0) continue;
  48. $this->result[$project] = array($year => array($week => round(($ev - $pv) / $pv, 4)));
  49. }
  50. }
  51. }
  52. }
  53. public function getResult($options = array())
  54. {
  55. $records = $this->getRecords(array('project', 'year', 'week', 'value'));
  56. return $this->filterByOptions($records, $options);
  57. }
  58. public function generateUniqueKey($records)
  59. {
  60. $uniqueKeyRecords = array();
  61. foreach($records as $record)
  62. {
  63. $key = "{$record['project']}_{$record['year']}_{$record['week']}";
  64. $uniqueKeyRecords[$key] = $record['value'];
  65. }
  66. return $uniqueKeyRecords;
  67. }
  68. }