* @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_success_pipeline extends baseCalc { public $dataset = 'getCompile'; public $fieldList = array('t1.status', 't1.createdDate'); public $result = array(); public $successCompile = array(); public function calculate($row) { $createdDate = $row->createdDate; $year = $this->getYear($createdDate); if(!$year) return false; list($year, $month, $day) = explode('-', $createdDate); $day = substr($day, 0, 2); if(!isset($this->result[$year])) $this->result[$year] = array(); if(!isset($this->result[$year][$month])) $this->result[$year][$month] = array(); if(!isset($this->result[$year][$month][$day])) $this->result[$year][$month][$day] = 0; $this->result[$year][$month][$day] += 1; $date = substr($createdDate, 0, 10); if(!isset($this->successCompile[$date])) $this->successCompile[$date] = 0; if($row->status == 'success') $this->successCompile[$date] += 1; } public function getResult($options = array()) { foreach($this->successCompile as $date => $successCount) { list($year, $month, $day) = explode('-', $date); $count = $this->result[$year][$month][$day]; $this->result[$year][$month][$day] = $count ? round($successCount / $count, 4) : 0; } $records = $this->getRecords(array('year', 'month', 'day', 'value')); return $this->filterByOptions($records, $options); } }