Merge branch 'MDL-65634_36' of git://github.com/dmonllao/moodle into MOODLE_36_STABLE
This commit is contained in:
@@ -203,6 +203,8 @@ class course_dropout extends \core_analytics\local\target\binary {
|
||||
*/
|
||||
public function is_valid_sample($sampleid, \core_analytics\analysable $course, $fortraining = true) {
|
||||
|
||||
$now = time();
|
||||
|
||||
$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
|
||||
@@ -227,6 +229,16 @@ class course_dropout extends \core_analytics\local\target\binary {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($now < $userenrol->timestart && $userenrol->timestart) {
|
||||
// Discard enrolments whose start date is after now (no need to check timecreated > $now :P).
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$fortraining && $userenrol->timeend && $userenrol->timeend < $now) {
|
||||
// We don't want to generate predictions for finished enrolments.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -245,6 +257,11 @@ class course_dropout extends \core_analytics\local\target\binary {
|
||||
*/
|
||||
protected function calculate_sample($sampleid, \core_analytics\analysable $course, $starttime = false, $endtime = false) {
|
||||
|
||||
if ($this->enrolment_starts_after_calculation_start($sampleid, $starttime)) {
|
||||
// Discard user enrolments whose start date is after $starttime.
|
||||
return null;
|
||||
}
|
||||
|
||||
$userenrol = $this->retrieve('user_enrolments', $sampleid);
|
||||
|
||||
// We use completion as a success metric only when it is enabled.
|
||||
@@ -273,4 +290,25 @@ class course_dropout extends \core_analytics\local\target\binary {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the user enrolment created after this time range start time or starts after it?
|
||||
*
|
||||
* We need to identify these enrolments because the indicators can not be calculated properly
|
||||
* if the student enrolment started half way through this time range.
|
||||
*
|
||||
* User enrolments whose end date is before time() have already been discarded in
|
||||
* course_enrolments::is_valid_sample.
|
||||
*
|
||||
* @param int $sampleid
|
||||
* @param int $starttime
|
||||
* @return bool
|
||||
*/
|
||||
protected function enrolment_starts_after_calculation_start(int $sampleid, int $starttime) {
|
||||
$userenrol = $this->retrieve('user_enrolments', $sampleid);
|
||||
if ($userenrol->timestart && $userenrol->timestart > $starttime) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user