* Add metric and unit test: count_of_annual_created_story_in_product.

This commit is contained in:
zhouxin
2023-07-13 13:55:35 +08:00
parent 007aea79ed
commit 477e7c208e
2 changed files with 71 additions and 16 deletions
@@ -8,14 +8,12 @@
* 目的:scale
* 度量名称:按产品统计的年度新增研发需求数
* 单位:个
* 描述:产品中创建时间为某年的研发需求的个数求和
过滤已删除的研发需求
过滤已删除的产品
* 描述:产品中创建时间为某年的研发需求的个数求和 过滤已删除的研发需求 过滤已删除的产品
* 度量库:
* 收集方式:realtime
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @author qixinzhi <qixinzhi@easycorp.ltd>
* @author zhouxin <zhouxin@easycorp.ltd>
* @package
* @uses func
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
@@ -23,21 +21,41 @@
*/
class count_of_annual_created_story_in_product extends baseCalc
{
public $dataset = '';
public $dataset = 'getStories';
public $fieldList = array();
public $fieldList = array('t1.product', 't1.openedDate');
public $result = array();
//public function getStatement()
//{
//}
public function calculate($row)
{
$product = $row->product;
$openedDate = $row->openedDate;
//public function calculate($data)
//{
//}
$year = substr($openedDate, 0, 4);
//public function getResult()
//{
//}
}
if(empty($year) || $year == '0000') return;
if(!isset($this->result[$product])) $this->result[$product] = array();
if(!isset($this->result[$product][$year])) $this->result[$product][$year] = 0;
$this->result[$product][$year] += 1;
}
public function getResult($options = array())
{
$records = array();
foreach($this->result as $product => $years)
{
foreach($years as $year => $value)
{
$records[] = array(
'product' => $product,
'year' => $year,
'value' => $value,
);
}
}
return $this->filterByOptions($records, $options);
}
}
@@ -0,0 +1,37 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 7) . '/test/lib/init.php';
include dirname(__FILE__, 4) . '/calc.class.php';
zdTable('story')->gen(100);
zdTable('product')->gen(100);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
/**
title=count_of_annual_created_story_in_product
timeout=0
cid=1
- 测试分组数. @25
- 测试2023年产品1,2,3创建的需求数。
- 第0条的value属性 @4
- 第1条的value属性 @4
- 第2条的value属性 @4
- 测试2023年产品4,5,6创建的需求数。
- 第0条的value属性 @4
- 第1条的value属性 @4
- 第2条的value属性 @4
- 测试不存在的年份创建的需求数。 @0
*/
r(count($calc->getResult())) && p('') && e('25'); // 测试分组数.
r($calc->getResult(array('product' => '1,2,3', 'year' => '2022,2023'))) && p('0:value;1:value;2:value') && e('4,4,4'); // 测试2023年产品1,2,3创建的需求数。
r($calc->getResult(array('product' => '4,5,6', 'year' => '2022,2023'))) && p('0:value;1:value;2:value') && e('4,4,4'); // 测试2023年产品4,5,6创建的需求数。
r($calc->getResult(array('product' => '1,2,3', 'year' => '2022'))) && p('') && e('0'); // 测试不存在的年份创建的需求数。