* @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_story extends baseCalc { public $dataset = 'getAllDevStories'; public $fieldList = array('t1.status', 't1.closedReason'); public $result = array('finished' => 0, 'valid' => 0); public function calculate($row) { if(!isset($this->result['finished'])) $this->result['finished'] = 0; if(!isset($this->result['valid'])) $this->result['valid'] = 0; if($row->status == 'closed' and $row->closedReason == 'done') $this->result['finished'] ++; if(!in_array($row->closedReason, array('duplicate', 'willnotdo', 'bydesign', 'cancel'))) $this->result['valid'] ++; } public function getResult($options = array()) { $this->result = !empty($this->result['valid']) ? round($this->result['finished'] / $this->result['valid'], 4) : 0; $records = array(array('value' => $this->result)); return $this->filterByOptions($records, $options); } }