* Finish task#98015.

This commit is contained in:
qixinzhi
2023-07-21 08:01:28 +00:00
parent 9f17cb3b9b
commit d84a0a468e
2 changed files with 71 additions and 8 deletions
@@ -10,9 +10,9 @@
* 单位:h
* 描述:按全局统计的月度关闭项目的任务消耗工时数是指团队或组织在某月内预计需要花费的总工时数,用于完成任务。该度量项可以用来评估团队或组织在任务执行过程中的工时投入情况和对资源的利用效率。较高的月度关闭项目的任务消耗工时数可能需要审查工作流程和资源分配,以提高工作效率和进度控制。
* 定义:所有项目任务消耗工时数求和
项目状态为已关闭
关闭时间为某年某月
过滤已删除的项目
* 项目状态为已关闭
* 关闭时间为某年某月
* 过滤已删除的项目
* 度量库:
* 收集方式:realtime
*
@@ -29,16 +29,54 @@ class consume_of_monthly_closed_project extends baseCalc
public $fieldList = array();
//public funtion getStatement($dao)
//{
//}
public $result = array();
public function getStatement()
{
$task = $this->dao->select('SUM(consumed) as consumed, project')
->from(TABLE_TASK)
->where('deleted')->eq('0')
->andWhere('parent')->ne('-1')
->groupBy('project')
->get();
return $this->dao->select('t1.id as project, YEAR(t1.closedDate) as year, MONTH(t1.closedDate) as month, t2.consumed')
->from(TABLE_PROJECT)->alias('t1')
->leftJoin("($task)")->alias('t2')->on('t1.id = t2.project')
->where('t1.type')->eq('project')
->andWhere('t1.status')->eq('closed')
->andWhere('t1.deleted')->eq('0')
->andWhere('t1.closedDate IS NOT NULL')
->andWhere('YEAR(t1.closedDate)')->ne('0000')
->query();
}
public function calculate($data)
{
$project = $data->project;
$year = $data->year;
$month = $data->month;
$consumed = $data->consumed;
if(!isset($this->result[$year])) $this->result[$year] = array();
if(!isset($this->result[$year][$month])) $this->result[$year][$month] = array();
$this->result[$year][$month][$project] = round($consumed, 2);
}
public function getResult($options = array())
{
return $this->filterByOptions($this->result, $options);
$records = array();
foreach($this->result as $year => $months)
{
foreach($months as $month => $projects)
{
foreach($projects as $project => $value)
{
$records[] = array('project' => $project, 'year' => $year, 'month' => $month, 'value' => $value);
}
}
}
return $this->filterByOptions($records, $options);
}
}
}
@@ -0,0 +1,25 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 7) . '/test/lib/init.php';
include dirname(__FILE__, 4) . '/calc.class.php';
zdTable('project')->config('project_close', $useCommon = true, $levels = 4)->gen(80);
zdTable('task')->config('task_consumed', $useCommon = true, $levels = 4)->gen(1000);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
/**
title=consume_of_monthly_closed_project
timeout=0
cid=1
*/
r(count($calc->getResult())) && p('') && e('10'); // 测试分组数。
r($calc->getResult(array('project' => '1', 'year' => '2011', 'month' => '1'))) && p('0:value') && e('48'); // 测试2011年项目1任务消耗的工时数。
r($calc->getResult(array('project' => '9', 'year' => '2011', 'month' => '3'))) && p('0:value') && e('10'); // 测试2012年项目3任务消耗的工时数
r($calc->getResult(array('project' => '4', 'year' => '9999'))) && p('') && e('0'); // 测试不存在年份的反馈数