* Finish task#97954.

This commit is contained in:
qixinzhi
2023-07-21 05:37:09 +00:00
parent 2594fbe6b3
commit 340d0711f7
2 changed files with 44 additions and 9 deletions
@@ -10,8 +10,8 @@
* 单位:个
* 描述:按全局统计的年度关闭计划数表示每年关闭的计划数量。该度量项反映了组织每年关闭的计划数量,可以用于评估组织的计划管理效能和调整情况。
* 定义:所有的计划个数求和
关闭时间为某年
过滤已删除的计划
* 关闭时间为某年
* 过滤已删除的计划
* 度量库:
* 收集方式:realtime
*
@@ -24,20 +24,32 @@
*/
class count_of_annual_closed_productplan extends baseCalc
{
public $dataset = null;
public $dataset = 'getPlans';
public $fieldList = array();
public $fieldList = array('t1.closedDate');
//public funtion getStatement($dao)
//{
//}
public $result = array();
public function calculate($data)
{
$closedDate = $data->closedDate;
if(empty($closedDate)) return;
$year = substr($closedDate, 0, 4);
if($year == '0000') return;
if(!isset($this->result[$year])) $this->result[$year] = 0;
$this->result[$year] += 1;
}
public function getResult($options = array())
{
return $this->filterByOptions($this->result, $options);
$records = array();
foreach($this->result as $year => $value)
{
$records[] = array('year' => $year, 'value' => $value);
}
return $this->filterByOptions($records, $options);
}
}
}
@@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 7) . '/test/lib/init.php';
include dirname(__FILE__, 4) . '/calc.class.php';
zdTable('product')->config('product', $useCommon = true, $levels = 4)->gen(10);
zdTable('productplan')->config('productplan', $useCommon = true, $levels = 4)->gen(1000);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
/**
title=count_of_annual_closed_productplan
timeout=0
cid=1
*/
r(count($calc->getResult())) && p('') && e('11'); // 测试年度关闭产品计划分组数。
r($calc->getResult(array('year' => '2017'))) && p('0:value') && e('21'); // 测试2017年关闭产品计划数
r($calc->getResult(array('year' => '2019'))) && p('0:value') && e('19'); // 测试2019年关闭产品计划数
r($calc->getResult(array('year' => '2023'))) && p('0:value') && e('0'); // 测试2023年关闭产品计划数