2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Question statistics calculations class. Used in the quiz statistics report.
20 * @package core_question
21 * @copyright 2018 Ryan Wyllie <ryan@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_question\statistics\questions
;
26 defined('MOODLE_INTERNAL') ||
die();
29 * Class calculated_random_question_summary
31 * This class is used to indicate the statistics for a random question slot should
32 * be rendered with a link to a summary of the displayed questions.
34 * It's used in the limited view of the statistics calculation in lieu of adding
35 * the stats for each subquestion individually.
37 * @copyright 2018 Ryan Wyllie <ryan@moodle.com>
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class calculated_random_question_summary
extends calculated
{
43 * @var int only set immediately before display in the table. The order of display in the table.
45 public $subqdisplayorder;
48 * @var calculated[] The instances storing the calculated stats of the questions that are being summarised.
53 * calculated_random_question_summary constructor.
55 * @param \stdClass $question
57 * @param calculated[] $subqstats The instances of the calculated stats of the questions that are being summarised.
59 public function __construct($question, $slot, $subqstats) {
60 parent
::__construct($question, $slot);
62 $this->subqstats
= $subqstats;
63 $this->subquestions
= implode(',', array_column($subqstats, 'questionid'));
67 * This is a summary stat so never breakdown by variant.
71 public function break_down_by_variant() {
76 * Returns the minimum and maximum values of the given attribute in the summarised calculated stats.
78 * @param string $attribute The attribute that we are looking for its extremums.
79 * @return array An array of [min,max]
81 public function get_min_max_of($attribute) {
82 $getmethod = 'get_min_max_of_' . $attribute;
83 if (method_exists($this, $getmethod)) {
84 return $this->$getmethod();
88 // We cannot simply use min or max functions because, in theory, some attributes might be non-scalar.
89 foreach (array_column($this->subqstats
, $attribute) as $value) {
90 if (is_scalar($value)) {
98 $min = min($min, $value);
99 $max = max($max, $value);
108 * Returns the minimum and maximum values of the standard deviation in the summarised calculated stats.
109 * @return array An array of [min,max]
111 protected function get_min_max_of_sd() {
114 foreach ($this->subqstats
as $subqstat) {
115 if (isset($subqstat->sd
) && $subqstat->maxmark
) {
117 $min = $subqstat->sd
/ $subqstat->maxmark
;
120 $max = $subqstat->sd
/ $subqstat->maxmark
;
123 $min = min($min, $subqstat->sd
/ $subqstat->maxmark
);
124 $max = max($max, $subqstat->sd
/ $subqstat->maxmark
);