* Finish task#97120.

This commit is contained in:
qixinzhi
2023-07-13 08:56:28 +00:00
parent 00a0e78cab
commit feb3327105
3 changed files with 74 additions and 15 deletions
@@ -1,7 +1,7 @@
<?php
/**
* 按产品统计的月度新增研发需求数。
* .
* Count of monthly created story in product.
*
* 范围:product
* 对象:story
@@ -9,8 +9,8 @@
* 度量名称:按产品统计的月度新增研发需求数
* 单位:个
* 描述:产品中创建时间在某年某月的研发需求的个数求和
过滤已删除的研发需求
过滤已删除的产品
* 过滤已删除的研发需求
* 过滤已删除的产品
* 度量库:
* 收集方式:realtime
*
@@ -23,21 +23,43 @@
*/
class count_of_monthly_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($data)
{
$product = $data->product;
$openedDate = $data->openedDate;
//public function calculate($data)
//{
//}
$year = substr($openedDate, 0, 4);
$month = substr($openedDate, 5, 2);
//public function getResult()
//{
//}
}
if($year == '0000') return;
if(!isset($this->result[$product])) $this->result[$product] = array();
if(!isset($this->result[$product][$year])) $this->result[$product][$year] = array();
if(!isset($this->result[$product][$year][$month])) $this->result[$product][$year][$month] = 0;
$this->result[$product][$year][$month] += 1;
}
public function getResult($options = null)
{
$records = array();
foreach($this->result as $product => $years)
{
foreach($years as $year => $months)
{
foreach($months as $month => $value)
{
$records[] = array('product' => $product, 'year' => $year, 'month' => $month, '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')->gen(200);
zdTable('story')->config('story_close')->gen(5000);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
/**
title=count_of_monthly_opened_story_in_product
cid=1
pid=1
*/
r(count($calc->getResult())) && p('') && e('651'); // 测试按产品的月度新增需求分组数。
r($calc->getResult(array('product' => '16', 'year' => '2019', 'month' => '06'))) && p('0:value') && e('10'); // 测试2019年6月产品16新增的需求数。
r($calc->getResult(array('product' => '78', 'year' => '2020', 'month' => '08'))) && p('0:value') && e('10'); // 测试2020年8月产品78新增的需求数。
r($calc->getResult(array('product' => '999', 'year' => '2021', 'month' => '04'))) && p('') && e('0'); // 测试不存在的产品的需求数。
@@ -0,0 +1,14 @@
---
title: zt_story
author: qixinzhi
version: "1.0"
fields:
- field: id
range: 1-10000
- field: product
range: 1-100{10}
- field: openedDate
range: (-5Y)-(-10M)-(+1w):-1D
type: timestamp
format: YYYY-MM-DD hh:mm:ss
...