Example #1
0
 /**
  * Load cached statistics from the database.
  *
  * @param $qubaids \qubaid_condition
  * @return calculated The statistics for overall attempt scores or false if not cached.
  */
 public function get_cached($qubaids)
 {
     global $DB;
     $timemodified = time() - self::TIME_TO_CACHE;
     $fromdb = $DB->get_record_select('quiz_statistics', 'hashcode = ? AND timemodified > ?', array($qubaids->get_hash_code(), $timemodified));
     $stats = new calculated();
     $stats->populate_from_record($fromdb);
     return $stats;
 }
Example #2
0
 /**
  * Then loop through all questions for the first time.
  *
  * Perform some computations on the per-question statistics calculations after
  * we have been through all the step data.
  *
  * @param calculated $stats question stats to update.
  */
 protected function initial_question_walker($stats)
 {
     $stats->markaverage = $stats->totalmarks / $stats->s;
     if ($stats->maxmark != 0) {
         $stats->facility = $stats->markaverage / $stats->maxmark;
     } else {
         $stats->facility = null;
     }
     $stats->othermarkaverage = $stats->totalothermarks / $stats->s;
     $stats->summarksaverage = $stats->totalsummarks / $stats->s;
     sort($stats->markarray, SORT_NUMERIC);
     sort($stats->othermarksarray, SORT_NUMERIC);
     // Here we have collected enough data to make the decision about which questions have variants whose stats we also want to
     // calculate. We delete the initialised structures where they are not needed.
     if (!$stats->get_variants() || !$stats->break_down_by_variant()) {
         $stats->clear_variants();
     }
     foreach ($stats->get_variants() as $variant) {
         $this->initial_question_walker($stats->variantstats[$variant]);
     }
 }