/** * 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); }
/** * 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 array $groupstudents students in this group. * @param array $questions full question data. * @return array with 4 elements: * - $quizstats The statistics for overall attempt scores. * - $questionstats array of \core_question\statistics\questions\calculated objects keyed by slot. * - $subquestionstats array of \core_question\statistics\questions\calculated_for_subquestion objects keyed by question id. */ public function get_quiz_and_questions_stats($quiz, $whichattempts, $groupstudents, $questions) { $qubaids = quiz_statistics_qubaids_condition($quiz->id, $groupstudents, $whichattempts); $qcalc = new \core_question\statistics\questions\calculator($questions); $quizcalc = new quiz_statistics_calculator(); if ($quizcalc->get_last_calculated_time($qubaids) === false) { // Recalculate now. list($questionstats, $subquestionstats) = $qcalc->calculate($qubaids); $quizstats = $quizcalc->calculate($quiz->id, $whichattempts, $groupstudents, count($questions), $qcalc->get_sum_of_mark_variance()); if ($quizstats->s()) { $this->analyse_responses_for_all_questions_and_subquestions($qubaids, $questions, $subquestionstats); } } else { $quizstats = $quizcalc->get_cached($qubaids); list($questionstats, $subquestionstats) = $qcalc->get_cached($qubaids); } return array($quizstats, $questionstats, $subquestionstats); }