Commit 04853f27 authored by Tim Hunt's avatar Tim Hunt
Browse files

MDL-20636 Convert quiz statistics report.

parent 9b40c540
<?php
function quiz_report_statistics_cron(){
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Quiz statistics report cron code.
*
* @package quiz
* @subpackage statistics
* @copyright 2008 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/question/engine/compatibility.php');
/**
* Quiz statistics report cron code. Deletes cached data more than a certain age.
*/
function quiz_report_statistics_cron() {
global $DB;
if ($todelete = $DB->get_records_select_menu('quiz_statistics', 'timemodified < ?', array(time()-5*HOURSECS))){
list($todeletesql, $todeleteparams) = $DB->get_in_or_equal(array_keys($todelete));
if (!$DB->delete_records_select('quiz_statistics', "id $todeletesql", $todeleteparams)){
mtrace('Error deleting out of date quiz_statistics records.');
}
if (!$DB->delete_records_select('quiz_question_statistics', "quizstatisticsid $todeletesql", $todeleteparams)){
mtrace('Error deleting out of date quiz_question_statistics records.');
}
$expiretime = time() - 5*HOURSECS;
$todelete = $DB->get_records_select_menu('quiz_statistics', 'timemodified < ?', array($expiretime), '', 'id,1');
if (!$todelete) {
return true;
}
list($todeletesql, $todeleteparams) = $DB->get_in_or_equal(array_keys($todelete));
if (!$DB->delete_records_select('quiz_question_statistics', 'quizstatisticsid ' . $todeletesql, $todeleteparams)){
mtrace('Error deleting out of date quiz_question_statistics records.');
}
if (!$DB->delete_records_select('quiz_question_response_stats', 'quizstatisticsid ' . $todeletesql, $todeleteparams)) {
mtrace('Error deleting out of date quiz_question_response_stats records.');
}
if (!$DB->delete_records_select('quiz_statistics', 'id ' . $todeletesql, $todeleteparams)){
mtrace('Error deleting out of date quiz_statistics records.');
}
return true;
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Capability definitions for the quiz statistics report.
*
* For naming conventions, see lib/db/access.php.
* @package quiz
* @subpackage statistics
* @copyright 2008 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$capabilities = array(
'quizreport/statistics:view' => array(
'quiz/statistics:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
......
<?php
// This file is executed right after the install.xml
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Post-install script for the quiz statistics report.
* @package quiz
* @subpackage statistics
* @copyright 2010 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Post-install script
*/
function xmldb_quiz_statistics_install() {
global $DB;
......@@ -10,7 +34,6 @@ function xmldb_quiz_statistics_install() {
$record->name = 'statistics';
$record->displayorder = 8000;
$record->cron = 18000;
$record->capability = 'quizreport/statistics:view';
$DB->insert_record('quiz_report', $record);
}
\ No newline at end of file
$record->capability = 'quiz/statistics:view';
$DB->insert_record('quiz_reports', $record);
}
......@@ -31,8 +31,9 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="quizstatisticsid"/>
<FIELD NAME="quizstatisticsid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="questionid"/>
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="quizstatisticsid" NEXT="subquestion"/>
<FIELD NAME="subquestion" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="questionid" NEXT="s"/>
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="quizstatisticsid" NEXT="slot"/>
<FIELD NAME="slot" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The position in the quiz where this question appears" PREVIOUS="questionid" NEXT="subquestion"/>
<FIELD NAME="subquestion" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="slot" NEXT="s"/>
<FIELD NAME="s" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="subquestion" NEXT="effectiveweight"/>
<FIELD NAME="effectiveweight" TYPE="number" LENGTH="15" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" PREVIOUS="s" NEXT="negcovar"/>
<FIELD NAME="negcovar" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="effectiveweight" NEXT="discriminationindex"/>
......@@ -40,9 +41,10 @@
<FIELD NAME="discriminativeefficiency" TYPE="number" LENGTH="15" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" DECIMALS="5" PREVIOUS="discriminationindex" NEXT="sd"/>
<FIELD NAME="sd" TYPE="number" LENGTH="15" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="10" PREVIOUS="discriminativeefficiency" NEXT="facility"/>
<FIELD NAME="facility" TYPE="number" LENGTH="15" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="10" PREVIOUS="sd" NEXT="subquestions"/>
<FIELD NAME="subquestions" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" PREVIOUS="facility" NEXT="maxgrade"/>
<FIELD NAME="maxgrade" TYPE="number" LENGTH="12" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="7" PREVIOUS="subquestions" NEXT="positions"/>
<FIELD NAME="positions" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" COMMENT="positions in which this item appears. Only used for random questions." PREVIOUS="maxgrade"/>
<FIELD NAME="subquestions" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" PREVIOUS="facility" NEXT="maxmark"/>
<FIELD NAME="maxmark" TYPE="number" LENGTH="12" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="7" PREVIOUS="subquestions" NEXT="positions"/>
<FIELD NAME="positions" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" COMMENT="positions in which this item appears. Only used for random questions." PREVIOUS="maxmark" NEXT="randomguessscore"/>
<FIELD NAME="randomguessscore" TYPE="number" LENGTH="12" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" DECIMALS="7" COMMENT="An estimate of the score a student would get by guessing randomly." PREVIOUS="positions"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
......@@ -54,7 +56,7 @@
<FIELD NAME="quizstatisticsid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="questionid"/>
<FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="quizstatisticsid" NEXT="subqid"/>
<FIELD NAME="subqid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="questionid" NEXT="aid"/>
<FIELD NAME="aid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="subqid" NEXT="response"/>
<FIELD NAME="aid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="subqid" NEXT="response"/>
<FIELD NAME="response" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" PREVIOUS="aid" NEXT="rcount"/>
<FIELD NAME="rcount" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="response" NEXT="credit"/>
<FIELD NAME="credit" TYPE="number" LENGTH="15" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" PREVIOUS="rcount"/>
......
<?php
// This file keeps track of upgrades to
// the quiz statistics report.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// The commands in here will all be database-neutral,
// using the functions defined in lib/ddllib.php
/**
* Post-install script for the quiz statistics report.
* @package quiz
* @subpackage statistics
* @copyright 2008 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Quiz statistics report upgrade code.
*/
function xmldb_quiz_statistics_upgrade($oldversion) {
global $DB;
......@@ -13,7 +42,7 @@ function xmldb_quiz_statistics_upgrade($oldversion) {
$DB->set_field('quiz_report', 'cron', HOURSECS*5, array('name'=>'statistics'));
/// statistics savepoint reached
upgrade_plugin_savepoint(true, 2008072401, 'quizreport', 'statistics');
upgrade_plugin_savepoint(true, 2008072401, 'quiz', 'statistics');
}
if ($oldversion < 2008072500) {
......@@ -28,7 +57,7 @@ function xmldb_quiz_statistics_upgrade($oldversion) {
}
/// statistics savepoint reached
upgrade_plugin_savepoint(true, 2008072500, 'quizreport', 'statistics');
upgrade_plugin_savepoint(true, 2008072500, 'quiz', 'statistics');
}
if ($oldversion < 2008072800) {
......@@ -43,7 +72,7 @@ function xmldb_quiz_statistics_upgrade($oldversion) {
}
/// statistics savepoint reached
upgrade_plugin_savepoint(true, 2008072800, 'quizreport', 'statistics');
upgrade_plugin_savepoint(true, 2008072800, 'quiz', 'statistics');
}
if ($oldversion < 2008072801) {
......@@ -58,7 +87,7 @@ function xmldb_quiz_statistics_upgrade($oldversion) {
}
/// statistics savepoint reached
upgrade_plugin_savepoint(true, 2008072801, 'quizreport', 'statistics');
upgrade_plugin_savepoint(true, 2008072801, 'quiz', 'statistics');
}
if ($oldversion < 2008081500) {
......@@ -70,7 +99,7 @@ function xmldb_quiz_statistics_upgrade($oldversion) {
$dbman->change_field_type($table, $field);
/// statistics savepoint reached
upgrade_plugin_savepoint(true, 2008081500, 'quizreport', 'statistics');
upgrade_plugin_savepoint(true, 2008081500, 'quiz', 'statistics');
}
if ($oldversion < 2008082600) {
......@@ -96,7 +125,7 @@ function xmldb_quiz_statistics_upgrade($oldversion) {
}
/// statistics savepoint reached
upgrade_plugin_savepoint(true, 2008082600, 'quizreport', 'statistics');
upgrade_plugin_savepoint(true, 2008082600, 'quiz', 'statistics');
}
if ($oldversion < 2008090500) {
......@@ -130,7 +159,7 @@ function xmldb_quiz_statistics_upgrade($oldversion) {
}
/// statistics savepoint reached
upgrade_plugin_savepoint(true, 2008090500, 'quizreport', 'statistics');
upgrade_plugin_savepoint(true, 2008090500, 'quiz', 'statistics');
}
if ($oldversion < 2008111000) {
......@@ -150,14 +179,96 @@ function xmldb_quiz_statistics_upgrade($oldversion) {
}
/// statistics savepoint reached
upgrade_plugin_savepoint(true, 2008111000, 'quizreport', 'statistics');
upgrade_plugin_savepoint(true, 2008111000, 'quiz', 'statistics');
}
if ($oldversion < 2008112100) {
$DB->set_field('quiz_report', 'capability', 'quizreport/statistics:view', array('name'=>'statistics'));
/// statistics savepoint reached
upgrade_plugin_savepoint(true, 2008112100, 'quizreport', 'statistics');
upgrade_plugin_savepoint(true, 2008112100, 'quiz', 'statistics');
}
if ($oldversion < 2010031700) {
// Define field randomguessscore to be added to quiz_question_statistics
$table = new xmldb_table('quiz_question_statistics');
$field = new xmldb_field('randomguessscore', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'positions');
// Conditionally launch add field randomguessscore
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// statistics savepoint reached
upgrade_plugin_savepoint(true, 2010031700, 'quiz', 'statistics');
}
if ($oldversion < 2010032400) {
// Define field slot to be added to quiz_question_statistics
$table = new xmldb_table('quiz_question_statistics');
$field = new xmldb_field('slot', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'questionid');
// Conditionally launch add field slot
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// statistics savepoint reached
upgrade_plugin_savepoint(true, 2010032400, 'quiz', 'statistics');
}
if ($oldversion < 2010032401) {
/// Delete all cached data
$DB->delete_records('quiz_question_response_stats');
$DB->delete_records('quiz_question_statistics');
$DB->delete_records('quiz_statistics');
// Rename field maxgrade on table quiz_question_statistics to maxmark
$table = new xmldb_table('quiz_question_statistics');
$field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, null, null, null, 'subquestions');
// Launch rename field maxmark
$dbman->rename_field($table, $field, 'maxmark');
// statistics savepoint reached
upgrade_plugin_savepoint(true, 2010032401, 'quiz', 'statistics');
}
if ($oldversion < 2010062200) {
// Changing nullability of field aid on table quiz_question_response_stats to null
$table = new xmldb_table('quiz_question_response_stats');
$field = new xmldb_field('aid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'subqid');
// Launch change of nullability for field aid
$dbman->change_field_notnull($table, $field);
// statistics savepoint reached
upgrade_plugin_savepoint(true, 2010062200, 'quiz', 'statistics');
}
if ($oldversion < 2010070301) {
// Changing type of field maxmark on table quiz_question_statistics to number
$table = new xmldb_table('quiz_question_statistics');
$field = new xmldb_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, null, null, null, 'subquestions');
// Launch change of type for field maxmark
$dbman->change_field_type($table, $field);
// statistics savepoint reached
upgrade_plugin_savepoint(true, 2010070301, 'quiz', 'statistics');
}
if ($oldversion < 2011021500) {
$DB->set_field('quiz_reports', 'capability', 'quiz/statistics:view',
array('name' => 'statistics'));
// statistics savepoint reached
upgrade_plugin_savepoint(true, 2011021500, 'quiz', 'statistics');
}
return true;
......
......@@ -23,9 +23,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['actualresponse'] = 'Actual response';
$string['allattempts'] = 'all attempts';
$string['allattemptsavg'] = 'Average grade of all attempts';
$string['allattemptscount'] = 'Total number of attempts';
$string['allattemptscount'] = 'Total number of complete graded attempts';
$string['analysisofresponses'] = 'Analysis of responses';
$string['analysisofresponsesfor'] = 'Analysis of responses for {$a}.';
$string['attempts'] = 'Attempts';
......@@ -34,6 +36,7 @@ $string['attemptsfirst'] = 'first attempt';
$string['backtoquizreport'] = 'Back to main statistics report page.';
$string['calculatefrom'] = 'Calculate statistics from';
$string['cic'] = 'Coefficient of internal consistency (for {$a})';
$string['completestatsfilename'] = 'completestats';
$string['count'] = 'Count';
$string['coursename'] = 'Course name';
$string['detailedanalysis'] = 'More detailed analysis of the responses to this question';
......@@ -53,12 +56,13 @@ $string['errorstatisticsquestions'] = 'Error fetching data to calculate statisti
$string['facility'] = 'Facility index';
$string['firstattempts'] = 'first attempts';
$string['firstattemptsavg'] = 'Average grade of first attempts';
$string['firstattemptscount'] = 'Number of first attempts';
$string['firstattemptscount'] = 'Number of complete graded first attempts';
$string['frequency'] = 'Frequency';
$string['intended_weight'] = 'Intended weight';
$string['kurtosis'] = 'Score distribution kurtosis (for {$a})';
$string['lastcalculated'] = 'Last calculated {$a->lastcalculated} ago there have been {$a->count} attempts since then.';
$string['median'] = 'Median grade (for {$a})';
$string['modelresponse'] = 'Model response';
$string['negcovar'] = 'Negative covariance of grade with total attempt grade';
$string['negcovar_help'] = 'This question\'s grade for this set of attempts on the quiz varies in an opposite way to the overall attempt grade. This means overall attempt grade tends to be below average when the grade for this question is above average and vice-versa.
......@@ -73,6 +77,7 @@ $string['questioninformation'] = 'Question information';
$string['questionname'] = 'Question name';
$string['questionnumber'] = 'Q#';
$string['questionstatistics'] = 'Question statistics';
$string['questionstatsfilename'] = 'questionstats';
$string['questiontype'] = 'Question type';
$string['quizinformation'] = 'Quiz information';
$string['quizname'] = 'Quiz name';
......@@ -80,7 +85,7 @@ $string['quizoverallstatistics'] = 'Quiz overall statistics';
$string['quizstructureanalysis'] = 'Quiz structure analysis';
$string['random_guess_score'] = 'Random guess score';
$string['recalculatenow'] = 'Recalculate now';
$string['response'] = 'Answer';
$string['response'] = 'Response';
$string['skewness'] = 'Score distribution skewness (for {$a})';
$string['standarddeviation'] = 'Standard deviation (for {$a})';
$string['standarddeviationq'] = 'Standard deviation';
......
<?php
class qstats{
/**
* @var mixed states from which to calculate stats - iteratable.
*/
var $states;
var $sumofgradevariance = 0;
var $questions;
var $subquestions = array();
var $randomselectors = array();
var $responses = array();
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Quiz statistics report calculations class.
*
* @package quiz_statistics
* @copyright 2008 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* This class has methods to compute the question statistics from the raw data.
*
* @copyright 2008 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quiz_statistics_question_stats {
public $questions;
public $subquestions = array();
function qstats($questions, $s, $sumgradesavg){
protected $s;
protected $summarksavg;
protected $allattempts;
/** @var mixed states from which to calculate stats - iteratable. */
protected $lateststeps;
protected $sumofmarkvariance = 0;
protected $randomselectors = array();
/**
* 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->sumgradesavg = $sumgradesavg;
$this->summarksavg = $summarksavg;
foreach (array_keys($questions) as $qid){
$questions[$qid]->_stats = $this->stats_init_object();
foreach ($questions as $slot => $question) {
$question->_stats = $this->make_blank_question_stats();
$question->_stats->questionid = $question->id;
$question->_stats->slot = $slot;
}
$this->questions = $questions;
}
function stats_init_object(){
$statsinit = new stdClass();
$statsinit->s = 0;
$statsinit->totalgrades = 0;
$statsinit->totalothergrades = 0;
$statsinit->gradevariancesum = 0;
$statsinit->othergradevariancesum = 0;
$statsinit->covariancesum = 0;
$statsinit->covariancemaxsum = 0;
$statsinit->subquestion = false;
$statsinit->subquestions = '';
$statsinit->covariancewithoverallgradesum = 0;
$statsinit->gradearray = array();
$statsinit->othergradesarray = array();
return $statsinit;
/**
* @return object ready to hold all the question statistics.
*/
protected function make_blank_question_stats() {
$stats = new stdClass;
$stats->slot = null;
$stats->s = 0;
$stats->totalmarks = 0;
$stats->totalothermarks = 0;
$stats->markvariancesum = 0;
$stats->othermarkvariancesum = 0;
$stats->covariancesum = 0;
$stats->covariancemaxsum = 0;
$stats->subquestion = false;
$stats->subquestions = '';
$stats->covariancewithoverallmarksum = 0;
$stats->randomguessscore = null;
$stats->markarray = array();
$stats->othermarksarray = array();
return $stats;
}
function get_records($quizid, $currentgroup, $groupstudents, $allattempts){
/**
* Load the data that will be needed to perform the calculations.
*
* @param integer $quizid the quiz id.
* @param integer $currentgroup the current group. 0 for none.
* @param array $groupstudents students in this group.
* @param boolean $allattempts use all attempts, or just first attempts.
*/
public function load_step_data($quizid, $currentgroup, $groupstudents, $allattempts) {
global $DB;
$this->allattempts = $allattempts;
list($qsql, $qparams) = $DB->get_in_or_equal(array_keys($this->questions), SQL_PARAMS_NAMED, 'q0000');
list($fromqa, $whereqa, $qaparams) = quiz_report_attempts_sql($quizid, $currentgroup, $groupstudents, $allattempts);
$sql = 'SELECT qs.id, ' .
'qs.question, ' .
'qa.sumgrades, ' .
'qs.grade, ' .
'qs.answer ' .
'FROM ' .
'{question_sessions} qns, ' .
'{question_states} qs, '.
$fromqa.' '.
'WHERE ' .$whereqa.
'AND qs.question '.$qsql.' '.
'AND qns.attemptid = qa.uniqueid '.
'AND qns.newgraded = qs.id';
$this->states = $DB->get_records_sql($sql, $qaparams + $qparams);
if ($this->states === false){
print_error('errorstatisticsquestions', 'quiz_statistics');
}
}
list($fromqa, $whereqa, $qaparams) = quiz_statistics_attempts_sql(
$quizid, $currentgroup, $groupstudents, $allattempts, false);
function _initial_states_walker($state, &$stats, $positionstat = true){
$stats->s++;
$stats->totalgrades += $state->grade;
if ($positionstat){
$stats->totalothergrades += $state->sumgrades - $state->grade;
} else {
$stats->totalothergrades += $state->sumgrades;
}
//need to sort these to calculate max covariance :
$stats->gradearray[] = $state->grade;
if ($positionstat){
$stats->othergradesarray[] = $state->sumgrades - $state->grade;
} else {
$stats->othergradesarray[] = $state->sumgrades;
}
$this->lateststeps = $DB->get_records_sql("
SELECT
qas.id,
quiza.sumgrades,
qa.questionid,
qa.slot,
qa.maxmark,
qas.fraction * qa.maxmark as mark
FROM $fromqa