MDL-41752 question statistics class moved and improved
authorJamie Pratt <me@jamiep.org>
Wed, 25 Sep 2013 06:27:55 +0000 (13:27 +0700)
committerJamie Pratt <me@jamiep.org>
Fri, 27 Sep 2013 09:24:18 +0000 (16:24 +0700)
quiz_question_statistics_stats renamed to question_statistics_calculator
separate class question_statistics used to store calculated stats
and api changed, also code generally cleaned up.

15 files changed:
lib/db/upgrade.php
mod/quiz/report/statistics/classes/calculated.php
mod/quiz/report/statistics/classes/calculator.php
mod/quiz/report/statistics/db/install.php
mod/quiz/report/statistics/db/upgrade.php
mod/quiz/report/statistics/lib.php
mod/quiz/report/statistics/report.php
mod/quiz/report/statistics/statistics_form.php
mod/quiz/report/statistics/statistics_graph.php
mod/quiz/report/statistics/statistics_question_table.php
mod/quiz/report/statistics/statistics_table.php
mod/quiz/report/statistics/tests/statistics_test.php
question/classes/statistics/questions/calculated.php
question/classes/statistics/questions/calculator.php
question/engine/statisticslib.php

index d68ce28..80309ba 100644 (file)
@@ -864,11 +864,9 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2012062000.01);
     }
 
-
     // Moodle v2.3.0 release upgrade line
     // Put any upgrade step following this
 
-
     if ($oldversion < 2012062500.02) {
         // Drop some old backup tables, not used anymore
 
@@ -1497,7 +1495,6 @@ function xmldb_main_upgrade($oldversion) {
     // Moodle v2.4.0 release upgrade line
     // Put any upgrade step following this
 
-
     if ($oldversion < 2012120300.01) {
         // Make sure site-course has format='site' //MDL-36840
 
index 40a6210..8103b7c 100644 (file)
@@ -166,7 +166,6 @@ class quiz_statistics_calculated {
         }
     }
 
-
     /**
      * @var array of names of properties of this class that are cached in db record.
      */
index 997ee73..85c8cb7 100644 (file)
@@ -90,7 +90,6 @@ class quiz_statistics_calculator {
             }
         }
 
-
         $quizstats->cache(quiz_statistics_qubaids_condition($quizid, $currentgroup, $groupstudents, $useallattempts));
 
         return $quizstats;
index 4a15c7d..e148f9e 100644 (file)
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 defined('MOODLE_INTERNAL') || die();
 
-
 /**
  * Post-install script
  */
index 4beb458..3581dfe 100644 (file)
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 defined('MOODLE_INTERNAL') || die();
 
-
 /**
  * Quiz statistics report upgrade code.
  */
index 2dc0751..416981b 100644 (file)
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 defined('MOODLE_INTERNAL') || die();
 
-
 /**
  * Serve questiontext files in the question text when they are displayed in this report.
  *
index aab3d00..5179ee8 100644 (file)
@@ -22,7 +22,6 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 defined('MOODLE_INTERNAL') || die();
 
 require_once($CFG->dirroot . '/mod/quiz/report/statistics/statistics_form.php');
@@ -106,7 +105,6 @@ class quiz_statistics_report extends quiz_default_report {
 
         $qubaids = quiz_statistics_qubaids_condition($quiz->id, $currentgroup, $groupstudents, $useallattempts);
 
-
         // If recalculate was requested, handle that.
         if ($recalculate && confirm_sesskey()) {
             $this->clear_cached_data($qubaids);
@@ -532,7 +530,6 @@ class quiz_statistics_report extends quiz_default_report {
             $quizstats = $quizcalc->calculate($quiz->id, $currentgroup, $useallattempts,
                                                $groupstudents, count($questions), $qcalc->get_sum_of_mark_variance());
 
-
             if ($quizstats->s()) {
                 $this->calculate_responses_for_all_questions_and_subquestions($qubaids, $questions, $subquestionstats);
             }
index a583ea9..02fb2f4 100644 (file)
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 defined('MOODLE_INTERNAL') || die();
 
 require_once($CFG->libdir . '/formslib.php');
 
-
 /**
  * This is the settings form for the quiz statistics report.
  *
index 6f762b3..bb21b0f 100644 (file)
@@ -28,7 +28,6 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 require_once(dirname(__FILE__) . '/../../../../config.php');
 require_once($CFG->libdir . '/graphlib.php');
 require_once($CFG->dirroot . '/mod/quiz/locallib.php');
index 9265181..4bfc411 100644 (file)
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 defined('MOODLE_INTERNAL') || die();
 
 require_once($CFG->libdir . '/tablelib.php');
 
-
 /**
  * This table shows statistics about a particular question.
  *
index d186bee..73217a5 100644 (file)
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 defined('MOODLE_INTERNAL') || die();
 
 require_once($CFG->libdir.'/tablelib.php');
 
-
 /**
  * This table has one row for each question in the quiz, with sub-rows when
  * random questions appear. There are columns for the various statistics.
index 258062c..cc29888 100644 (file)
@@ -23,7 +23,6 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 defined('MOODLE_INTERNAL') || die();
 
 global $CFG;
@@ -31,7 +30,6 @@ require_once($CFG->libdir . '/questionlib.php');
 require_once($CFG->dirroot . '/mod/quiz/locallib.php');
 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
 
-
 /**
  * Test helper subclass of question_statistics
  *
index 05add67..e8e3404 100644 (file)
@@ -38,7 +38,6 @@ class calculated {
 
     public $questionid;
 
-
     // These first fields are the final fields cached in the db and shown in reports.
 
     // See : http://docs.moodle.org/dev/Quiz_statistics_calculations#Position_statistics .
@@ -175,5 +174,4 @@ class calculated {
         $this->timemodified = $record->timemodified;
     }
 
-
 }
index db8b574..55bb803 100644 (file)
@@ -171,7 +171,7 @@ class calculator {
             foreach ($lateststeps as $step) {
                 $this->secondary_steps_walker($step, $this->questionstats[$step->slot], $summarks, $summarksavg);
 
-                if ($this->questionstats[$step->slot]->subquestion) {
+                if ($this->questionstats[$step->slot]->subquestions) {
                     $this->secondary_steps_walker($step, $this->subquestionstats[$step->questionid], $summarks, $summarksavg);
                 }
             }
@@ -217,7 +217,7 @@ class calculator {
     public function get_cached($qubaids) {
         global $DB;
         $timemodified = time() - self::TIME_TO_CACHE;
-        $questionstatrecs = $DB->get_record_select('question_statistics', 'hashcode = ? AND timemodified > ?',
+        $questionstatrecs = $DB->get_records_select('question_statistics', 'hashcode = ? AND timemodified > ?',
                                          array($qubaids->get_hash_code(), $timemodified));
 
         $questionids = array();
@@ -250,7 +250,8 @@ class calculator {
         global $DB;
 
         $timemodified = time() - self::TIME_TO_CACHE;
-        return $DB->get_field_select('question_statistics', 'timemodified', 'hashcode = ? AND timemodified > ?',
+        return $DB->get_field_select('question_statistics', 'timemodified', 'hashcode = ? AND timemodified > ? '.
+                                                          'ORDER BY timemodified DESC LIMIT 1',
                                      array($qubaids->get_hash_code(), $timemodified));
     }
 
@@ -404,8 +405,6 @@ class calculator {
             $stats->negcovar = 0;
         }
 
-
-
         if ($stats->markvariance * $stats->othermarkvariance) {
             $stats->discriminationindex = 100 * $stats->covariance /
                 sqrt($stats->markvariance * $stats->othermarkvariance);
index ab99fc0..363c102 100644 (file)
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-
 defined('MOODLE_INTERNAL') || die();
 
-
 /**
  * Question statistics cron code. Deletes cached stats more than a certain age.
  */