Skip to content

Commit 840d6ba

Browse files
author
David Monllaó
committed
MDL-65829 analytics: Accept enrol start time after analysis time
1 parent 078699a commit 840d6ba

File tree

6 files changed

+1
-53
lines changed

6 files changed

+1
-53
lines changed

course/classes/analytics/target/course_competencies.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ public function is_valid_analysable(\core_analytics\analysable $course, $fortrai
118118
*/
119119
protected function calculate_sample($sampleid, \core_analytics\analysable $course, $starttime = false, $endtime = false) {
120120

121-
if ($this->enrolment_starts_after_calculation_start($sampleid, $starttime)) {
122-
// Discard user enrolments whose start date is after $starttime.
123-
return null;
124-
}
125-
126121
$userenrol = $this->retrieve('user_enrolments', $sampleid);
127122

128123
$key = $course->get_id();

course/classes/analytics/target/course_completion.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ public function is_valid_analysable(\core_analytics\analysable $course, $fortrai
9696
*/
9797
protected function calculate_sample($sampleid, \core_analytics\analysable $course, $starttime = false, $endtime = false) {
9898

99-
if ($this->enrolment_starts_after_calculation_start($sampleid, $starttime)) {
100-
// Discard user enrolments whose start date is after $starttime.
101-
return null;
102-
}
10399
$userenrol = $this->retrieve('user_enrolments', $sampleid);
104100

105101
// We use completion as a success metric.

course/classes/analytics/target/course_dropout.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ public function is_valid_analysable(\core_analytics\analysable $course, $fortrai
118118
*/
119119
protected function calculate_sample($sampleid, \core_analytics\analysable $course, $starttime = false, $endtime = false) {
120120

121-
if ($this->enrolment_starts_after_calculation_start($sampleid, $starttime)) {
122-
// Discard user enrolments whose start date is after $starttime.
123-
return null;
124-
}
125-
126121
$userenrol = $this->retrieve('user_enrolments', $sampleid);
127122

128123
// We use completion as a success metric only when it is enabled.

course/classes/analytics/target/course_enrolments.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -197,27 +197,4 @@ public function prediction_actions(\core_analytics\prediction $prediction, $incl
197197

198198
return array_merge($actions, parent::prediction_actions($prediction, $includedetailsaction));
199199
}
200-
201-
/**
202-
* Does the user enrolment created after this time range start time or starts after it?
203-
*
204-
* We need to identify these enrolments because the indicators can not be calculated properly
205-
* if the student enrolment started half way through this time range.
206-
*
207-
* User enrolments whose end date is before time() have already been discarded in
208-
* course_enrolments::is_valid_sample.
209-
*
210-
* @param int $sampleid
211-
* @param int $starttime
212-
* @return bool
213-
*/
214-
protected function enrolment_starts_after_calculation_start(int $sampleid, int $starttime) {
215-
216-
$userenrol = $this->retrieve('user_enrolments', $sampleid);
217-
if ($userenrol->timestart && $userenrol->timestart > $starttime) {
218-
return true;
219-
}
220-
221-
return false;
222-
}
223200
}

course/classes/analytics/target/course_gradetopass.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ public function is_valid_analysable(\core_analytics\analysable $course, $fortrai
164164
*/
165165
protected function calculate_sample($sampleid, \core_analytics\analysable $course, $starttime = false, $endtime = false) {
166166

167-
if ($this->enrolment_starts_after_calculation_start($sampleid, $starttime)) {
168-
// Discard user enrolments whose start date is after $starttime.
169-
return null;
170-
}
171-
172167
$userenrol = $this->retrieve('user_enrolments', $sampleid);
173168

174169
// Get course grade to pass.

lib/tests/targets_test.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,11 @@ public function test_core_target_course_gradetopass_calculate() {
413413
$student1 = $dg->create_user();
414414
$student2 = $dg->create_user();
415415
$student3 = $dg->create_user();
416-
$student4 = $dg->create_user();
417416
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
418417
$dg->enrol_user($student1->id, $course1->id, $studentrole->id);
419418
$dg->enrol_user($student2->id, $course1->id, $studentrole->id);
420419
$dg->enrol_user($student3->id, $course1->id, $studentrole->id);
421420

422-
$enrolstart = mktime(0, 0, 0, 10, 25, 2015);
423-
$dg->enrol_user($student4->id, $course1->id, $studentrole->id, 'manual', $enrolstart);
424-
425421
// get_all_samples() does not guarantee any order, so let's
426422
// explicitly define the expectations here for later comparing.
427423
// Expectations format being array($userid => expectation, ...)
@@ -439,9 +435,6 @@ public function test_core_target_course_gradetopass_calculate() {
439435
// Student 3 (has no grade) fails, so it's non achieved sample.
440436
$expectations[$student3->id] = 1;
441437

442-
// Student 4 should be null as its enrolment timestart is after the this range.
443-
$expectations[$student4->id] = null;
444-
445438
$courseitem->gradepass = 50;
446439
$DB->update_record('grade_items', $courseitem);
447440

@@ -460,12 +453,9 @@ public function test_core_target_course_gradetopass_calculate() {
460453
$method = $class->getMethod('calculate_sample');
461454
$method->setAccessible(true);
462455

463-
$starttime = mktime(0, 0, 0, 10, 24, 2015);
464-
465456
// Verify all the expectations are fulfilled.
466457
foreach ($sampleids as $sampleid => $key) {
467-
$this->assertEquals($expectations[$samplesdata[$key]['user']->id], $method->invoke($target, $sampleid,
468-
$analysable, $starttime));
458+
$this->assertEquals($expectations[$samplesdata[$key]['user']->id], $method->invoke($target, $sampleid, $analysable));
469459
}
470460
}
471461
}

0 commit comments

Comments
 (0)