Skip to content

Commit

Permalink
Merge branch 'MDL-42957-26' of https://github.com/jamiepratt/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_26_STABLE
  • Loading branch information
stronk7 committed Nov 28, 2013
2 parents 66d40a5 + a69c787 commit d6ece9f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion mod/quiz/report/statistics/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ protected function output_statistics_graph($quizid, $currentgroup, $whichattempt
* - $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.
*/
protected function get_quiz_and_questions_stats($quiz, $whichattempts, $groupstudents, $questions) {
public function get_quiz_and_questions_stats($quiz, $whichattempts, $groupstudents, $questions) {

$qubaids = quiz_statistics_qubaids_condition($quiz->id, $groupstudents, $whichattempts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,7 @@
require_once($CFG->dirroot . '/mod/quiz/report/default.php');
require_once($CFG->dirroot . '/mod/quiz/report/statistics/report.php');
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
/**
* Test helper subclass of quiz_statistics_report
*
* @copyright 2013 The Open University
* @author Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class testable_quiz_statistics_report extends quiz_statistics_report {

public function get_stats($quiz, $whichattempts = QUIZ_GRADEAVERAGE, $groupstudents = array()) {
$qubaids = quiz_statistics_qubaids_condition($quiz->id, $groupstudents, $whichattempts);
$this->clear_cached_data($qubaids);
$questions = $this->load_and_initialise_questions_for_calculations($quiz);
return $this->get_quiz_and_questions_stats($quiz, $whichattempts, $groupstudents, $questions);
}
}

/**
* Quiz attempt walk through using data from csv file.
Expand Down Expand Up @@ -92,8 +77,31 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata) {

$this->check_attempts_results($csvdata['results'], $attemptids);

$this->report = new testable_quiz_statistics_report();
list($quizstats, $questionstats, $subquestionstats) = $this->report->get_stats($this->quiz);
$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 :
Expand Down
2 changes: 1 addition & 1 deletion question/classes/statistics/questions/calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function get_last_calculated_time($qubaids) {

$timemodified = time() - self::TIME_TO_CACHE;
return $DB->get_field_select('question_statistics', 'timemodified', 'hashcode = ? AND timemodified > ?',
array($qubaids->get_hash_code(), $timemodified));
array($qubaids->get_hash_code(), $timemodified), IGNORE_MULTIPLE);
}

/** @var integer Time after which statistics are automatically recomputed. */
Expand Down
3 changes: 2 additions & 1 deletion question/classes/statistics/responses/analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public function get_last_analysed_time($qubaids) {
global $DB;

$timemodified = time() - self::TIME_TO_CACHE;
return $DB->get_field_select('question_response_analysis', 'hashcode = ? AND questionid = ? AND timemodified > ?',
return $DB->get_field_select('question_response_analysis', 'timemodified',
'hashcode = ? AND questionid = ? AND timemodified > ?',
array($qubaids->get_hash_code(), $this->questiondata->id, $timemodified), IGNORE_MULTIPLE);
}
}

0 comments on commit d6ece9f

Please sign in to comment.