cv_weekly_in_waterfall.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * 按瀑布项目统计的截止本周的成本偏差率。
  4. * Cv weekly in waterfall.
  5. *
  6. * 范围:project
  7. * 对象:task
  8. * 目的:rate
  9. * 度量名称:按瀑布项目统计的截止本周的成本偏差率
  10. * 单位:%
  11. * 描述:按瀑布项目统计的截止本周的成本偏差率用于衡量项目的实际成本与计划成本之间的差异。它通过计算已花费的成本与预计花费的成本之间的差异来评估项目的成本绩效。
  12. * 定义:复用: 按瀑布项目统计的截止本周已完成任务工作的预计工时、按瀑布项目统计的截止本周的实际花费工时(AC) 公式: 按瀑布项目统计的截止本周的成本偏差率=(EV-AC)/AC*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 cv_weekly_in_waterfall extends baseCalc
  22. {
  23. public $result = array();
  24. public $reuse = true;
  25. public $reuseMetrics = array('ac' => 'ac_of_weekly_all_in_waterfall', 'ev' => 'ev_of_weekly_finished_task_in_waterfall');
  26. public $reuseRule = '({ev} - {ac}) / {ac}';
  27. public function calculate($metrics)
  28. {
  29. $acs = $metrics['ac'];
  30. $evs = $metrics['ev'];
  31. if(empty($acs) || empty($evs)) return false;
  32. $all = array_merge($acs, $evs);
  33. $projects = array_column($all, 'project', 'project');
  34. $years = array_column($all, 'year', 'year');
  35. $weeks = array_column($all, 'week', 'week');
  36. $acs = $this->generateUniqueKey($acs);
  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. $ac = isset($acs[$key]) ? $acs[$key] : 0;
  46. $ev = isset($evs[$key]) ? $evs[$key] : 0;
  47. if($ac == 0) continue;
  48. $this->result[$project] = array($year => array($week => round(($ev - $ac) / $ac, 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. }