diff --git a/module/metric/calc/project/hour/day_of_invested_in_project.php.tmp b/module/metric/calc/project/hour/day_of_invested_in_project.php similarity index 53% rename from module/metric/calc/project/hour/day_of_invested_in_project.php.tmp rename to module/metric/calc/project/hour/day_of_invested_in_project.php index 0fcec92618..3ab871a0bb 100644 --- a/module/metric/calc/project/hour/day_of_invested_in_project.php.tmp +++ b/module/metric/calc/project/hour/day_of_invested_in_project.php @@ -1,7 +1,7 @@ dao->select('value') + ->from(TABLE_CONFIG) + ->where('module')->eq('execution') + ->andWhere('key')->eq('defaultWorkhours') + ->fetch('value'); - //public funtion getStatement($dao) - //{ - //} + return $this->dao->select("t3.id as project, SUM(t1.consumed) as consumed, $defaultHours as defaultHours") + ->from(TABLE_EFFORT)->alias('t1') + ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.execution=t2.id') + ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t2.project=t3.id') + ->where('t3.deleted')->eq('0') + ->andWhere('t3.type')->eq('project') + ->groupBy('t3.id') + ->query(); + } public function calculate($row) { + $project = $row->project; + $consumed = $row->consumed; + $defaultHours = $row->defaultHours; + + if(!isset($this->result[$project])) $this->result[$project] = round($consumed / $defaultHours, 2); } public function getResult($options = array()) { - $records = $this->getRecords(array('value')); + $records = $this->getRecords(array('project', 'value')); return $this->filterByOptions($records, $options); } -} \ No newline at end of file +} diff --git a/module/metric/test/calc/project/hour/day_of_invested_in_project.php b/module/metric/test/calc/project/hour/day_of_invested_in_project.php new file mode 100755 index 0000000000..7969dc8cb7 --- /dev/null +++ b/module/metric/test/calc/project/hour/day_of_invested_in_project.php @@ -0,0 +1,23 @@ +#!/usr/bin/env php +config('project', $useCommon = true, $levels = 4)->gen(10); +zdTable('project')->config('sprint', $useCommon = true, $levels = 4)->gen(40, false); +zdTable('effort')->config('effort', $useCommon = true, $levels = 4)->gen(1000); + +$metric = new metricTest(); +$calc = $metric->calcMetric(__FILE__); + +/** + +title=day_of_invested_in_project +cid=1 +pid=1 + +*/ + +r(count($calc->getResult())) && p('') && e('5'); // 测试分组数。 + +r($calc->getResult(array('project' => '7'))) && p('0:value') && e('27.87'); // 测试项目7。