Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

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

(no description)

File Size: 294 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.

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
return: calculated $quizstats The statistics for overall attempt scores.

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

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

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

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

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.

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

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.

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

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
param: int $quizid
param: \core\dml\sql_join $groupstudentsjoins Contains joins, wheres, params for students in this group.
return: \stdClass with properties with count and avg with prefixes firstattempts, highestattempts, etc.

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

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

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

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

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