/**
  * Create a quiz add questions to it, walk through quiz attempts and then check results.
  *
  * @param PHPUnit_Extensions_Database_DataSet_ITable[] of data read from csv file "questionsXX.csv",
  *                                                                                  "stepsXX.csv" and "resultsXX.csv".
  * @dataProvider get_data_for_walkthrough
  */
 public function test_walkthrough_from_csv($quizsettings, $csvdata)
 {
     // CSV data files for these tests were generated using :
     // https://github.com/jamiepratt/moodle-quiz-tools/tree/master/responsegenerator
     $this->resetAfterTest(true);
     question_bank::get_qtype('random')->clear_caches_before_testing();
     $this->create_quiz($quizsettings, $csvdata['questions']);
     $attemptids = $this->walkthrough_attempts($csvdata['steps']);
     $this->check_attempts_results($csvdata['results'], $attemptids);
     $this->report = new quiz_statistics_report();
     $whichattempts = QUIZ_GRADEAVERAGE;
     $groupstudents = array();
     $questions = $this->report->load_and_initialise_questions_for_calculations($this->quiz);
     list($quizstats, $questionstats, $subquestionstats) = $this->report->get_quiz_and_questions_stats($this->quiz, $whichattempts, $groupstudents, $questions);
     $qubaids = quiz_statistics_qubaids_condition($this->quiz->id, $groupstudents, $whichattempts);
     // We will create some quiz and question stat calculator instances and some response analyser instances, just in order
     // to check the time of the
     $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));
     foreach ($questions as $question) {
         if (!question_bank::get_qtype($question->qtype, false)->can_analyse_responses()) {
             continue;
         }
         $responesstats = new \core_question\statistics\responses\analyser($question);
         $this->assertTimeCurrent($responesstats->get_last_analysed_time($qubaids));
     }
     // These quiz stats and the question stats found in qstats00.csv were calculated independently in spreadsheet which is
     // available in open document or excel format here :
     // https://github.com/jamiepratt/moodle-quiz-tools/tree/master/statsspreadsheet
     $quizstatsexpected = array('median' => 4.5, 'firstattemptsavg' => 4.617333332, 'allattemptsavg' => 4.617333332, 'firstattemptscount' => 25, 'allattemptscount' => 25, 'standarddeviation' => 0.8117265554, 'skewness' => -0.092502502, 'kurtosis' => -0.7073968557, 'cic' => -87.22309355420001, 'errorratio' => 136.8294900795, 'standarderror' => 1.1106813066);
     foreach ($quizstatsexpected as $statname => $statvalue) {
         $this->assertEquals($statvalue, $quizstats->{$statname}, $quizstats->{$statname}, abs($statvalue) * 1.5E-5);
     }
     for ($rowno = 0; $rowno < $csvdata['qstats']->getRowCount(); $rowno++) {
         $slotqstats = $csvdata['qstats']->getRow($rowno);
         foreach ($slotqstats as $statname => $slotqstat) {
             if ($statname !== 'slot') {
                 switch ($statname) {
                     case 'covariance':
                     case 'discriminationindex':
                     case 'discriminativeefficiency':
                     case 'effectiveweight':
                         $precision = 1.0E-5;
                         break;
                     default:
                         $precision = 1.0E-6;
                 }
                 $slot = $slotqstats['slot'];
                 $delta = abs($slotqstat) * $precision;
                 $actual = $questionstats[$slot]->{$statname};
                 $this->assertEquals(floatval($slotqstat), $actual, "{$statname} for slot {$slot}", $delta);
             }
         }
     }
 }
 protected function definition()
 {
     $mform = $this->_form;
     $mform->addElement('header', 'preferencespage', get_string('reportsettings', 'quiz_statistics'));
     $options = array();
     foreach (array_keys(quiz_get_grading_options()) as $which) {
         $options[$which] = \quiz_statistics_calculator::using_attempts_lang_string($which);
     }
     $mform->addElement('select', 'whichattempts', get_string('calculatefrom', 'quiz_statistics'), $options);
     $mform->addElement('submit', 'submitbutton', get_string('preferencessave', 'quiz_overview'));
 }
Esempio n. 3
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 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);
 }
Esempio n. 4
0
 /**
  * @param $course
  * @param $cm
  * @param $quiz
  * @return array to display in table or spreadsheet.
  */
 public function get_formatted_quiz_info_data($course, $cm, $quiz)
 {
     // You can edit this array to control which statistics are displayed.
     $todisplay = array('firstattemptscount' => 'number', 'allattemptscount' => 'number', 'firstattemptsavg' => 'summarks_as_percentage', 'allattemptsavg' => 'summarks_as_percentage', 'lastattemptsavg' => 'summarks_as_percentage', 'highestattemptsavg' => 'summarks_as_percentage', 'median' => 'summarks_as_percentage', 'standarddeviation' => 'summarks_as_percentage', 'skewness' => 'number_format', 'kurtosis' => 'number_format', 'cic' => 'number_format_percent', 'errorratio' => 'number_format_percent', 'standarderror' => 'summarks_as_percentage');
     // General information about the quiz.
     $quizinfo = array();
     $quizinfo[get_string('quizname', 'quiz_statistics')] = format_string($quiz->name);
     $quizinfo[get_string('coursename', 'quiz_statistics')] = format_string($course->fullname);
     if ($cm->idnumber) {
         $quizinfo[get_string('idnumbermod')] = $cm->idnumber;
     }
     if ($quiz->timeopen) {
         $quizinfo[get_string('quizopen', 'quiz')] = userdate($quiz->timeopen);
     }
     if ($quiz->timeclose) {
         $quizinfo[get_string('quizclose', 'quiz')] = userdate($quiz->timeclose);
     }
     if ($quiz->timeopen && $quiz->timeclose) {
         $quizinfo[get_string('duration', 'quiz_statistics')] = format_time($quiz->timeclose - $quiz->timeopen);
     }
     // The statistics.
     foreach ($todisplay as $property => $format) {
         if (!isset($this->{$property}) || !$format) {
             continue;
         }
         $value = $this->{$property};
         switch ($format) {
             case 'summarks_as_percentage':
                 $formattedvalue = quiz_report_scale_summarks_as_percentage($value, $quiz);
                 break;
             case 'number_format_percent':
                 $formattedvalue = quiz_format_grade($quiz, $value) . '%';
                 break;
             case 'number_format':
                 // 2 extra decimal places, since not a percentage,
                 // and we want the same number of sig figs.
                 $formattedvalue = format_float($value, $quiz->decimalpoints + 2);
                 break;
             case 'number':
                 $formattedvalue = $value + 0;
                 break;
             default:
                 $formattedvalue = $value;
         }
         $quizinfo[get_string($property, 'quiz_statistics', quiz_statistics_calculator::using_attempts_lang_string($this->whichattempts))] = $formattedvalue;
     }
     return $quizinfo;
 }