From aef4d8b58b66761f9526719d3a124a413af6887c Mon Sep 17 00:00:00 2001 From: qixinzhi Date: Sun, 28 Apr 2024 05:53:32 +0000 Subject: [PATCH] * Fix cv_in_waterfall. --- .../calc/project/rate/cv_in_waterfall.php | 76 ++++++++++++------- .../calc/project/rate/sv_in_waterfall.php | 8 +- .../calc/project/rate/cv_in_waterfall.php | 8 +- 3 files changed, 55 insertions(+), 37 deletions(-) diff --git a/module/metric/calc/project/rate/cv_in_waterfall.php b/module/metric/calc/project/rate/cv_in_waterfall.php index e3466ccc4c..4558600e31 100755 --- a/module/metric/calc/project/rate/cv_in_waterfall.php +++ b/module/metric/calc/project/rate/cv_in_waterfall.php @@ -1,15 +1,15 @@ @@ -20,43 +20,61 @@ */ class cv_in_waterfall extends baseCalc { - public $dataset = 'getWaterfallTasks'; - - public $fieldList = array('t1.id as project', 't2.estimate', 't2.consumed', 't2.left', 't3.consumed as ac'); - public $result = array(); - public function calculate($row) + public $reuse = true; + + public $reuseMetrics = array('ac' => 'ac_of_all_in_waterfall', 'ev' => 'ev_of_finished_task_in_waterfall'); + + public $reuseRule = '({ev} - {ac}) / {ac}'; + + public function calculate($metrics) { - $project = $row->project; - $ac = $row->ac; + $acs = $metrics['ac']; + $evs = $metrics['ev']; + if(empty($acs) || empty($evs)) return false; - $estimate = (float)$row->estimate; - $consumed = (float)$row->consumed; - $left = (float)$row->left; - $total = $consumed + $left; + $all = array_merge($acs, $evs); - $ev = $total == 0 ? 0 : round($consumed / $total * $estimate, 2); + $projects = array_column($all, 'project', 'project'); + $years = array_column($all, 'year', 'year'); + $weeks = array_column($all, 'week', 'week'); - if(!isset($this->result[$project])) + $acs = $this->generateUniqueKey($acs); + $evs = $this->generateUniqueKey($evs); + + foreach($projects as $project) { - $this->result[$project]['ev'] = $ev; - $this->result[$project]['ac'] = $ac; + foreach($years as $year) + { + foreach($weeks as $week) + { + $key = "{$project}_{$year}_{$week}"; + $ac = isset($acs[$key]) ? $acs[$key] : 0; + $ev = isset($evs[$key]) ? $evs[$key] : 0; + + if($ac == 0) continue; + $this->result[$project] = array($year => array($week => round(($ev - $ac) / $ac, 4))); + } + } } } public function getResult($options = array()) { - $records = array(); - foreach($this->result as $project => $value) - { - $ac = (float)$value['ac']; - $ev = (float)$value['ev']; - - $ratio = $ac == 0 ? 0 : round(($ev - $ac) / $ac, 4); - - $records[] = array('project' => $project, 'value' => $ratio); - } + $records = $this->getRecords(array('project', 'year', 'week', 'value')); return $this->filterByOptions($records, $options); } + + public function generateUniqueKey($records) + { + $uniqueKeyRecords = array(); + foreach($records as $record) + { + $key = "{$record['project']}_{$record['year']}_{$record['week']}"; + $uniqueKeyRecords[$key] = $record['value']; + } + + return $uniqueKeyRecords; + } } diff --git a/module/metric/calc/project/rate/sv_in_waterfall.php b/module/metric/calc/project/rate/sv_in_waterfall.php index 2bdfd31cdd..f10ec57a2a 100755 --- a/module/metric/calc/project/rate/sv_in_waterfall.php +++ b/module/metric/calc/project/rate/sv_in_waterfall.php @@ -1,15 +1,15 @@ diff --git a/module/metric/test/calc/project/rate/cv_in_waterfall.php b/module/metric/test/calc/project/rate/cv_in_waterfall.php index fe8e94bae5..99d503a313 100755 --- a/module/metric/test/calc/project/rate/cv_in_waterfall.php +++ b/module/metric/test/calc/project/rate/cv_in_waterfall.php @@ -8,7 +8,7 @@ timeout=0 cid=1 - 测试分组数。 @5 -- 测试项目7。第0条的value属性 @-0.7799 +- 测试项目1。第0条的value属性 @45.6259 */ include dirname(__FILE__, 7) . '/test/lib/init.php'; @@ -17,11 +17,11 @@ include dirname(__FILE__, 4) . '/calc.class.php'; zdTable('project')->config('waterfall', true, 4)->gen(10); zdTable('project')->config('stage', true, 4)->gen(40, false); zdTable('task')->config('task_waterfall', true, 4)->gen(1000); -zdTable('effort')->config('effort', true, 4)->gen(1000); +zdTable('effort')->config('effort_ac', true, 4)->gen(1000); $metric = new metricTest(); $calc = $metric->calcMetric(__FILE__); -r(count($calc->getResult())) && p('') && e('5'); // 测试分组数。 +r(count($metric->getReuseCalcResult($calc))) && p('') && e('5'); // 测试分组数。 -r($calc->getResult(array('project' => '7'))) && p('0:value') && e('-0.7799'); // 测试项目7。 \ No newline at end of file +r($metric->getReuseCalcResult($calc, array('project' => '1', 'year' => '2024', 'week' => '05'))) && p('0:value') && e('45.6259'); // 测试项目1。 \ No newline at end of file