MDL-41758 quiz statistics : link to full break down of stats for slots
authorJames Pratt <me@jamiep.org>
Fri, 20 Dec 2013 04:22:47 +0000 (11:22 +0700)
committerJames Pratt <me@jamiep.org>
Fri, 14 Feb 2014 08:16:07 +0000 (15:16 +0700)
where a question in a slot has subquestions and/or variants.

mod/quiz/report/statistics/lang/en/quiz_statistics.php
mod/quiz/report/statistics/report.php
mod/quiz/report/statistics/statistics_table.php
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
question/classes/statistics/questions/calculated.php

index d068602..9c9c1c8 100644 (file)
@@ -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';
index 39a9298..42ea15d 100644 (file)
@@ -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('<a href="' . $reporturl->out() . '">' .
-                    get_string('backtoquizreport', 'quiz_statistics') . '</a>',
-                    'backtomainstats boxaligncenter generalbox boxwidthnormal mdl-align');
+            }
+            if (!$this->table->is_downloading()) {
+                // Back to overview link.
+                echo $OUTPUT->box('<a href="' . $reporturl->out() . '">' .
+                        get_string('backtoquizreport', 'quiz_statistics') . '</a>',
+                        '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);
     }
index 45bbcc6..7c674d0 100644 (file)
@@ -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 '';
         }
 
index 4dca155..91b483a 100644 (file)
@@ -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.
index 2b4defc..aa0b960 100644 (file)
@@ -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();
+        }
+    }
 }