* Add metric and unit test: count_of_invalid_story_in_product.

This commit is contained in:
zhouxin
2023-07-13 13:22:13 +08:00
parent eb12e68918
commit 87c50cbe10
2 changed files with 53 additions and 18 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,27 @@
*/
class count_of_invalid_story_in_product extends baseCalc
{
public $dataset = '';
public $fieldList = array();
public $result = array();
//public function getStatement()
//{
//}
public function getStatement()
{
return $this->dao->select('t1.product,count(t1.id) as value')->from(TABLE_STORY)->alias('t1')
->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
->where('t1.deleted')->eq(0)
->andWhere('t2.deleted')->eq(0)
->andWhere('t1.status')->eq('closed')
->andWhere('t1.closedReason')->in('duplicate,willnotdo,bydesign,cancel')
->groupBy('t1.product')
->query();
}
//public function calculate($data)
//{
//}
public function calculate($row)
{
$this->result[] = $row;
}
//public function getResult()
//{
//}
}
public function getResult($options = array())
{
return $this->filterByOptions($this->result, $options);
}
}
@@ -0,0 +1,31 @@
#!/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_invalid_story_in_product
timeout=0
cid=1
- 测试分组数 @14
- 测试产品1无效需求数
- 第0条的value属性 @1
- 第1条的value属性 @1
- 第2条的value属性 @1
- 测试不存在产品的无效需求数 @0
*/
r(count($calc->getResult())) && p('') && e('14'); // 测试分组数
r($calc->getResult(array('product' => '1,2,5'))) && p('0:value;1:value;2:value') && e('1;1;1'); // 测试产品1无效需求数
r($calc->getResult(array('product' => '999,1000'))) && p('') && e('0'); // 测试不存在产品的无效需求数