mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-65588 analytics: New models for student accesses
This commit is contained in:
parent
7d8ed90757
commit
2d9280e0df
21 changed files with 1079 additions and 89 deletions
|
@ -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 accesses since the start of the course.
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2019 David Monllaó {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_course\analytics\target;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* No accesses since the start of the course.
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2019 David Monllaó {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class no_access_since_course_start extends no_recent_accesses {
|
||||
|
||||
/**
|
||||
* Only past stuff whose start matches the course start.
|
||||
*
|
||||
* @param \core_analytics\local\time_splitting\base $timesplitting
|
||||
* @return bool
|
||||
*/
|
||||
public function can_use_timesplitting(\core_analytics\local\time_splitting\base $timesplitting): bool {
|
||||
return ($timesplitting instanceof \core_analytics\local\time_splitting\after_start);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('target:noaccesssincecoursestart', 'course');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body message for the insight.
|
||||
*
|
||||
* @param \context $context
|
||||
* @param string $contextname
|
||||
* @param \stdClass $user
|
||||
* @param \moodle_url $insighturl
|
||||
* @return array The plain text message and the HTML message
|
||||
*/
|
||||
public function get_insight_body(\context $context, string $contextname, \stdClass $user, \moodle_url $insighturl): array {
|
||||
global $OUTPUT;
|
||||
|
||||
$a = (object)['coursename' => $contextname, 'userfirstname' => $user->firstname];
|
||||
$fullmessage = get_string('noaccesssincestartinfomessage', 'course', $a) . PHP_EOL . PHP_EOL . $insighturl->out(false);
|
||||
$fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message',
|
||||
['url' => $insighturl->out(false), 'insightinfomessage' => get_string('noaccesssincestartinfomessage', 'course', $a)]
|
||||
);
|
||||
|
||||
return [$fullmessage, $fullmessagehtml];
|
||||
}
|
||||
|
||||
}
|
135
course/classes/analytics/target/no_recent_accesses.php
Normal file
135
course/classes/analytics/target/no_recent_accesses.php
Normal file
|
@ -0,0 +1,135 @@
|
|||
<?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 recent accesses.
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2019 David Monllaó {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_course\analytics\target;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* No recent accesses.
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2019 David Monllaó {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class no_recent_accesses extends course_enrolments {
|
||||
|
||||
/**
|
||||
* Machine learning backends are not required to predict.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function based_on_assumptions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('target:norecentaccesses', 'course');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body message for the insight.
|
||||
*
|
||||
* @param \context $context
|
||||
* @param string $contextname
|
||||
* @param \stdClass $user
|
||||
* @param \moodle_url $insighturl
|
||||
* @return array The plain text message and the HTML message
|
||||
*/
|
||||
public function get_insight_body(\context $context, string $contextname, \stdClass $user, \moodle_url $insighturl): array {
|
||||
global $OUTPUT;
|
||||
|
||||
$a = (object)['coursename' => $contextname, 'userfirstname' => $user->firstname];
|
||||
$fullmessage = get_string('norecentaccessesinfomessage', 'course', $a) . PHP_EOL . PHP_EOL . $insighturl->out(false);
|
||||
$fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message',
|
||||
['url' => $insighturl->out(false), 'insightinfomessage' => get_string('norecentaccessesinfomessage', 'course', $a)]
|
||||
);
|
||||
|
||||
return [$fullmessage, $fullmessagehtml];
|
||||
}
|
||||
|
||||
/**
|
||||
* Only past stuff whose start matches the course start.
|
||||
*
|
||||
* @param \core_analytics\local\time_splitting\base $timesplitting
|
||||
* @return bool
|
||||
*/
|
||||
public function can_use_timesplitting(\core_analytics\local\time_splitting\base $timesplitting): bool {
|
||||
return ($timesplitting instanceof \core_analytics\local\time_splitting\past_periodic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards courses that are not yet ready to be used for prediction.
|
||||
*
|
||||
* @param \core_analytics\analysable $course
|
||||
* @param bool $fortraining
|
||||
* @return true|string
|
||||
*/
|
||||
public function is_valid_analysable(\core_analytics\analysable $course, $fortraining = true) {
|
||||
|
||||
if (!$course->was_started()) {
|
||||
return get_string('coursenotyetstarted', 'course');
|
||||
}
|
||||
|
||||
if (!$this->students = $course->get_students()) {
|
||||
return get_string('nocoursestudents', 'course');
|
||||
}
|
||||
|
||||
if ($course->get_end() && $course->get_end() < $course->get_start()) {
|
||||
return get_string('errorendbeforestart', 'course');
|
||||
}
|
||||
|
||||
// Finished courses can not be used to get predictions.
|
||||
if (!$fortraining && $course->is_finished()) {
|
||||
return get_string('coursealreadyfinished', 'course');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the user has any read action in the course?
|
||||
*
|
||||
* @param int $sampleid
|
||||
* @param \core_analytics\analysable $analysable
|
||||
* @param int $starttime
|
||||
* @param int $endtime
|
||||
* @return float 0 -> accesses, 1 -> no accesses.
|
||||
*/
|
||||
protected function calculate_sample($sampleid, \core_analytics\analysable $analysable, $starttime = false, $endtime = false) {
|
||||
|
||||
$readactions = $this->retrieve('\core\analytics\indicator\any_course_access', $sampleid);
|
||||
if ($readactions == \core\analytics\indicator\any_course_access::get_min_value()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue