Skip to content

Commit

Permalink
Merge branch 'MDL-78488_402' of https://github.com/t-schroeder/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_402_STABLE
  • Loading branch information
junpataleta committed Jul 6, 2023
2 parents d5e8ce4 + 5014d7b commit 3e592b1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions question/classes/local/statistics/statistics_bulk_loader.php
Expand Up @@ -43,6 +43,15 @@ class statistics_bulk_loader {
* @return float[][] if a value is not available, it will be set to null.
*/
public static function load_aggregate_statistics(array $questionids, array $requiredstatistics): array {
// Prevent unnecessary statistics calculations.
if (empty($requiredstatistics)) {
$aggregates = [];
foreach ($questionids as $questionid) {
$aggregates[$questionid] = [];
}
return $aggregates;
}

$places = self::get_all_places_where_questions_were_attempted($questionids);

// Set up blank two-dimensional arrays to store the running totals. Indexed by questionid and field name.
Expand Down
27 changes: 27 additions & 0 deletions question/tests/local/statistics/statistics_bulk_loader_test.php
Expand Up @@ -567,4 +567,31 @@ public function test_load_question_discrimination_index(
$this->assertEqualsWithDelta($expectedaveragediscriminationindex[3],
$stats[$questions[4]->id]['discriminationindex'], self::PERCENT_DELTA);
}

/**
* Test with question statistics disabled
*/
public function test_statistics_disabled(): void {
$this->resetAfterTest();

// Prepare some quizzes and attempts. Exactly what is not important to this test.
$quiz1attempts = [$this->generate_attempt_answers([1, 0, 0, 0])];
$quiz2attempts = [$this->generate_attempt_answers([1, 1, 1, 1])];
[, , $questions] = $this->prepare_and_submit_quizzes($quiz1attempts, $quiz2attempts);

// Prepare some useful arrays.
$expectedstats = [
$questions[1]->id => [],
$questions[2]->id => [],
$questions[3]->id => [],
$questions[4]->id => [],
];
$questionids = array_keys($expectedstats);

// Ask to load no statistics at all.
$stats = statistics_bulk_loader::load_aggregate_statistics($questionids, []);

// Verify we got the right thing.
$this->assertEquals($expectedstats, $stats);
}
}

0 comments on commit 3e592b1

Please sign in to comment.