Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

Question statistics calculator class. Used in the quiz statistics report but also available for use elsewhere.

Author: Jamie Pratt <me@jamiep.org>
Copyright: 2013 Open University
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 494 lines (22 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: calculator  - X-Ref

This class has methods to compute the question statistics from the raw data.

__construct($questions, $progress = null)   X-Ref
Constructor.

param: object[] questions to analyze, keyed by slot, also analyses sub questions for random questions.
param: \core\progress\base|null $progress the element to send progress messages to, default is {@link \core\progress\none}.

calculate($qubaids)   X-Ref
Calculate the stats.

param: \qubaid_condition $qubaids Which question usages to calculate the stats for?
return: all_calculated_for_qubaid_condition The calculated stats.

get_sum_of_mark_variance()   X-Ref
Used when computing Coefficient of Internal Consistency by quiz statistics.

return: float

get_latest_steps($qubaids)   X-Ref
Get the latest step data from the db, from which we will calculate stats.

param: \qubaid_condition $qubaids Which question usages to get the latest steps for?
return: array with two items

initial_steps_walker($step, $stats, $summarks, $positionstat = true, $dovariantalso = true)   X-Ref
Calculating the stats is a four step process.

We loop through all 'last step' data first.

Update $stats->totalmarks, $stats->markarray, $stats->totalothermarks
and $stats->othermarksarray to include another state.

param: object     $step         the state to add to the statistics.
param: calculated $stats        the question statistics we are accumulating.
param: array      $summarks     of the sum of marks for each question usage, indexed by question usage id
param: bool       $positionstat whether this is a statistic of position of question.
param: bool       $dovariantalso do we also want to do the same calculations for this variant?

initial_question_walker($stats)   X-Ref
Then loop through all questions for the first time.

Perform some computations on the per-question statistics calculations after
we have been through all the step data.

param: calculated $stats question stats to update.

secondary_steps_walker($step, $stats, $summarks)   X-Ref
Loop through all last step data again.

Now we know the averages, accumulate the date needed to compute the higher
moments of the question scores.

param: object $step        the state to add to the statistics.
param: calculated $stats       the question statistics we are accumulating.
param: float[]  $summarks    of the sum of marks for each question usage, indexed by question usage id

secondary_question_walker($stats)   X-Ref
And finally loop through all the questions again.

Perform more per-question statistics calculations.

param: calculated $stats question stats to update.

get_random_guess_score($questiondata)   X-Ref
Given the question data find the average grade that random guesses would get.

param: object $questiondata the full question object.
return: float the random guess score for this question.

get_last_calculated_time($qubaids)   X-Ref
Find time of non-expired statistics in the database.

param: \qubaid_condition $qubaids Which question usages to look for?
return: int|bool Time of cached record that matches this qubaid_condition or false is non found.

get_cached($qubaids)   X-Ref
Load cached statistics from the database.

param: \qubaid_condition $qubaids Which question usages to load the cached stats for?
return: all_calculated_for_qubaid_condition The cached stats.