diff --git a/module/metric/calc/task/rate/rate_of_finished_task.php b/module/metric/calc/task/rate/rate_of_finished_task.php new file mode 100755 index 0000000000..0ccf5e31e0 --- /dev/null +++ b/module/metric/calc/task/rate/rate_of_finished_task.php @@ -0,0 +1,44 @@ + + * @package + * @uses func + * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html) + * @Link https://www.zentao.net + */ +class rate_of_finished_task extends baseCalc +{ + public $dataset = ''; + + public $fieldList = array(); + + public $result = array('finished' => 0, 'total' => 0); + + public function calculate($row) + { + $this->result['total'] += 1; + if($row->status == 'done' || $row->closedReason == 'done') $this->result['finished'] += 1; + } + + public function getResult($options = array()) + { + $total = $this->result['total']; + $finished = $this->result['finished']; + $rate = $total == 0 ? 0 : round($finished / $total, 4); + + $records = array(array('value' => $rate)); + return $this->filterByOptions($records, $options); + } +}