MDL-65829 analytics: Accept enrol start time after analysis time
This commit is contained in:
@@ -118,11 +118,6 @@ class course_competencies extends course_enrolments {
|
||||
*/
|
||||
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);
|
||||
|
||||
$key = $course->get_id();
|
||||
|
||||
@@ -96,10 +96,6 @@ class course_completion extends course_enrolments {
|
||||
*/
|
||||
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.
|
||||
|
||||
@@ -118,11 +118,6 @@ class course_dropout extends course_enrolments {
|
||||
*/
|
||||
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.
|
||||
|
||||
@@ -197,27 +197,4 @@ abstract class course_enrolments extends \core_analytics\local\target\binary {
|
||||
|
||||
return array_merge($actions, parent::prediction_actions($prediction, $includedetailsaction));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,11 +164,6 @@ class course_gradetopass extends course_enrolments {
|
||||
*/
|
||||
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);
|
||||
|
||||
// Get course grade to pass.
|
||||
|
||||
@@ -413,15 +413,11 @@ class core_analytics_targets_testcase extends advanced_testcase {
|
||||
$student1 = $dg->create_user();
|
||||
$student2 = $dg->create_user();
|
||||
$student3 = $dg->create_user();
|
||||
$student4 = $dg->create_user();
|
||||
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
|
||||
$dg->enrol_user($student1->id, $course1->id, $studentrole->id);
|
||||
$dg->enrol_user($student2->id, $course1->id, $studentrole->id);
|
||||
$dg->enrol_user($student3->id, $course1->id, $studentrole->id);
|
||||
|
||||
$enrolstart = mktime(0, 0, 0, 10, 25, 2015);
|
||||
$dg->enrol_user($student4->id, $course1->id, $studentrole->id, 'manual', $enrolstart);
|
||||
|
||||
// get_all_samples() does not guarantee any order, so let's
|
||||
// explicitly define the expectations here for later comparing.
|
||||
// Expectations format being array($userid => expectation, ...)
|
||||
@@ -439,9 +435,6 @@ class core_analytics_targets_testcase extends advanced_testcase {
|
||||
// Student 3 (has no grade) fails, so it's non achieved sample.
|
||||
$expectations[$student3->id] = 1;
|
||||
|
||||
// Student 4 should be null as its enrolment timestart is after the this range.
|
||||
$expectations[$student4->id] = null;
|
||||
|
||||
$courseitem->gradepass = 50;
|
||||
$DB->update_record('grade_items', $courseitem);
|
||||
|
||||
@@ -460,12 +453,9 @@ class core_analytics_targets_testcase extends advanced_testcase {
|
||||
$method = $class->getMethod('calculate_sample');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$starttime = mktime(0, 0, 0, 10, 24, 2015);
|
||||
|
||||
// Verify all the expectations are fulfilled.
|
||||
foreach ($sampleids as $sampleid => $key) {
|
||||
$this->assertEquals($expectations[$samplesdata[$key]['user']->id], $method->invoke($target, $sampleid,
|
||||
$analysable, $starttime));
|
||||
$this->assertEquals($expectations[$samplesdata[$key]['user']->id], $method->invoke($target, $sampleid, $analysable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user