Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Time splitting method that generates predictions 3 days after the analysable start.
19
 *
20
 * @package   core_analytics
21
 * @copyright 2019 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\time_splitting;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
/**
30
 * Time splitting method that generates predictions 3 days after the analysable start.
31
 *
32
 * @package   core_analytics
33
 * @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class ten_percent_after_start extends \core_analytics\local\time_splitting\after_start {
37
 
38
    /**
39
     * The time splitting method name.
40
     *
41
     * @return \lang_string
42
     */
43
    public static function get_name(): \lang_string {
44
        return new \lang_string('timesplitting:tenpercentafterstart');
45
    }
46
 
47
    /**
48
     * Extended as we require and end date here.
49
     *
50
     * @param \core_analytics\analysable $analysable
51
     * @return bool
52
     */
53
    public function is_valid_analysable(\core_analytics\analysable $analysable) {
54
 
55
        // We require an end date to calculate the 10%.
56
        if (!$analysable->get_end()) {
57
            return false;
58
        }
59
 
60
        return parent::is_valid_analysable($analysable);
61
    }
62
 
63
    /**
64
     * The period we should wait until we generate predictions for this.
65
     *
66
     * @throws \coding_exception
67
     * @param  \core_analytics\analysable $analysable
68
     * @return \DateInterval
69
     */
70
    protected function wait_period(\core_analytics\analysable $analysable) {
71
 
72
        if (!$analysable->get_end() || !$analysable->get_start()) {
73
            throw new \coding_exception('Analysables with no start or end should be discarded in is_valid_analysable.');
74
        }
75
 
76
        $diff = $analysable->get_end() - $analysable->get_start();
77
 
78
        // A 10% of $diff.
79
        return new \DateInterval('PT' . intval($diff / 10) . 'S');
80
    }
81
}