From 51e3ded838e78bb5ffc751213fbd4cf704c79f22 Mon Sep 17 00:00:00 2001 From: James Pratt Date: Fri, 20 Dec 2013 11:22:47 +0700 Subject: [PATCH] MDL-41758 quiz statistics : link to full break down of stats for slots where a question in a slot has subquestions and/or variants. --- .../statistics/lang/en/quiz_statistics.php | 1 + mod/quiz/report/statistics/report.php | 37 ++++++++++------ .../report/statistics/statistics_table.php | 29 ++++++++----- .../all_calculated_for_qubaid_condition.php | 43 +++++++++---------- .../statistics/questions/calculated.php | 14 ++++++ 5 files changed, 79 insertions(+), 45 deletions(-) diff --git a/mod/quiz/report/statistics/lang/en/quiz_statistics.php b/mod/quiz/report/statistics/lang/en/quiz_statistics.php index d0686027fa5..9c9c1c8d2f3 100644 --- a/mod/quiz/report/statistics/lang/en/quiz_statistics.php +++ b/mod/quiz/report/statistics/lang/en/quiz_statistics.php @@ -96,6 +96,7 @@ $string['random_guess_score'] = 'Random guess score'; $string['recalculatenow'] = 'Recalculate now'; $string['reportsettings'] = 'Statistics calculation settings'; $string['response'] = 'Response'; +$string['slotstructureanalysis'] = 'Structural analysis for question number {$a}'; $string['skewness'] = 'Score distribution skewness (for {$a})'; $string['standarddeviation'] = 'Standard deviation (for {$a})'; $string['standarddeviationq'] = 'Standard deviation'; diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php index 39a929863f6..42ea15dde7c 100644 --- a/mod/quiz/report/statistics/report.php +++ b/mod/quiz/report/statistics/report.php @@ -215,16 +215,29 @@ class quiz_statistics_report extends quiz_default_report { print_error('questiondoesnotexist', 'question'); } - $this->output_individual_question_data($quiz, $questionstats->for_slot($slot)); - $this->output_individual_question_response_analysis($questions[$slot], - $questionstats->for_slot($slot)->s, - $reporturl, - $qubaids); + if ($questionstats->for_slot($slot)->get_sub_question_ids() || $questionstats->for_slot($slot)->get_variants()) { + if (!$this->table->is_downloading()) { + $number = $questionstats->for_slot($slot)->question->number; + echo $OUTPUT->heading(get_string('slotstructureanalysis', 'quiz_statistics', $number), 3); + } + $this->table->define_baseurl(new moodle_url($reporturl, array('slot' => $slot))); + $this->table->format_and_add_array_of_rows($questionstats->structure_analysis_for_one_slot($slot)); + } else { + $this->output_individual_question_data($quiz, $questionstats->for_slot($slot)); + $this->output_individual_question_response_analysis($questions[$slot], + $questionstats->for_slot($slot)->s, + $reporturl, + $qubaids); - // Back to overview link. - echo $OUTPUT->box('' . - get_string('backtoquizreport', 'quiz_statistics') . '', - 'backtomainstats boxaligncenter generalbox boxwidthnormal mdl-align'); + } + if (!$this->table->is_downloading()) { + // Back to overview link. + echo $OUTPUT->box('' . + get_string('backtoquizreport', 'quiz_statistics') . '', + 'backtomainstats boxaligncenter generalbox boxwidthnormal mdl-align'); + } else { + $this->table->finish_output(); + } } else if ($qid) { // Report on an individual sub-question indexed questionid. @@ -417,12 +430,10 @@ class quiz_statistics_report extends quiz_default_report { */ protected function output_quiz_structure_analysis_table($questionstats) { $tooutput = array(); + $limitvariants = !$this->table->is_downloading(); foreach ($questionstats->get_all_slots() as $slot) { // Output the data for these question statistics. - $tooutput[] = $questionstats->for_slot($slot); - - $limitvariants = !$this->table->is_downloading(); - $tooutput = array_merge($tooutput, $questionstats->all_subq_and_variant_stats_for_slot($slot, $limitvariants)); + $tooutput = array_merge($tooutput, $questionstats->structure_analysis_for_one_slot($slot, $limitvariants)); } $this->table->format_and_add_array_of_rows($tooutput); } diff --git a/mod/quiz/report/statistics/statistics_table.php b/mod/quiz/report/statistics/statistics_table.php index 45bbcc6e0c5..7c674d0f8ae 100644 --- a/mod/quiz/report/statistics/statistics_table.php +++ b/mod/quiz/report/statistics/statistics_table.php @@ -202,17 +202,26 @@ class quiz_statistics_table extends flexible_table { return $name; } - $url = null; - if ($questionstat->subquestion) { - $url = new moodle_url($this->baseurl, array('qid' => $questionstat->questionid)); - } else if ($questionstat->slot && $questionstat->question->qtype != 'random') { - $url = new moodle_url($this->baseurl, array('slot' => $questionstat->slot)); + $baseurl = new moodle_url($this->baseurl); + if (is_null($questionstat->variant)) { + if ($questionstat->subquestion && !$questionstat->get_variants()) { + $url = new moodle_url($baseurl, array('qid' => $questionstat->questionid)); + $name = html_writer::link($url, $name, array('title' => get_string('detailedanalysis', 'quiz_statistics'))); + } else if ($baseurl->param('slot') === null && $questionstat->slot) { + $number = $questionstat->question->number; + $url = new moodle_url($baseurl, array('slot' => $questionstat->slot)); + if ($questionstat->get_variants() || $questionstat->get_sub_question_ids()) { + $name = html_writer::link($url, + $name, + array('title' => get_string('slotstructureanalysis', 'quiz_statistics', $number))); + } else { + $name = html_writer::link($url, + $name, + array('title' => get_string('detailedanalysis', 'quiz_statistics'))); + } + } } - if ($url) { - $name = html_writer::link($url, $name, - array('title' => get_string('detailedanalysis', 'quiz_statistics'))); - } if ($this->is_dubious_question($questionstat)) { $name = html_writer::tag('div', $name, array('class' => 'dubious')); @@ -298,7 +307,7 @@ class quiz_statistics_table extends flexible_table { protected function col_effective_weight($questionstat) { global $OUTPUT; - if ($questionstat->subquestion) { + if (is_null($questionstat->effectiveweight)) { return ''; } 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 4dca155d66d..91b483aca63 100644 --- a/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php +++ b/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php @@ -144,20 +144,6 @@ class all_calculated_for_qubaid_condition { } } - /** - * Array of variants that have appeared in the attempt data for a question in one slot. - * - * @param $slot - * @return int[] - */ - public function get_variants_for_slot($slot) { - if (count($this->questionstats[$slot]->variantstats) > 1) { - return array_keys($this->questionstats[$slot]->variantstats); - } else { - return false; - } - } - /** * Reference to position stats instance for a slot and optional variant no. * @@ -314,10 +300,8 @@ class all_calculated_for_qubaid_condition { */ protected function all_variant_stats_for_one_slot($slot) { $toreturn = array(); - if ($variants = $this->get_variants_for_slot($slot)){ - foreach ($variants as $variant) { - $toreturn[] = $this->for_slot($slot, $variant); - } + foreach ($this->for_slot($slot)->get_variants() as $variant) { + $toreturn[] = $this->for_slot($slot, $variant); } return $toreturn; } @@ -364,11 +348,11 @@ class all_calculated_for_qubaid_condition { * - variants of randomly selected questions * - randomly selected questions * - * @param int $slot - * @param bool $limited - * @return calculated[] + * @param int $slot the slot no + * @param bool $limited limit number of variants and sub-questions displayed? + * @return calculated|calculated_for_subquestion[] stats to display */ - public function all_subq_and_variant_stats_for_slot($slot, $limited) { + protected function all_subq_and_variant_stats_for_slot($slot, $limited) { // Random question in this slot? if ($this->for_slot($slot)->get_sub_question_ids()) { if ($limited) { @@ -406,6 +390,21 @@ class all_calculated_for_qubaid_condition { } + /** + * Return all stats for one slot, stats for the slot itself, and either : + * - variants of question + * - variants of randomly selected questions + * - randomly selected questions + * + * @param int $slot the slot no + * @param int $limitvariants limit number of variants and sub-questions displayed? + * @return calculated|calculated_for_subquestion[] stats to display + */ + public function structure_analysis_for_one_slot($slot, $limitvariants = false) { + return array_merge(array($this->for_slot($slot)), + $this->all_subq_and_variant_stats_for_slot($slot, $limitvariants)); + } + /** * We need a new object for display. Sub-question stats can appear more than once in different slots. * So we create a clone of the object and then we can set properties on the object that are per slot. diff --git a/question/classes/statistics/questions/calculated.php b/question/classes/statistics/questions/calculated.php index 2b4defc3fc5..aa0b960a250 100644 --- a/question/classes/statistics/questions/calculated.php +++ b/question/classes/statistics/questions/calculated.php @@ -258,4 +258,18 @@ class calculated { return array(); } } + + /** + * Array of variants that have appeared in the attempt data for this question. + * + * @return int[] + */ + public function get_variants() { + $variants = array_keys($this->variantstats); + if (count($variants) > 1) { + return $variants; + } else { + return array(); + } + } }