Merge branch 'MDL-59786_master' of git://github.com/dmonllao/moodle

This commit is contained in:
Dan Poltawski 2017-09-04 11:52:14 +01:00 committed by David Monllao
commit edb911984a
4 changed files with 49 additions and 9 deletions

View file

@ -115,7 +115,7 @@ class course_dropout extends \core_analytics\local\target\binary {
}
/**
* is_valid_analysable
* Discards courses that are not yet ready to be used for training or prediction.
*
* @param \core_analytics\analysable $course
* @param bool $fortraining
@ -147,13 +147,22 @@ class course_dropout extends \core_analytics\local\target\binary {
return get_string('nocourseendtime');
}
if ($course->get_end() < $course->get_start()) {
return get_string('errorendbeforestart', 'analytics');
}
// A course that lasts longer than 1 year probably have wrong start or end dates.
if ($course->get_end() - $course->get_start() > (YEARSECS + (WEEKSECS * 4))) {
return get_string('coursetoolong', 'analytics');
}
// Ongoing courses data can not be used to train.
if ($fortraining && !$course->is_finished()) {
return get_string('coursenotyetfinished');
}
if ($fortraining) {
// Not a valid target for training if there are not enough course accesses.
// Not a valid target for training if there are not enough course accesses between the course start and end dates.
$params = array('courseid' => $course->get_id(), 'anonymous' => 0, 'start' => $course->get_start(),
'end' => $course->get_end());
@ -178,14 +187,39 @@ class course_dropout extends \core_analytics\local\target\binary {
}
/**
* All student enrolments are valid.
* Discard student enrolments that are invalid.
*
* @param int $sampleid
* @param \core_analytics\analysable $course
* @param bool $fortraining
* @return true|string
* @return bool
*/
public function is_valid_sample($sampleid, \core_analytics\analysable $course, $fortraining = true) {
$userenrol = $this->retrieve('user_enrolments', $sampleid);
if ($userenrol->timeend && $course->get_start() > $userenrol->timeend) {
// Discard enrolments which time end is prior to the course start. This should get rid of
// old user enrolments that remain on the course.
return false;
}
$limit = $course->get_start() - (YEARSECS + (WEEKSECS * 4));
if (($userenrol->timestart && $userenrol->timestart < $limit) ||
(!$userenrol->timestart && $userenrol->timecreated < $limit)) {
// Following what we do in is_valid_sample, we will discard enrolments that last more than 1 academic year
// because they have incorrect start and end dates or because they are reused along multiple years
// without removing previous academic years students. This may not be very accurate because some courses
// can last just some months, but it is better than nothing and they will be flagged as drop out anyway
// in most of the cases.
return false;
}
if (($userenrol->timestart && $userenrol->timestart > $course->get_end()) ||
(!$userenrol->timestart && $userenrol->timecreated > $course->get_end())) {
// Discard user enrolments that starts after the analysable official end.
return false;
}
return true;
}

View file

@ -134,7 +134,7 @@ class no_teaching extends \core_analytics\local\target\binary {
* @param int $sampleid
* @param \core_analytics\analysable $analysable
* @param bool $fortraining
* @return true|string
* @return bool
*/
public function is_valid_sample($sampleid, \core_analytics\analysable $analysable, $fortraining = true) {