* Finish task#97959.

This commit is contained in:
qixinzhi
2023-07-20 08:28:17 +00:00
parent b7a91a1443
commit ef376ffec8
2 changed files with 46 additions and 9 deletions
@@ -10,8 +10,8 @@
* 单位:个
* 描述:按全局统计的年度新增发布数表示每年新增加的发布数量。该度量项反映了组织每年增加的发布数量,可以用于评估组织产品发布的速度和规模。
* 定义:所有的发布个数求和
发布时间为某年
过滤已删除的发布
* 发布时间为某年
* 过滤已删除的发布
* 度量库:
* 收集方式:realtime
*
@@ -24,20 +24,34 @@
*/
class count_of_annual_created_release extends baseCalc
{
public $dataset = null;
public $dataset = "getReleases";
public $fieldList = array();
public $fieldList = array('t1.date');
//public funtion getStatement($dao)
//{
//}
public $result = array();
public function calculate($data)
{
if(empty($data->date)) return;
$date = $data->date;
$year = substr($date, 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('release')->config('release', $useCommon = true, $levels = 4)->gen(1000);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
/**
title=count_of_annual_created_release
timeout=0
cid=1
*/
r(count($calc->getResult())) && p('') && e('11'); // 测试新增发布分组数。
r($calc->getResult(array('year' => '2019'))) && p('0:value') && e('18'); // 测试2019年新增发布数。
r($calc->getResult(array('year' => '2020'))) && p('0:value') && e('18'); // 测试2020年新增发布数。