Skip to content

Commit

Permalink
MDL-43369 : quiz statistics - average across attempts
Browse files Browse the repository at this point in the history
where item seen and not across all attempts for subqs.
  • Loading branch information
jamiepratt committed Dec 13, 2013
1 parent 3dc57a1 commit 7cd9c85
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
13 changes: 5 additions & 8 deletions mod/quiz/report/statistics/qstats.php
Expand Up @@ -36,8 +36,6 @@ class quiz_statistics_question_stats {
public $questions;
public $subquestions = array();

protected $s;
protected $summarksavg;
protected $allattempts;

/** @var mixed states from which to calculate stats - iteratable. */
Expand All @@ -49,12 +47,8 @@ class quiz_statistics_question_stats {
/**
* Constructor.
* @param $questions the questions.
* @param $s the number of attempts included in the stats.
* @param $summarksavg the average attempt summarks.
*/
public function __construct($questions, $s, $summarksavg) {
$this->s = $s;
$this->summarksavg = $summarksavg;
public function __construct($questions) {

foreach ($questions as $slot => $question) {
$question->_stats = $this->make_blank_question_stats();
Expand All @@ -74,6 +68,7 @@ protected function make_blank_question_stats() {
$stats->s = 0;
$stats->totalmarks = 0;
$stats->totalothermarks = 0;
$stats->totalsumgrades = 0;
$stats->markvariancesum = 0;
$stats->othermarkvariancesum = 0;
$stats->covariancesum = 0;
Expand Down Expand Up @@ -285,6 +280,7 @@ public function compute_statistics() {
protected function initial_steps_walker($step, $stats, $positionstat = true) {
$stats->s++;
$stats->totalmarks += $step->mark;
$stats->totalsumgrades += $step->sumgrades;
$stats->markarray[] = $step->mark;

if ($positionstat) {
Expand Down Expand Up @@ -313,6 +309,7 @@ protected function initial_question_walker($stats) {
}

$stats->othermarkaverage = $stats->totalothermarks / $stats->s;
$stats->sumgradeaverage = $stats->totalsumgrades / $stats->s;

sort($stats->markarray, SORT_NUMERIC);
sort($stats->othermarksarray, SORT_NUMERIC);
Expand All @@ -334,7 +331,7 @@ protected function secondary_steps_walker($step, $stats) {
$othermarkdifference = $step->sumgrades - $step->mark -
$stats->othermarkaverage;
}
$overallmarkdifference = $step->sumgrades - $this->summarksavg;
$overallmarkdifference = $step->sumgrades - $stats->sumgradeaverage;

$sortedmarkdifference = array_shift($stats->markarray) - $stats->markaverage;
$sortedothermarkdifference = array_shift($stats->othermarksarray) -
Expand Down
3 changes: 1 addition & 2 deletions mod/quiz/report/statistics/report.php
Expand Up @@ -676,7 +676,6 @@ protected function compute_stats($quizid, $currentgroup, $nostudentsingroup,
return $this->get_emtpy_stats($questions, $firstattempts->countrecs,
$allattempts->countrecs);
}
$summarksavg = $usingattempts->total / $usingattempts->countrecs;

$quizstats = new stdClass();
$quizstats->allattempts = $useallattempts;
Expand Down Expand Up @@ -750,7 +749,7 @@ protected function compute_stats($quizid, $currentgroup, $nostudentsingroup,
}
}

$qstats = new quiz_statistics_question_stats($questions, $s, $summarksavg);
$qstats = new quiz_statistics_question_stats($questions);
$qstats->load_step_data($quizid, $currentgroup, $groupstudents, $useallattempts);
$qstats->compute_statistics();

Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/report/statistics/tests/statistics_test.php
Expand Up @@ -68,7 +68,7 @@ public function test_qstats() {
// Data is taken from questions mostly generated by
// contrib/tools/generators/generator.php.
$questions = $this->get_records_from_csv(__DIR__.'/fixtures/mdl_question.csv');
$this->qstats = new testable_quiz_statistics_question_stats($questions, 22, 10045.45455);
$this->qstats = new testable_quiz_statistics_question_stats($questions);
$this->qstats->set_step_data($steps);
$this->qstats->compute_statistics();

Expand Down

0 comments on commit 7cd9c85

Please sign in to comment.