Skip to content

Commit

Permalink
Merge branch 'MDL-43338-master' of https://github.com/jamiepratt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Feb 10, 2014
2 parents 696195a + c3e2e75 commit 16b2fc5
Show file tree
Hide file tree
Showing 8 changed files with 701 additions and 343 deletions.
176 changes: 55 additions & 121 deletions mod/quiz/report/statistics/report.php

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions mod/quiz/report/statistics/statistics_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

/**
* This table has one row for each question in the quiz, with sub-rows when
* random questions appear. There are columns for the various statistics.
* random questions and variants appear.
*
* There are columns for the various item and position statistics.
*
* @copyright 2008 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand Down Expand Up @@ -136,6 +138,9 @@ public function statistics_setup($quiz, $cmid, $reporturl, $s) {
* @return string contents of this table cell.
*/
protected function col_number($questionstat) {
if (!isset($questionstat->question->number)) {
return '';
}
$number = $questionstat->question->number;

if (isset($questionstat->subqdisplayorder)) {
Expand Down Expand Up @@ -214,7 +219,7 @@ protected function col_name($questionstat) {
}

if (!empty($questionstat->minmedianmaxnotice)) {
$name = $questionstat->minmedianmaxnotice . '<br />' . $name;
$name = get_string($questionstat->minmedianmaxnotice, 'quiz_statistics') . '<br />' . $name;
}

return $name;
Expand Down
25 changes: 19 additions & 6 deletions mod/quiz/report/statistics/tests/statistics_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');

class testable_all_calculated_for_qubaid_condition extends \core_question\statistics\questions\all_calculated_for_qubaid_condition {

/**
* Disabling caching in tests so we are always sure to force the calculation of stats right then and there.
*
* @param qubaid_condition $qubaids
*/
public function cache($qubaids) {

}
}

/**
* Test helper subclass of question_statistics
*
Expand All @@ -43,6 +55,8 @@ class testable_question_statistics extends \core_question\statistics\questions\c
*/
protected $lateststeps;

protected $statscollectionclassname = 'testable_all_calculated_for_qubaid_condition';

public function set_step_data($states) {
$this->lateststeps = $states;
}
Expand Down Expand Up @@ -86,7 +100,7 @@ protected function cache_stats($qubaids) {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quiz_statistics_question_stats_testcase extends basic_testcase {
/** @var qstats object created to test class. */
/** @var testable_all_calculated_for_qubaid_condition object created to test class. */
protected $qstats;

public function test_qstats() {
Expand All @@ -99,7 +113,7 @@ public function test_qstats() {
$questions = $this->get_records_from_csv(__DIR__.'/fixtures/mdl_question.csv');
$calculator = new testable_question_statistics($questions);
$calculator->set_step_data($steps);
list($this->qstats, ) = $calculator->calculate(null);
$this->qstats = $calculator->calculate(null);

// Values expected are taken from contrib/tools/quiz_tools/stats.xls.
$facility = array(0, 0, 0, 0, null, null, null, 41.19318182, 81.36363636,
Expand Down Expand Up @@ -127,13 +141,12 @@ public function test_qstats() {
}

public function qstats_q_fields($fieldname, $values, $multiplier=1) {
foreach ($this->qstats as $qstat) {
foreach ($this->qstats->get_all_slots() as $slot) {
$value = array_shift($values);
if ($value !== null) {
$this->assertEquals($value, $qstat->{$fieldname} * $multiplier,
'', 1E-6);
$this->assertEquals($value, $this->qstats->for_slot($slot)->{$fieldname} * $multiplier, '', 1E-6);
} else {
$this->assertEquals($value, $qstat->{$fieldname} * $multiplier);
$this->assertEquals($value, $this->qstats->for_slot($slot)->{$fieldname} * $multiplier);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata) {
$whichattempts = QUIZ_GRADEAVERAGE;
$groupstudents = array();
$questions = $this->report->load_and_initialise_questions_for_calculations($this->quiz);
list($quizstats, $questionstats, $subquestionstats) =
list($quizstats, $questionstats) =
$this->report->get_all_stats_and_analysis($this->quiz, $whichattempts, $groupstudents, $questions);

$qubaids = quiz_statistics_qubaids_condition($this->quiz->id, $groupstudents, $whichattempts);
Expand All @@ -102,11 +102,9 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata) {
$this->assertTimeCurrent($responesstats->get_last_analysed_time($qubaids));
}

// These quiz stats and the question stats found in qstats00.csv were calculated independently in spreadsheets which are
// 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

// These quiz stats and the position stats here are calculated in stats.xls and stats.ods available, see above github URL.
$quizstatsexpected = array(
'median' => 4.5,
'firstattemptsavg' => 4.617333332,
Expand All @@ -129,8 +127,7 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata) {
$slotqstats = $csvdata['qstats']->getRow($rowno);
foreach ($slotqstats as $statname => $slotqstat) {
if ($statname !== 'slot') {
$this->assert_stat_equals($questionstats, $subquestionstats, $slotqstats['slot'],
null, null, $statname, (float)$slotqstat);
$this->assert_stat_equals($questionstats, $slotqstats['slot'], null, null, $statname, (float)$slotqstat);
}
}
}
Expand All @@ -146,7 +143,7 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata) {
'slot' => null,
'subquestion' => true);
foreach ($itemstats as $statname => $expected) {
$this->assert_stat_equals($questionstats, $subquestionstats, 1, null, 'numerical', $statname, $expected);
$this->assert_stat_equals($questionstats, 1, null, 'numerical', $statname, $expected);
}


Expand Down Expand Up @@ -176,30 +173,29 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata) {
'subquestion' => false));
foreach ($statsforslot2variants as $variant => $stats) {
foreach ($stats as $statname => $expected) {
$this->assert_stat_equals($questionstats, $subquestionstats, 2, $variant, null, $statname, $expected);
$this->assert_stat_equals($questionstats, 2, $variant, null, $statname, $expected);
}
}
}

/**
* Check that the stat is as expected within a reasonable tolerance.
*
* @param \core_question\statistics\questions\calculated[] $questionstats
* @param \core_question\statistics\questions\calculated_for_subquestion[] $subquestionstats
* @param \core_question\statistics\questions\all_calculated_for_qubaid_condition $questionstats
* @param int $slot
* @param int|null $variant if null then not a variant stat.
* @param string|null $subqname if null then not an item stat.
* @param string $statname
* @param float $expected
*/
protected function assert_stat_equals($questionstats, $subquestionstats, $slot, $variant, $subqname, $statname, $expected) {
protected function assert_stat_equals($questionstats, $slot, $variant, $subqname, $statname, $expected) {

if ($variant === null && $subqname === null) {
$actual = $questionstats[$slot]->{$statname};
$actual = $questionstats->for_slot($slot)->{$statname};
} else if ($subqname !== null) {
$actual = $subquestionstats[$this->randqids[$slot][$subqname]]->{$statname};
$actual = $questionstats->for_subq($this->randqids[$slot][$subqname])->{$statname};
} else {
$actual = $questionstats[$slot]->variantstats[$variant]->{$statname};
$actual = $questionstats->for_slot($slot, $variant)->{$statname};
}
if (is_bool($expected) || is_string($expected)) {
$this->assertEquals($expected, $actual, "$statname for slot $slot");
Expand Down
Loading

0 comments on commit 16b2fc5

Please sign in to comment.