mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
MDL-77626 quiz statistics: Divide by zero if a random Q has max mark 0
This commit is contained in:
parent
5e1df25566
commit
d5086a0938
@ -23,8 +23,11 @@
|
||||
*/
|
||||
|
||||
namespace core_question\statistics\questions;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/lib.php');
|
||||
|
||||
/**
|
||||
* Class calculated_question_summary
|
||||
*
|
||||
@ -114,7 +117,7 @@ class calculated_question_summary extends calculated {
|
||||
$set = false;
|
||||
|
||||
foreach ($this->subqstats as $subqstat) {
|
||||
if (isset($subqstat->sd) && $subqstat->maxmark) {
|
||||
if (isset($subqstat->sd) && $subqstat->maxmark > \question_utils::MARK_TOLERANCE) {
|
||||
$value = $subqstat->sd / $subqstat->maxmark;
|
||||
} else {
|
||||
$value = null;
|
||||
|
@ -127,7 +127,7 @@ class calculated_question_summary_test extends \advanced_testcase {
|
||||
],
|
||||
'zero mark' => [
|
||||
[
|
||||
(object)['questionid' => 1, 'sd' => 0.2, 'maxmark' => 0],
|
||||
(object)['questionid' => 1, 'sd' => 0, 'maxmark' => 0],
|
||||
(object)['questionid' => 2, 'sd' => 0.1049, 'maxmark' => 1],
|
||||
],
|
||||
[null, 0.1049]
|
||||
@ -139,6 +139,13 @@ class calculated_question_summary_test extends \advanced_testcase {
|
||||
],
|
||||
[0.35, 0.4]
|
||||
],
|
||||
'zero max mark as loaded from the DB' => [
|
||||
[
|
||||
(object)['questionid' => 1, 'sd' => '0.0000000000', 'maxmark' => '0.0000000'],
|
||||
(object)['questionid' => 2, 'sd' => '0.0000000000', 'maxmark' => '0.0000000'],
|
||||
],
|
||||
[null, null]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user