* @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 avg_of_compile_time_pipeline extends baseCalc { public $dataset = 'getCompile'; public $fieldList = array('t1.createdDate', 't1.updateDate'); public $result = array(); public $compileTime = array(); public function calculate($row) { $createdDate = $row->createdDate; $updateDate = $row->updateDate; $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; $date = substr($createdDate, 0, 10); if(!isset($this->compileTime[$date])) $this->compileTime[$date] = array(); $this->compileTime[$date][] = strtotime($updateDate) - strtotime($createdDate); } public function getResult($options = array()) { foreach($this->compileTime as $date => $data) { $avgTime = count($data) ? round(array_sum($data) / count($data), 2) : 0; list($year, $month, $day) = explode('-', $date); $this->result[$year][$month][$day] = $avgTime ? $avgTime / 3600 : 0; } $records = $this->getRecords(array('year', 'month', 'day', 'value')); return $this->filterByOptions($records, $options); } }