* Finish task#97137.

This commit is contained in:
qixinzhi
2023-07-12 07:25:12 +00:00
parent fec5fb2da5
commit ef56696cc7
3 changed files with 68 additions and 15 deletions
@@ -1,7 +1,7 @@
<?php
/**
* 按产品统计的年度新增用户需求数。
* .
* Count of annual created requirement in product.
*
* 范围:prod
* 对象:requirement
@@ -9,8 +9,8 @@
* 度量名称:按产品统计的年度新增用户需求数
* 单位:个
* 描述:产品中创建时间为某年的用户需求的个数求和
过滤已删除的用户需求
过滤已删除的产品
* 过滤已删除的用户需求
* 过滤已删除的产品
* 度量库:
* 收集方式:realtime
*
@@ -23,21 +23,38 @@
*/
class count_of_annual_created_requirement_in_product extends baseCalc
{
public $dataset = '';
public $dataset = 'getStories';
public $fieldList = array();
public $fieldList = array('t1.product', 't1.type', 't1.openedDate');
public $result = array();
//public function getStatement()
//{
//}
public function calculate($data)
{
$product = $data->product;
$type = $data->type;
$openedDate = $data->openedDate;
//public function calculate($data)
//{
//}
$year = substr($openedDate, 0, 4);
if($year == '0000') return;
//public function getResult()
//{
//}
}
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 = null)
{
$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,22 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 7) . '/test/lib/init.php';
include dirname(__FILE__, 4) . '/calc.class.php';
zdTable('story')->config('story_create')->gen(5000);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
/**
title=count_of_annual_created_requirement_in_product
cid=1
pid=1
*/
r(count($calc->getResult())) && p('') && e('232'); // 测试按产品的年度新增用户需求分组数。
r($calc->getResult(array('product' => '78', 'year' => '2021'))) && p('0:value') && e('10'); // 测试2021年产品78新增的用户需求数。
r($calc->getResult(array('product' => '84', 'year' => '2022'))) && p('0:value') && e('0'); // 测试2022年产品84新增的用户需求数。
r($calc->getResult(array('product' => '999', 'year' => '2021'))) && 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: (-10Y)-(-1M)-(+1w):-1D
type: timestamp
format: YYYY-MM-DD hh:mm:ss
...