From bec7719c3ba4f6c5f796e7184bdb1b63c3c7c0b9 Mon Sep 17 00:00:00 2001 From: James Pratt Date: Mon, 7 Apr 2014 17:02:30 +0700 Subject: [PATCH] MDL-44980 quiz statistics report : break down by variants failing when there has only been one variant seen. --- .../statistics/tests/fixtures/questions03.csv | 2 ++ .../statistics/tests/fixtures/quizzes.csv | 1 + .../tests/fixtures/responsecounts03.csv | 2 ++ .../statistics/tests/fixtures/steps03.csv | 2 ++ .../all_calculated_for_qubaid_condition.php | 18 ++---------------- .../statistics/questions/calculated.php | 4 ++-- .../statistics/questions/calculator.php | 2 +- 7 files changed, 12 insertions(+), 19 deletions(-) create mode 100644 mod/quiz/report/statistics/tests/fixtures/questions03.csv create mode 100644 mod/quiz/report/statistics/tests/fixtures/responsecounts03.csv create mode 100644 mod/quiz/report/statistics/tests/fixtures/steps03.csv diff --git a/mod/quiz/report/statistics/tests/fixtures/questions03.csv b/mod/quiz/report/statistics/tests/fixtures/questions03.csv new file mode 100644 index 00000000000..ba8b3e84b64 --- /dev/null +++ b/mod/quiz/report/statistics/tests/fixtures/questions03.csv @@ -0,0 +1,2 @@ +slot,type,which,cat,mark +1,calculatedsimple,sumwithvariants,maincat,1 diff --git a/mod/quiz/report/statistics/tests/fixtures/quizzes.csv b/mod/quiz/report/statistics/tests/fixtures/quizzes.csv index 63dd846c8bd..e6c19b9f858 100644 --- a/mod/quiz/report/statistics/tests/fixtures/quizzes.csv +++ b/mod/quiz/report/statistics/tests/fixtures/quizzes.csv @@ -2,3 +2,4 @@ testnumber,preferredbehaviour 00,deferredfeedback 01,interactive 02,interactive +03,deferredfeedback diff --git a/mod/quiz/report/statistics/tests/fixtures/responsecounts03.csv b/mod/quiz/report/statistics/tests/fixtures/responsecounts03.csv new file mode 100644 index 00000000000..78ecaab5d85 --- /dev/null +++ b/mod/quiz/report/statistics/tests/fixtures/responsecounts03.csv @@ -0,0 +1,2 @@ +slot,variant,modelresponse,actualresponse,totalcount +1,4,"{a} + {b} (±0.01 Relative)",19.4,1 diff --git a/mod/quiz/report/statistics/tests/fixtures/steps03.csv b/mod/quiz/report/statistics/tests/fixtures/steps03.csv new file mode 100644 index 00000000000..8c395b67b4c --- /dev/null +++ b/mod/quiz/report/statistics/tests/fixtures/steps03.csv @@ -0,0 +1,2 @@ +quizattempt,firstname,lastname,responses.1.answer,variants.1 +1,John,Jones,19.4,4 diff --git a/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php b/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php index 9f815680cca..1b53a059aeb 100644 --- a/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php +++ b/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php @@ -136,20 +136,6 @@ class all_calculated_for_qubaid_condition { return array_keys($this->questionstats); } - /** - * Array of variants of one randomly selected question that have appeared in the attempt data. - * - * @param int $questionid The id for the sub question. - * @return int[] The variant nos. - */ - public function get_variants_for_subq($questionid) { - if (count($this->subquestionstats[$questionid]->variantstats) > 1) { - return array_keys($this->subquestionstats[$questionid]->variantstats); - } else { - return false; - } - } - /** * Get position stats instance for a slot and optional variant no. * @@ -351,7 +337,7 @@ class all_calculated_for_qubaid_condition { $toreturn = array(); $displayorder = 1; foreach ($this->for_slot($slot)->get_sub_question_ids() as $subqid) { - if ($variants = $this->get_variants_for_subq($subqid)) { + if ($variants = $this->for_subq($subqid)->get_variants()) { foreach ($variants as $variant) { $toreturn[] = $this->make_new_subq_stat_for($displayorder, $slot, $subqid, $variant); } @@ -406,7 +392,7 @@ class all_calculated_for_qubaid_condition { $displaynumber = 1; foreach ($this->for_slot($slot)->get_sub_question_ids() as $subqid) { $toreturn[] = $this->make_new_subq_stat_for($displaynumber, $slot, $subqid); - if ($variants = $this->get_variants_for_subq($subqid)) { + if ($variants = $this->for_subq($subqid)->get_variants()) { foreach ($variants as $variant) { $toreturn[] = $this->make_new_subq_stat_for($displaynumber, $slot, $subqid, $variant); } diff --git a/question/classes/statistics/questions/calculated.php b/question/classes/statistics/questions/calculated.php index 7d1fffed176..e896ca9a7f9 100644 --- a/question/classes/statistics/questions/calculated.php +++ b/question/classes/statistics/questions/calculated.php @@ -230,7 +230,7 @@ class calculated { } $DB->insert_record('question_statistics', $toinsert, false); - if (count($this->variantstats) > 1) { + if ($this->get_variants()) { foreach ($this->variantstats as $variantstat) { $variantstat->cache($qubaids); } @@ -276,7 +276,7 @@ class calculated { */ public function get_variants() { $variants = array_keys($this->variantstats); - if (count($variants) > 1) { + if (count($variants) > 1 || reset($variants) != 1) { return $variants; } else { return array(); diff --git a/question/classes/statistics/questions/calculator.php b/question/classes/statistics/questions/calculator.php index 19370eb67a2..85c471d946c 100644 --- a/question/classes/statistics/questions/calculator.php +++ b/question/classes/statistics/questions/calculator.php @@ -161,7 +161,7 @@ class calculator { $this->stats->for_subq($qid)->question = $subquestion; $this->stats->for_subq($qid)->randomguessscore = $this->get_random_guess_score($subquestion); - if ($variants = $this->stats->get_variants_for_subq($qid)) { + if ($variants = $this->stats->for_subq($qid)->get_variants()) { foreach ($variants as $variant) { $this->stats->for_subq($qid, $variant)->question = $subquestion; $this->stats->for_subq($qid, $variant)->randomguessscore = $this->get_random_guess_score($subquestion);