Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 402] [Versions 400 and 403]

(no description)

File Size: 290 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: calculator  - X-Ref

Class to calculate and also manage caching of quiz statistics.

These quiz statistics calculations are described here :

http://docs.moodle.org/dev/Quiz_statistics_calculations#Test_statistics

__construct(\core\progress\base $progress = null)   X-Ref


calculate($quizid, $whichattempts, \core\dml\sql_join $groupstudentsjoins, $p, $sumofmarkvariance)   X-Ref
Compute the quiz statistics.

return: calculated $quizstats The statistics for overall attempt scores.
param: int   $quizid            the quiz id.
param: int $whichattempts which attempts to use, represented internally as one of the constants as used in
param: \core\dml\sql_join $groupstudentsjoins Contains joins, wheres, params for students in this group.
param: int   $p                 number of positions (slots).
param: float $sumofmarkvariance sum of mark variance, calculated as part of question statistics

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

return: calculated|false The statistics for overall attempt scores or false if not cached.
param: \qubaid_condition $qubaids

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

return: int|bool Time of cached record that matches this qubaid_condition or false is non found.
param: $qubaids \qubaid_condition

using_attempts_lang_string($whichattempts)   X-Ref
Given a particular quiz grading method return a lang string describing which attempts contribute to grade.

Note internally we use the grading method constants to represent which attempts we are calculating statistics for, each
grading method corresponds to different attempts for each user.

return: string the appropriate lang string to describe this option.
param: int $whichattempts which attempts to use, represented internally as one of the constants as used in

using_attempts_string_id($whichattempts)   X-Ref
Given a particular quiz grading method return a string id for use as a field name prefix in mdl_quiz_statistics or to
fetch the appropriate language string describing which attempts contribute to grade.

Note internally we use the grading method constants to represent which attempts we are calculating statistics for, each
grading method corresponds to different attempts for each user.

return: string the string id for this option.
param: int $whichattempts which attempts to use, represented internally as one of the constants as used in

attempt_counts_and_averages($quizid, \core\dml\sql_join $groupstudentsjoins)   X-Ref
Calculating count and mean of marks for first and ALL attempts by students.

See : http://docs.moodle.org/dev/Quiz_item_analysis_calculations_in_practise
#Calculating_MEAN_of_grades_for_all_attempts_by_students
return: \stdClass with properties with count and avg with prefixes firstattempts, highestattempts, etc.
param: int $quizid
param: \core\dml\sql_join $groupstudentsjoins Contains joins, wheres, params for students in this group.

median($s, $fromqa, $whereqa, $qaparams)   X-Ref
Median mark.

http://docs.moodle.org/dev/Quiz_statistics_calculations#Median_Score

return: float
param: $s integer count of attempts
param: $fromqa string
param: $whereqa string
param: $qaparams string

sum_of_powers_of_difference_to_mean($mean, $fromqa, $whereqa, $qaparams)   X-Ref
Fetch the sum of squared, cubed and to the power 4 differences between sumgrade and it's mean.

Explanation here : http://docs.moodle.org/dev/Quiz_item_analysis_calculations_in_practise
#Calculating_Standard_Deviation.2C_Skewness_and_Kurtosis_of_grades_for_all_attempts_by_students

return: object with properties power2, power3, power4
param: $mean
param: $fromqa
param: $whereqa
param: $qaparams