From 4b528f264668ce7fd635ef7ebc8eda4e5e222669 Mon Sep 17 00:00:00 2001 From: qixinzhi Date: Wed, 2 Aug 2023 09:05:22 +0000 Subject: [PATCH] * Finish task#99204. --- .../calc/project/rate/sv_in_waterfall.php | 67 +++++++++++++++++++ .../calc/project/rate/sv_in_waterfall.php.tmp | 42 ------------ .../calc/project/rate/sv_in_waterfall.php | 23 +++++++ .../project/scale/count_of_bug_in_project.php | 0 4 files changed, 90 insertions(+), 42 deletions(-) create mode 100644 module/metric/calc/project/rate/sv_in_waterfall.php delete mode 100644 module/metric/calc/project/rate/sv_in_waterfall.php.tmp create mode 100755 module/metric/test/calc/project/rate/sv_in_waterfall.php mode change 100644 => 100755 module/metric/test/calc/project/scale/count_of_bug_in_project.php diff --git a/module/metric/calc/project/rate/sv_in_waterfall.php b/module/metric/calc/project/rate/sv_in_waterfall.php new file mode 100644 index 0000000000..b66177c6a3 --- /dev/null +++ b/module/metric/calc/project/rate/sv_in_waterfall.php @@ -0,0 +1,67 @@ + + * @package + * @uses func + * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html) + * @Link https://www.zentao.net + */ +class sv_in_waterfall extends baseCalc +{ + public $result = array(); + + public function getStatement() + { + $task = $this->dao->select('project, SUM(estimate) as estimate, SUM(consumed) as consumed, SUM(`left`) as `left`') + ->from(TABLE_TASK) + ->where('deleted')->eq('0') + ->andWhere('parent')->ne('-1') + ->andWhere('status', true)->in('done,closed') + ->orWhere('closedReason')->eq('done') + ->markRight(1) + ->groupBy('project') + ->get(); + + return $this->dao->select('t1.id as project, t2.estimate, t2.consumed, t2.`left`') + ->from(TABLE_PROJECT)->alias('t1') + ->leftJoin("($task)")->alias('t2')->on('t1.id=t2.project') + ->where('t1.deleted')->eq('0') + ->andWhere('t1.type')->eq('project') + ->andWhere('t1.model')->eq('waterfall') + ->query(); + } + + public function calculate($row) + { + $project = $row->project; + $estimate = $row->estimate; + $consumed = $row->consumed; + $left = $row->left; + $total = $consumed + $left; + + $ev = $total == 0 ? 0 : round($consumed / $total * $estimate, 2); + $sv = $estimate == 0 ? 0 : round(($ev - $estimate) / $estimate, 4); + + if(!isset($this->result[$project])) $this->result[$project] = $sv; + } + + public function getResult($options = array()) + { + $records = $this->getRecords(array('project', 'value')); + return $this->filterByOptions($records, $options); + } +} diff --git a/module/metric/calc/project/rate/sv_in_waterfall.php.tmp b/module/metric/calc/project/rate/sv_in_waterfall.php.tmp deleted file mode 100644 index f805946ce4..0000000000 --- a/module/metric/calc/project/rate/sv_in_waterfall.php.tmp +++ /dev/null @@ -1,42 +0,0 @@ - - * @package - * @uses func - * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html) - * @Link https://www.zentao.net - */ -class sv_in_waterfall extends baseCalc -{ - public $dataset = null; - - public $fieldList = array(); - - //public funtion getStatement($dao) - //{ - //} - - public function calculate($row) - { - } - - public function getResult($options = array()) - { - $records = $this->getRecords(array('value')); - return $this->filterByOptions($records, $options); - } -} \ No newline at end of file diff --git a/module/metric/test/calc/project/rate/sv_in_waterfall.php b/module/metric/test/calc/project/rate/sv_in_waterfall.php new file mode 100755 index 0000000000..b1bd7f7dcb --- /dev/null +++ b/module/metric/test/calc/project/rate/sv_in_waterfall.php @@ -0,0 +1,23 @@ +#!/usr/bin/env php +config('waterfall', $useCommon = true, $levels = 4)->gen(10); +zdTable('project')->config('stage', $useCommon = true, $levels = 4)->gen(40, false); +zdTable('task')->config('task_waterfall', $useCommon = true, $levels = 4)->gen(1000); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=sv_in_waterfall +cid=1 +pid=1 + +*/ + +r(count($calc->getResult())) && p('') && e('5'); // 测试分组数。 + +r($calc->getResult(array('project' => '7'))) && p('0:value') && e('-0.3492'); // 测试项目7。 diff --git a/module/metric/test/calc/project/scale/count_of_bug_in_project.php b/module/metric/test/calc/project/scale/count_of_bug_in_project.php old mode 100644 new mode 100755