Example #1
0
 /**
  * Get the quiz and question statistics, either by loading the cached results,
  * or by recomputing them.
  *
  * @param object $quiz               the quiz settings.
  * @param string $whichattempts      which attempts to use, represented internally as one of the constants as used in
  *                                   $quiz->grademethod ie.
  *                                   QUIZ_GRADEAVERAGE, QUIZ_GRADEHIGHEST, QUIZ_ATTEMPTLAST or QUIZ_ATTEMPTFIRST
  *                                   we calculate stats based on which attempts would affect the grade for each student.
  * @param string $whichtries         which tries to analyse for response analysis. Will be one of
  *                                   question_attempt::FIRST_TRY, LAST_TRY or ALL_TRIES.
  * @param array  $groupstudents      students in this group.
  * @param array  $questions          full question data.
  * @param \core\progress\base|null   $progress
  * @return array with 2 elements:    - $quizstats The statistics for overall attempt scores.
  *                                   - $questionstats \core_question\statistics\questions\all_calculated_for_qubaid_condition
  */
 public function get_all_stats_and_analysis($quiz, $whichattempts, $whichtries, $groupstudents, $questions, $progress = null)
 {
     if ($progress === null) {
         $progress = new \core\progress\none();
     }
     $qubaids = quiz_statistics_qubaids_condition($quiz->id, $groupstudents, $whichattempts);
     $qcalc = new \core_question\statistics\questions\calculator($questions, $progress);
     $quizcalc = new \quiz_statistics\calculator($progress);
     $progress->start_progress('', 3);
     if ($quizcalc->get_last_calculated_time($qubaids) === false) {
         // Recalculate now.
         $questionstats = $qcalc->calculate($qubaids);
         $progress->progress(1);
         $quizstats = $quizcalc->calculate($quiz->id, $whichattempts, $groupstudents, count($questions), $qcalc->get_sum_of_mark_variance());
         $progress->progress(2);
     } else {
         $quizstats = $quizcalc->get_cached($qubaids);
         $progress->progress(1);
         $questionstats = $qcalc->get_cached($qubaids);
         $progress->progress(2);
     }
     if ($quizstats->s()) {
         $subquestions = $questionstats->get_sub_questions();
         $this->analyse_responses_for_all_questions_and_subquestions($questions, $subquestions, $qubaids, $whichtries, $progress);
     }
     $progress->progress(3);
     $progress->end_progress();
     return array($quizstats, $questionstats);
 }
 /**
  * Check the question stats and the response counts used in the statistics report. If the appropriate files exist in fixtures/.
  *
  * @param PHPUnit_Extensions_Database_DataSet_ITable[] $csvdata Data loaded from csv files for this test.
  * @param string $whichattempts
  * @param string $whichtries
  * @param \core\dml\sql_join $groupstudentsjoins
  * @return array with contents 0 => $questions, 1 => $quizstats, 2=> $questionstats, 3=> $qubaids Might be needed for further
  *               testing.
  */
 protected function check_stats_calculations_and_response_analysis($csvdata, $whichattempts, $whichtries, \core\dml\sql_join $groupstudentsjoins)
 {
     $this->report = new quiz_statistics_report();
     $questions = $this->report->load_and_initialise_questions_for_calculations($this->quiz);
     list($quizstats, $questionstats) = $this->report->get_all_stats_and_analysis($this->quiz, $whichattempts, $whichtries, $groupstudentsjoins, $questions);
     $qubaids = quiz_statistics_qubaids_condition($this->quiz->id, $groupstudentsjoins, $whichattempts);
     // We will create some quiz and question stat calculator instances and some response analyser instances, just in order
     // to check the last analysed time then returned.
     $quizcalc = new \quiz_statistics\calculator();
     // Should not be a delay of more than one second between the calculation of stats above and here.
     $this->assertTimeCurrent($quizcalc->get_last_calculated_time($qubaids));
     $qcalc = new \core_question\statistics\questions\calculator($questions);
     $this->assertTimeCurrent($qcalc->get_last_calculated_time($qubaids));
     if (isset($csvdata['responsecounts'])) {
         $this->check_response_counts($csvdata['responsecounts'], $qubaids, $questions, $whichtries);
     }
     if (isset($csvdata['qstats'])) {
         $this->check_question_stats($csvdata['qstats'], $questionstats);
         return array($questions, $quizstats, $questionstats, $qubaids);
     }
     return array($questions, $quizstats, $questionstats, $qubaids);
 }