* Finish task#97123.

This commit is contained in:
qixinzhi
2023-08-08 06:51:43 +00:00
parent 4772d0757b
commit ec8f7a79a7
2 changed files with 55 additions and 2 deletions
@@ -22,15 +22,44 @@
*/
class scale_of_annual_delivered_story_in_product extends baseCalc
{
public $dataset = '';
public $dataset = 'getDevStories';
public $fieldList = array();
public $fieldList = array('t1.product', 't1.stage', 't1.releasedDate', 't1.closedReason', 't1.closedDate', 't1.estimate');
public function calculate($row)
{
$product = $row->product;
$stage = $row->stage;
$releasedDate = $row->releasedDate;
$closedReason = $row->closedReason;
$closedDate = $row->closedDate;
$estimate = $row->estimate;
$year = null;
if($stage == 'released')
{
if(empty($releasedDate)) return false;
$year = substr($releasedDate, 0, 4);
if($year == '0000') return false;
}
if($closedReason == 'done')
{
if(empty($closedDate)) return false;
$year = substr($closedDate, 0, 4);
if($year == '0000') return false;
}
if(empty($year)) return false;
if(!isset($this->result[$product])) $this->result[$product] = array();
if(!isset($this->result[$product][$year])) $this->result[$product][$year] = 0;
$this->result[$product][$year] += $estimate;
}
public function getResult($options = array())
{
$records = $this->getRecords(array('product', 'year', 'value'));
return $this->filterByOptions($records, $options);
}
}
@@ -0,0 +1,24 @@
#!/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('story')->config('story_stage_closedreason', $useCommon = true, $levels = 4)->gen(2000);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
/**
title=scale_of_annual_delivered_story_in_product
cid=1
pid=1
*/
r(count($calc->getResult())) && p('') && e('18'); // 测试分组数。
r($calc->getResult(array('product' => '5', 'year' => '2014'))) && p('0:value') && e('7'); // 测试产品5 2014年。
r($calc->getResult(array('product' => '5', 'year' => '2015'))) && p('0:value') && e('108'); // 测试产品5 2015年。
r($calc->getResult(array('product' => '7', 'year' => '2015'))) && p('0:value') && e('20'); // 测试产品7 2015年。