1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Range processor splitting the course in parts and accumulating data from the start. 19 * 20 * @package core_analytics 21 * @copyright 2017 David Monllao {@link http://www.davidmonllao.com} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core_analytics\local\time_splitting; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 /** 30 * Range processor splitting the course in parts and accumulating data from the start. 31 * 32 * @package core_analytics 33 * @copyright 2017 David Monllao {@link http://www.davidmonllao.com} 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 abstract class accumulative_parts extends base implements before_now { 37 38 /** 39 * The number of parts to split the analysable duration in. 40 * 41 * @return int 42 */ 43 abstract protected function get_number_parts(); 44 45 /** 46 * define_ranges 47 * 48 * @return array 49 */ 50 protected function define_ranges() { 51 52 $nparts = $this->get_number_parts(); 53 54 $rangeduration = ($this->analysable->get_end() - $this->analysable->get_start()) / $nparts; 55 56 $ranges = array(); 57 for ($i = 0; $i < $nparts; $i++) { 58 $end = $this->analysable->get_start() + intval($rangeduration * ($i + 1)); 59 if ($i === ($nparts - 1)) { 60 // Better to use the end for the last one as we are using floor above. 61 $end = $this->analysable->get_end(); 62 } 63 $ranges[$i] = array( 64 'start' => $this->analysable->get_start(), 65 'end' => $end, 66 'time' => $end 67 ); 68 } 69 70 return $ranges; 71 } 72 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body