Skip to content
Permalink
Browse files

Merge branch 'MDL-65634_36' of git://github.com/dmonllao/moodle into …

…MOODLE_36_STABLE
  • Loading branch information...
abgreeve committed May 23, 2019
2 parents d4fe51c + 474e5c5 commit e793a8e36803698a96fbcf8d0c738c05c681e70c
Showing with 38 additions and 0 deletions.
  1. +38 −0 lib/classes/analytics/target/course_dropout.php
@@ -203,6 +203,8 @@ public function is_valid_analysable(\core_analytics\analysable $course, $fortrai
*/
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 @@ public function is_valid_sample($sampleid, \core_analytics\analysable $course, $
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 @@ public function is_valid_sample($sampleid, \core_analytics\analysable $course, $
*/
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 @@ protected function calculate_sample($sampleid, \core_analytics\analysable $cours
}
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;
}
}

0 comments on commit e793a8e

Please sign in to comment.
You can’t perform that action at this time.