first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+139
View File
@@ -0,0 +1,139 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Courses analyser working at course level (insights for the course teachers).
*
* @package core
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\analyser;
defined('MOODLE_INTERNAL') || die();
/**
* Courses analyser working at course level (insights for the course teachers).
*
* @package core
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class courses extends \core_analytics\local\analyser\by_course {
/**
* Samples origin is course table.
*
* @return string
*/
public function get_samples_origin() {
return 'course';
}
/**
* Just one sample per analysable.
*
* @return bool
*/
public static function one_sample_per_analysable() {
return true;
}
/**
* Returns the analysable of a sample
*
* @param int $sampleid
* @return \core_analytics\analysable
*/
public function get_sample_analysable($sampleid) {
return \core_analytics\course::instance($sampleid);
}
/**
* This provides samples' course and context.
*
* @return string[]
*/
protected function provided_sample_data() {
return array('course', 'context');
}
/**
* Returns the context of a sample.
*
* @param int $sampleid
* @return \context
*/
public function sample_access_context($sampleid) {
return \context_course::instance($sampleid);
}
/**
* This will return just one course as we analyse 'by_course'.
*
* @param \core_analytics\analysable $course
* @return array
*/
public function get_all_samples(\core_analytics\analysable $course) {
$context = \context_course::instance($course->get_id());
// Just 1 sample per analysable.
return array(
array($course->get_id() => $course->get_id()),
array($course->get_id() => array('course' => $course->get_course_data(), 'context' => $context))
);
}
/**
* Returns samples data from sample ids.
*
* @param int[] $sampleids
* @return array
*/
public function get_samples($sampleids) {
global $DB;
list($sql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED);
$courses = $DB->get_records_select('course', "id $sql", $params);
$courseids = array_keys($courses);
$sampleids = array_combine($courseids, $courseids);
$courses = array_map(function($course) {
return array('course' => $course, 'context' => \context_course::instance($course->id));
}, $courses);
// No related data attached.
return array($sampleids, $courses);
}
/**
* Returns the sample description
*
* @param int $sampleid
* @param int $contextid
* @param array $sampledata
* @return array array(string, \renderable)
*/
public function sample_description($sampleid, $contextid, $sampledata) {
$description = format_string(
get_course_display_name_for_list($sampledata['course']), true, array('context' => $sampledata['context']));
$courseimage = new \pix_icon('i/course', get_string('course'));
return array($description, $courseimage);
}
}
@@ -0,0 +1,139 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Site courses analyser working at system level (insights for the site admin).
*
* @package core
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\analyser;
defined('MOODLE_INTERNAL') || die();
/**
* Site courses analyser working at system level (insights for the site admin).
*
* @package core
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class site_courses extends \core_analytics\local\analyser\sitewide {
/**
* Samples origin is course table.
*
* @return string
*/
public function get_samples_origin() {
return 'course';
}
/**
* Returns the sample analysable
*
* @param int $sampleid
* @return \core_analytics\analysable
*/
public function get_sample_analysable($sampleid) {
return new \core_analytics\site();
}
/**
* Data this analyer samples provide.
*
* @return string[]
*/
protected function provided_sample_data() {
return array('course', 'context');
}
/**
* Returns the sample context.
*
* @param int $sampleid
* @return \context
*/
public function sample_access_context($sampleid) {
return \context_system::instance();
}
/**
* Returns all site courses.
*
* @param \core_analytics\analysable $site
* @return array
*/
public function get_all_samples(\core_analytics\analysable $site) {
global $DB;
// Getting courses from DB instead of from the site as these samples
// will be stored in memory and we just want the id.
$select = 'id != 1';
$courses = get_courses('all', 'c.sortorder ASC');
unset($courses[SITEID]);
$courseids = array_keys($courses);
$sampleids = array_combine($courseids, $courseids);
$courses = array_map(function($course) {
return array('course' => $course, 'context' => \context_course::instance($course->id));
}, $courses);
// No related data attached.
return array($sampleids, $courses);
}
/**
* Return all complete samples data from sample ids.
*
* @param int[] $sampleids
* @return array
*/
public function get_samples($sampleids) {
global $DB;
list($sql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED);
$courses = $DB->get_records_select('course', "id $sql", $params);
$courseids = array_keys($courses);
$sampleids = array_combine($courseids, $courseids);
$courses = array_map(function($course) {
return array('course' => $course, 'context' => \context_course::instance($course->id));
}, $courses);
// No related data attached.
return array($sampleids, $courses);
}
/**
* Returns the description of a sample.
*
* @param int $sampleid
* @param int $contextid
* @param array $sampledata
* @return array array(string, \renderable)
*/
public function sample_description($sampleid, $contextid, $sampledata) {
$description = format_string(
get_course_display_name_for_list($sampledata['course']), true, array('context' => $sampledata['context']));
$courseimage = new \pix_icon('i/course', get_string('course'));
return array($description, $courseimage);
}
}
@@ -0,0 +1,251 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Student enrolments analyser.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\analyser;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/lib/enrollib.php');
/**
* Student enrolments analyser.
*
* It does return all student enrolments including the suspended ones.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class student_enrolments extends \core_analytics\local\analyser\by_course {
/**
* @var array Cache for user_enrolment id - course id relation.
*/
protected $samplecourses = array();
/**
* Defines the origin of the samples in the database.
*
* @return string
*/
public function get_samples_origin() {
return 'user_enrolments';
}
/**
* Returns the student enrolment course context.
*
* @param int $sampleid
* @return \context
*/
public function sample_access_context($sampleid) {
return \context_course::instance($this->get_sample_courseid($sampleid));
}
/**
* Returns the student enrolment course.
*
* @param int $sampleid
* @return \core_analytics\analysable
*/
public function get_sample_analysable($sampleid) {
$course = enrol_get_course_by_user_enrolment_id($sampleid);
return \core_analytics\course::instance($course);
}
/**
* Data provided by get_all_samples & get_samples.
*
* @return string[]
*/
protected function provided_sample_data() {
return array('user_enrolments', 'context', 'course', 'user');
}
/**
* We need to delete associated data if a user requests his data to be deleted.
*
* @return bool
*/
public function processes_user_data() {
return true;
}
/**
* Join the samples origin table with the user id table.
*
* @param string $sampletablealias
* @return string
*/
public function join_sample_user($sampletablealias) {
return "JOIN {user_enrolments} ue ON {$sampletablealias}.sampleid = ue.id " .
"JOIN {user} u ON u.id = ue.userid";
}
/**
* All course student enrolments.
*
* It does return all student enrolments including the suspended ones.
*
* @param \core_analytics\analysable $course
* @return array
*/
public function get_all_samples(\core_analytics\analysable $course) {
$enrolments = enrol_get_course_users($course->get_id());
// We fetch all enrolments, but we are only interested in students.
$studentids = $course->get_students();
$samplesdata = array();
foreach ($enrolments as $userenrolmentid => $user) {
if (empty($studentids[$user->id])) {
// Not a student or an analysed one.
continue;
}
$sampleid = $userenrolmentid;
$samplesdata[$sampleid]['user_enrolments'] = (object)array(
'id' => $user->ueid,
'status' => $user->uestatus,
'enrolid' => $user->ueenrolid,
'userid' => $user->id,
'timestart' => $user->uetimestart,
'timeend' => $user->uetimeend,
'modifierid' => $user->uemodifierid,
'timecreated' => $user->uetimecreated,
'timemodified' => $user->uetimemodified
);
unset($user->ueid);
unset($user->uestatus);
unset($user->ueenrolid);
unset($user->uetimestart);
unset($user->uetimeend);
unset($user->uemodifierid);
unset($user->uetimecreated);
unset($user->uetimemodified);
// This student has been already analysed. We analyse each student once.
unset($studentids[$user->id]);
$samplesdata[$sampleid]['course'] = $course->get_course_data();
$samplesdata[$sampleid]['context'] = $course->get_context();
$samplesdata[$sampleid]['user'] = $user;
// Fill the cache.
$this->samplecourses[$sampleid] = $course->get_id();
}
$enrolids = array_keys($samplesdata);
return array(array_combine($enrolids, $enrolids), $samplesdata);
}
/**
* Returns all samples from the samples ids.
*
* @param int[] $sampleids
* @return array
*/
public function get_samples($sampleids) {
global $DB;
$enrolments = enrol_get_course_users(false, false, array(), $sampleids);
// Some course enrolments.
list($enrolsql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED);
$samplesdata = array();
foreach ($enrolments as $userenrolmentid => $user) {
$sampleid = $userenrolmentid;
$samplesdata[$sampleid]['user_enrolments'] = (object)array(
'id' => $user->ueid,
'status' => $user->uestatus,
'enrolid' => $user->ueenrolid,
'userid' => $user->id,
'timestart' => $user->uetimestart,
'timeend' => $user->uetimeend,
'modifierid' => $user->uemodifierid,
'timecreated' => $user->uetimecreated,
'timemodified' => $user->uetimemodified
);
unset($user->ueid);
unset($user->uestatus);
unset($user->ueenrolid);
unset($user->uetimestart);
unset($user->uetimeend);
unset($user->uemodifierid);
unset($user->uetimecreated);
unset($user->uetimemodified);
// Enrolment samples are grouped by the course they belong to, so all $sampleids belong to the same
// course, $courseid and $coursemodinfo will only query the DB once and cache the course data in memory.
$courseid = $this->get_sample_courseid($sampleid);
$coursemodinfo = get_fast_modinfo($courseid);
$coursecontext = \context_course::instance($courseid);
$samplesdata[$sampleid]['course'] = $coursemodinfo->get_course();
$samplesdata[$sampleid]['context'] = $coursecontext;
$samplesdata[$sampleid]['user'] = $user;
// Fill the cache.
$this->samplecourses[$sampleid] = $coursemodinfo->get_course()->id;
}
$enrolids = array_keys($samplesdata);
return array(array_combine($enrolids, $enrolids), $samplesdata);
}
/**
* Returns the student enrolment course id.
*
* @param int $sampleid
* @return int
*/
protected function get_sample_courseid($sampleid) {
global $DB;
if (empty($this->samplecourses[$sampleid])) {
$course = enrol_get_course_by_user_enrolment_id($sampleid);
$this->samplecourses[$sampleid] = $course->id;
}
return $this->samplecourses[$sampleid];
}
/**
* Returns the visible name of a sample + a renderable to display as sample picture.
*
* @param int $sampleid
* @param int $contextid
* @param array $sampledata
* @return array array(string, \renderable)
*/
public function sample_description($sampleid, $contextid, $sampledata) {
$description = fullname($sampledata['user'], true, array('context' => $contextid));
return array($description, new \user_picture($sampledata['user']));
}
}
+192
View File
@@ -0,0 +1,192 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Users analyser (insights for users).
*
* @package core
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\analyser;
defined('MOODLE_INTERNAL') || die();
/**
* Users analyser (insights for users).
*
* @package core
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class users extends \core_analytics\local\analyser\base {
/**
* The site users are the analysable elements returned by this analyser.
*
* @param string|null $action 'prediction', 'training' or null if no specific action needed.
* @param \context[] $contexts Only analysables that depend on the provided contexts. All analysables in the system if empty.
* @return \Iterator
*/
public function get_analysables_iterator(?string $action = null, array $contexts = []) {
global $DB, $CFG;
$siteadmins = explode(',', $CFG->siteadmins);
list($sql, $params) = $this->get_iterator_sql('user', CONTEXT_USER, $action, 'u', $contexts);
$sql .= " AND u.deleted = :deleted AND u.confirmed = :confirmed AND u.suspended = :suspended";
$params = $params + ['deleted' => 0, 'confirmed' => 1, 'suspended' => 0];
$ordersql = $this->order_sql('timecreated', 'ASC', 'u');
$recordset = $DB->get_recordset_sql($sql, $params);
if (!$recordset->valid()) {
$this->add_log(get_string('nousersfound'));
return new \ArrayIterator([]);
}
return new \core\dml\recordset_walk($recordset, function($record) use ($siteadmins) {
if (in_array($record->id, $siteadmins) || isguestuser($record->id)) {
// Skip admins and the guest user.
return false;
}
$context = \context_helper::preload_from_record($record);
return \core_analytics\user::instance($record, $context);
});
}
/**
* Just one sample per analysable.
*
* @return bool
*/
public static function one_sample_per_analysable() {
return true;
}
/**
* Samples origin is user table.
*
* @return string
*/
public function get_samples_origin() {
return 'user';
}
/**
* Returns the analysable of a sample
*
* @param int $sampleid
* @return \core_analytics\analysable
*/
public function get_sample_analysable($sampleid) {
return \core_analytics\user::instance($sampleid);
}
/**
* This provides samples' user and context.
*
* @return string[]
*/
protected function provided_sample_data() {
return ['user', 'context'];
}
/**
* Returns the context of a sample.
*
* @param int $sampleid
* @return \context
*/
public function sample_access_context($sampleid) {
return \context_user::instance($sampleid);
}
/**
* This will return just one user as we analyse users separately.
*
* @param \core_analytics\analysable $user
* @return array
*/
public function get_all_samples(\core_analytics\analysable $user) {
$context = \context_user::instance($user->get_id());
// Just 1 sample per analysable.
return [
[$user->get_id() => $user->get_id()],
[$user->get_id() => ['user' => $user->get_user_data(), 'context' => $context]]
];
}
/**
* Returns samples data from sample ids.
*
* @param int[] $sampleids
* @return array
*/
public function get_samples($sampleids) {
global $DB;
list($sql, $params) = $DB->get_in_or_equal($sampleids, SQL_PARAMS_NAMED);
$users = $DB->get_records_select('user', "id $sql", $params);
$userids = array_keys($users);
$sampleids = array_combine($userids, $userids);
$users = array_map(function($user) {
return ['user' => $user, 'context' => \context_user::instance($user->id)];
}, $users);
// No related data attached.
return [$sampleids, $users];
}
/**
* Returns the description of a sample.
*
* @param int $sampleid
* @param int $contextid
* @param array $sampledata
* @return array array(string, \renderable)
*/
public function sample_description($sampleid, $contextid, $sampledata) {
$description = fullname($sampledata['user']);
return [$description, new \user_picture($sampledata['user'])];
}
/**
* We need to delete associated data if a user requests his data to be deleted.
*
* @return bool
*/
public function processes_user_data() {
return true;
}
/**
* Join the samples origin table with the user id table.
*
* @param string $sampletablealias
* @return string
*/
public function join_sample_user($sampletablealias) {
return "JOIN {user} u ON u.id = {$sampletablealias}.sampleid";
}
}
@@ -0,0 +1,88 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Any access after the official end of the course.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Any access after the official end of the course.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class any_access_after_end extends \core_analytics\local\indicator\binary {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:accessesafterend');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
return array('user', 'course', 'context');
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $samplesorigin
* @param int $starttime
* @param int $endtime
* @return float
*/
protected function calculate_sample($sampleid, $samplesorigin, $starttime = false, $endtime = false) {
global $DB;
$user = $this->retrieve('user', $sampleid);
$course = \core_analytics\course::instance($this->retrieve('course', $sampleid));
// Filter by context to use the db table index.
$context = $this->retrieve('context', $sampleid);
$select = "userid = :userid AND contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid AND " .
"timecreated > :end";
$params = array('userid' => $user->id, 'contextlevel' => $context->contextlevel,
'contextinstanceid' => $context->instanceid, 'end' => $course->get_end());
$logstore = \core_analytics\manager::get_analytics_logstore();
$nlogs = $logstore->get_events_select_count($select, $params);
if ($nlogs) {
return self::get_max_value();
} else {
return self::get_min_value();
}
}
}
@@ -0,0 +1,91 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Any access before the official start of the course.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Any access before the official start of the course.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class any_access_before_start extends \core_analytics\local\indicator\binary {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:accessesbeforestart');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
return array('user', 'course', 'context');
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $samplesorigin
* @param int $starttime
* @param int $endtime
* @return float
*/
protected function calculate_sample($sampleid, $samplesorigin, $starttime = false, $endtime = false) {
global $DB;
$user = $this->retrieve('user', $sampleid);
$course = \core_analytics\course::instance($this->retrieve('course', $sampleid));
if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
throw new \coding_exception('No available log stores');
}
// Filter by context to use the logstore_standard_log db table index.
$context = $this->retrieve('context', $sampleid);
$select = "userid = :userid AND contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid AND " .
"timecreated < :start";
$params = array('userid' => $user->id, 'contextlevel' => $context->contextlevel,
'contextinstanceid' => $context->instanceid, 'start' => $course->get_start());
$nlogs = $logstore->get_events_select_count($select, $params);
if ($nlogs) {
return self::get_max_value();
} else {
return self::get_min_value();
}
}
}
@@ -0,0 +1,138 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Any access indicator.
*
* @package core
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Any access indicator.
*
* @package core
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class any_course_access extends \core_analytics\local\indicator\binary {
/** @var array user last access. */
protected $lastaccesses = [];
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:anycourseaccess');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
return array('course', 'user');
}
/**
* Store userid => timeaccess relation if the provided analysable is a course.
*
* @param \core_analytics\analysable $analysable
* @return null
*/
public function fill_per_analysable_caches(\core_analytics\analysable $analysable) {
global $DB;
if ($analysable instanceof \core_analytics\course) {
// Indexed by userid (there is a UNIQUE KEY at DB level).
$this->lastaccesses = $DB->get_records('user_lastaccess', ['courseid' => $analysable->get_id()],
'', 'userid, timeaccess');
}
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $sampleorigin
* @param int $starttime
* @param int $endtime
* @return float
*/
protected function calculate_sample($sampleid, $sampleorigin, $starttime = false, $endtime = false) {
$course = $this->retrieve('course', $sampleid);
$user = $this->retrieve('user', $sampleid);
// We first try using user_lastaccess as it is much faster than the log table.
if (empty($this->lastaccesses[$user->id]->timeaccess)) {
// The user never accessed.
return self::get_min_value();
} else if (!$starttime && !$endtime) {
// No time restrictions, so all good as long as there is a record.
return self::get_max_value();
} else if ($starttime && $this->lastaccesses[$user->id]->timeaccess < $starttime) {
// The last access is prior to $starttime.
return self::get_min_value();
} else if ($endtime && $this->lastaccesses[$user->id]->timeaccess < $endtime) {
// The last access is before the $endtime.
return self::get_max_value();
} else if ($starttime && !$endtime && $starttime <= $this->lastaccesses[$user->id]->timeaccess) {
// No end time, so max value as long as the last access is after $starttime.
return self::get_max_value();
}
// If the last access is after $endtime we can not know for sure if the user accessed or not
// between $starttime and $endtime, we need to check the logs table in this case. Note that
// it is unlikely that we will reach this point as this indicator will be used in models whose
// dates are in the past.
if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
throw new \coding_exception('No available log stores');
}
// Filter by context to use the logstore_standard_log db table index.
$select = "userid = :userid AND courseid = :courseid";
$params = ['courseid' => $course->id, 'userid' => $user->id];
if ($starttime) {
$select .= " AND timecreated > :starttime";
$params['starttime'] = $starttime;
}
if ($endtime) {
$select .= " AND timecreated <= :endtime";
$params['endtime'] = $endtime;
}
$nlogs = $logstore->get_events_select_count($select, $params);
if ($nlogs) {
return self::get_max_value();
} else {
return self::get_min_value();
}
}
}
@@ -0,0 +1,106 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Write actions indicator.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Write actions indicator.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class any_write_action extends \core_analytics\local\indicator\binary {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:anywrite');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
// User is not required, calculate_sample can handle its absence.
return array('context');
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $sampleorigin
* @param int $starttime
* @param int $endtime
* @return float
*/
protected function calculate_sample($sampleid, $sampleorigin, $starttime = false, $endtime = false) {
global $DB;
$select = '';
$params = array();
if ($user = $this->retrieve('user', $sampleid)) {
$select .= "userid = :userid AND ";
$params = $params + array('userid' => $user->id);
}
if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
throw new \coding_exception('No available log stores');
}
// Filter by context to use the logstore_standard_log db table index.
$context = $this->retrieve('context', $sampleid);
$select .= "contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid AND " .
"(crud = 'c' OR crud = 'u')";
$params = $params + array('contextlevel' => $context->contextlevel,
'contextinstanceid' => $context->instanceid);
if ($starttime) {
$select .= " AND timecreated > :starttime";
$params['starttime'] = $starttime;
}
if ($endtime) {
$select .= " AND timecreated <= :endtime";
$params['endtime'] = $endtime;
}
$nlogs = $logstore->get_events_select_count($select, $params);
if ($nlogs) {
return self::get_max_value();
} else {
return self::get_min_value();
}
}
}
@@ -0,0 +1,101 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Write actions in a course indicator.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Write actions in a course indicator.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class any_write_action_in_course extends \core_analytics\local\indicator\binary {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:anywriteincourse');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
// User is not required, calculate_sample can handle its absence.
return array('course');
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $sampleorigin
* @param int $starttime
* @param int $endtime
* @return float
*/
protected function calculate_sample($sampleid, $sampleorigin, $starttime = false, $endtime = false) {
global $DB;
if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
throw new \coding_exception('No available log stores');
}
// Filter by context to use the logstore_standard_log db table index.
$course = $this->retrieve('course', $sampleid);
$select = "courseid = :courseid AND anonymous = :anonymous AND (crud = 'c' OR crud = 'u')";
$params = array('courseid' => $course->id, 'anonymous' => '0');
if ($user = $this->retrieve('user', $sampleid)) {
$select .= " AND userid = :userid";
$params['userid'] = $user->id;
}
if ($starttime) {
$select .= " AND timecreated > :starttime";
$params['starttime'] = $starttime;
}
if ($endtime) {
$select .= " AND timecreated <= :endtime";
$params['endtime'] = $endtime;
}
$nlogs = $logstore->get_events_select_count($select, $params);
if ($nlogs) {
return self::get_max_value();
} else {
return self::get_min_value();
}
}
}
@@ -0,0 +1,114 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Read actions indicator.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Read actions indicator.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class read_actions extends \core_analytics\local\indicator\linear {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:readactions');
}
/**
* required_sample_data
*
* @return string[]
*/
public static function required_sample_data() {
// User is not required, calculate_sample can handle its absence.
return array('context');
}
/**
* calculate_sample
*
* @param int $sampleid
* @param string $sampleorigin
* @param int $starttime
* @param int $endtime
* @return float
*/
protected function calculate_sample($sampleid, $sampleorigin, $starttime = false, $endtime = false) {
if (!$starttime || !$endtime) {
return null;
}
$select = '';
$params = array();
if ($user = $this->retrieve('user', $sampleid)) {
$select .= "userid = :userid AND ";
$params = $params + array('userid' => $user->id);
}
if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
throw new \coding_exception('No available log stores');
}
// Filter by context to use the logstore_standard_log db table index.
$context = $this->retrieve('context', $sampleid);
$select .= "contextlevel = :contextlevel AND contextinstanceid = :contextinstanceid AND " .
"crud = 'r' AND timecreated > :starttime AND timecreated <= :endtime";
$params = $params + array('contextlevel' => $context->contextlevel,
'contextinstanceid' => $context->instanceid, 'starttime' => $starttime, 'endtime' => $endtime);
$nrecords = $logstore->get_events_select_count($select, $params);
// We define a list of ranges to fit $nrecords into it
// # Done absolutely nothing
// # Not much really, just accessing the course once a week
// # More than just accessing the course, some interaction
// # Significant contribution, will depend on the course anyway.
// We need to adapt the limits to the time range duration.
$nweeks = $this->get_time_range_weeks_number($starttime, $endtime);
// Careful with this, depends on the course.
$limit = $nweeks * 3 * 10;
$ranges = array(
array('eq', 0),
// 1 course access per week (3 records are easily generated).
array('le', $nweeks * 3),
// 3 course accesses per week doing some stuff.
array('le', $limit),
array('gt', $limit)
);
return $this->classify_value($nrecords, $ranges);
}
}
@@ -0,0 +1,59 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 10 parts time splitting method.
*
* @package core
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* 10 parts time splitting method.
*
* @package core
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class deciles extends \core_analytics\local\time_splitting\equal_parts {
/**
* Returns a lang_string object representing the name for the time splitting method.
*
* Used as column identificator.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:deciles');
}
/**
* 10 parts.
*
* @return int
*/
protected function get_number_parts() {
return 10;
}
}
@@ -0,0 +1,59 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Range processor splitting the course in ten parts and accumulating data.
*
* @package core
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Range processor splitting the course in ten parts and accumulating data.
*
* @package core
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class deciles_accum extends \core_analytics\local\time_splitting\accumulative_parts {
/**
* Returns a lang_string object representing the name for the time splitting method.
*
* Used as column identificator.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:decilesaccum');
}
/**
* 10 parts.
*
* @return int
*/
protected function get_number_parts() {
return 10;
}
}
@@ -0,0 +1,80 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* No time splitting method.
*
* Used when time is not a factor to consider into the equation.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* No time splitting method.
*
* Used when time is not a factor to consider into the equation.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class no_splitting extends \core_analytics\local\time_splitting\base {
/**
* Returns a lang_string object representing the name for the time splitting method.
*
* Used as column identificator.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:nosplitting');
}
/**
* ready_to_predict
*
* @param array $range
* @return true
*/
public function ready_to_predict($range) {
return true;
}
/**
* define_ranges
*
* @return array
*/
protected function define_ranges() {
return [
[
'start' => 0,
'end' => \core_analytics\analysable::MAX_TIME,
// Time is ignored as we overwrite ready_to_predict.
'time' => 0
]
];
}
}
@@ -0,0 +1,56 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Time splitting method that generates predictions one month after the analysable start.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Time splitting method that generates predictions one month after the analysable start.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class one_month_after_start extends \core_analytics\local\time_splitting\after_start {
/**
* The time splitting method name.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:onemonthafterstart');
}
/**
* The period we should wait until we generate predictions for this.
*
* @param \core_analytics\analysable $analysable Not used in this implementation.
* @return \DateInterval
*/
protected function wait_period(\core_analytics\analysable $analysable) {
return new \DateInterval('P1M');
}
}
@@ -0,0 +1,56 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Time splitting method that generates predictions one week after the analysable start.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Time splitting method that generates predictions one week after the analysable start.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class one_week_after_start extends \core_analytics\local\time_splitting\after_start {
/**
* The time splitting method name.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:oneweekafterstart');
}
/**
* The period we should wait until we generate predictions for this.
*
* @param \core_analytics\analysable $analysable Not used in this implementation.
* @return \DateInterval
*/
protected function wait_period(\core_analytics\analysable $analysable) {
return new \DateInterval('P1W');
}
}
@@ -0,0 +1,55 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Time splitting method that generates predictions every 3 days.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Time splitting method that generates predictions every 3 days.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class past_3_days extends \core_analytics\local\time_splitting\past_periodic {
/**
* The time splitting method name.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:past3days');
}
/**
* Once every 3 days.
*
* @return \DateInterval
*/
public function periodicity() {
return new \DateInterval('P3D');
}
}
@@ -0,0 +1,55 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Time splitting method that generates monthly predictions.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Time splitting method that generates monthly predictions.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class past_month extends \core_analytics\local\time_splitting\past_periodic {
/**
* The time splitting method name.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:pastmonth');
}
/**
* Once a month.
*
* @return \DateInterval
*/
public function periodicity() {
return new \DateInterval('P1M');
}
}
@@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Time splitting method that generates weekly predictions.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Time splitting method that generates weekly predictions.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class past_week extends \core_analytics\local\time_splitting\past_periodic {
/**
* The time splitting method name.
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:pastweek');
}
/**
* Once per week.
*
* @return \DateInterval
*/
public function periodicity() {
return new \DateInterval('P1W');
}
}
@@ -0,0 +1,59 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Quarters time splitting method.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Quarters time splitting method.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quarters extends \core_analytics\local\time_splitting\equal_parts {
/**
* Returns a lang_string object representing the name for the time spliting method.
*
* Used as column identificator.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:quarters');
}
/**
* 4 parts
*
* @return int
*/
protected function get_number_parts() {
return 4;
}
}
@@ -0,0 +1,59 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Range processor splitting the course in quarters and accumulating data.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Range processor splitting the course in quarters and accumulating data.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quarters_accum extends \core_analytics\local\time_splitting\accumulative_parts {
/**
* Returns a lang_string object representing the name for the time spliting method.
*
* Used as column identificator.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:quartersaccum');
}
/**
* 4 parts.
*
* @return int
*/
protected function get_number_parts() {
return 4;
}
}
@@ -0,0 +1,67 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Single time splitting method.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Single time splitting method.
*
* @package core
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class single_range extends \core_analytics\local\time_splitting\base
implements \core_analytics\local\time_splitting\before_now {
/**
* Returns a lang_string object representing the name for the time spliting method.
*
* Used as column identificator.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:singlerange');
}
/**
* One single range covering all analysable duration.
*
* @return array
*/
protected function define_ranges() {
// Key 'time' == 0 because we want it to start predicting from the beginning.
return [
[
'start' => $this->analysable->get_start(),
'end' => $this->analysable->get_end(),
'time' => 0
]
];
}
}
@@ -0,0 +1,81 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Time splitting method that generates predictions 3 days after the analysable start.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Time splitting method that generates predictions 3 days after the analysable start.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class ten_percent_after_start extends \core_analytics\local\time_splitting\after_start {
/**
* The time splitting method name.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:tenpercentafterstart');
}
/**
* Extended as we require and end date here.
*
* @param \core_analytics\analysable $analysable
* @return bool
*/
public function is_valid_analysable(\core_analytics\analysable $analysable) {
// We require an end date to calculate the 10%.
if (!$analysable->get_end()) {
return false;
}
return parent::is_valid_analysable($analysable);
}
/**
* The period we should wait until we generate predictions for this.
*
* @throws \coding_exception
* @param \core_analytics\analysable $analysable
* @return \DateInterval
*/
protected function wait_period(\core_analytics\analysable $analysable) {
if (!$analysable->get_end() || !$analysable->get_start()) {
throw new \coding_exception('Analysables with no start or end should be discarded in is_valid_analysable.');
}
$diff = $analysable->get_end() - $analysable->get_start();
// A 10% of $diff.
return new \DateInterval('PT' . intval($diff / 10) . 'S');
}
}
@@ -0,0 +1,53 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Time splitting method that generates insights every three days and calculates indicators using upcoming dates.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Time splitting method that generates insights every three days and calculates indicators using upcoming dates.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class upcoming_3_days extends \core_analytics\local\time_splitting\upcoming_periodic {
/**
* The time splitting method name.
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:upcoming3days');
}
/**
* Once every three days.
* @return \DateInterval
*/
public function periodicity() {
return new \DateInterval('P3D');
}
}
@@ -0,0 +1,53 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Time splitting method that generates insights every fortnight and calculates indicators using upcoming dates.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Time splitting method that generates insights every fortnight and calculates indicators using upcoming dates.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class upcoming_fortnight extends \core_analytics\local\time_splitting\upcoming_periodic {
/**
* The time splitting method name.
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:upcomingfortnight');
}
/**
* Every two weeks.
* @return \DateInterval
*/
public function periodicity() {
return new \DateInterval('P2W');
}
}
@@ -0,0 +1,53 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Time splitting method that generates weekly predictions.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\analytics\time_splitting;
defined('MOODLE_INTERNAL') || die();
/**
* Time splitting method that generates weekly predictions.
*
* @package core_analytics
* @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class upcoming_week extends \core_analytics\local\time_splitting\upcoming_periodic {
/**
* The time splitting method name.
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('timesplitting:upcomingweek');
}
/**
* Once per week.
* @return \DateInterval
*/
public function periodicity() {
return new \DateInterval('P1W');
}
}