Skip to content

Commit

Permalink
Merge branch 'MDL-41761-master' of git://github.com/jamiepratt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Oct 8, 2013
2 parents 38c6dc4 + 6dd9362 commit 8fe9bbd
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 172 deletions.
5 changes: 2 additions & 3 deletions mod/quiz/report/attemptsreport.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ protected function init($mode, $formclass, $quiz, $cm, $course) {
$this->qmsubselect = quiz_report_qm_filter_select($quiz);

$this->form = new $formclass($this->get_base_url(),
array('qmsubselect' => $this->qmsubselect, 'quiz' => $quiz,
'currentgroup' => $currentgroup, 'context' => $this->context));
array('quiz' => $quiz, 'currentgroup' => $currentgroup, 'context' => $this->context));

return array($currentgroup, $students, $groupstudents, $allowed);
}
Expand All @@ -103,7 +102,7 @@ protected function get_base_url() {
* Get information about which students to show in the report.
* @param object $cm the coures module.
* @param object $course the course settings.
* @return an array with four elements:
* @return array with four elements:
* 0 => integer the current group id (0 for none).
* 1 => array ids of all the students in this course.
* 2 => array ids of all the students in the current group.
Expand Down
66 changes: 39 additions & 27 deletions mod/quiz/report/reportlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,52 +137,64 @@ function quiz_report_can_filter_only_graded($quiz) {
}

/**
* Given the quiz grading method return sub select sql to find the id of the
* one attempt that will be graded for each user. Or return
* empty string if all attempts contribute to final grade.
* This is a wrapper for {@link quiz_report_grade_method_sql} that takes the whole quiz object instead of just the grading method
* as a param. See definition for {@link quiz_report_grade_method_sql} below.
*
* @param object $quiz
* @param string $quizattemptsalias sql alias for 'quiz_attempts' table
* @return string sql to test if this is an attempt that will contribute towards the grade of the user
*/
function quiz_report_qm_filter_select($quiz, $quizattemptsalias = 'quiza') {
if ($quiz->attempts == 1) {
// This quiz only allows one attempt.
return '';
}
return quiz_report_grade_method_sql($quiz->grademethod, $quizattemptsalias);
}

switch ($quiz->grademethod) {
/**
* Given a quiz grading method return sql to test if this is an
* attempt that will be contribute towards the grade of the user. Or return an
* empty string if the grading method is QUIZ_GRADEAVERAGE and thus all attempts
* contribute to final grade.
*
* @param string $grademethod quiz grading method.
* @param string $quizattemptsalias sql alias for 'quiz_attempts' table
* @return string sql to test if this is an attempt that will contribute towards the graded of the user
*/
function quiz_report_grade_method_sql($grademethod, $quizattemptsalias = 'quiza') {
switch ($grademethod) {
case QUIZ_GRADEHIGHEST :
return "$quizattemptsalias.id = (
SELECT MIN(qa2.id)
FROM {quiz_attempts} qa2
WHERE qa2.quiz = $quizattemptsalias.quiz AND
qa2.userid = $quizattemptsalias.userid AND
COALESCE(qa2.sumgrades, 0) = (
SELECT MAX(COALESCE(qa3.sumgrades, 0))
FROM {quiz_attempts} qa3
WHERE qa3.quiz = $quizattemptsalias.quiz AND
qa3.userid = $quizattemptsalias.userid
)
)";
SELECT MIN(qa2.id)
FROM {quiz_attempts} qa2
WHERE qa2.quiz = $quizattemptsalias.quiz AND
qa2.userid = $quizattemptsalias.userid AND
COALESCE(qa2.sumgrades, 0) = (
SELECT MAX(COALESCE(qa3.sumgrades, 0))
FROM {quiz_attempts} qa3
WHERE qa3.quiz = $quizattemptsalias.quiz AND
qa3.userid = $quizattemptsalias.userid
)
)";

case QUIZ_GRADEAVERAGE :
return '';

case QUIZ_ATTEMPTFIRST :
return "$quizattemptsalias.id = (
SELECT MIN(qa2.id)
FROM {quiz_attempts} qa2
WHERE qa2.quiz = $quizattemptsalias.quiz AND
qa2.userid = $quizattemptsalias.userid)";
return "$quizattemptsalias.attempt = 1";

case QUIZ_ATTEMPTLAST :
return "$quizattemptsalias.id = (
SELECT MAX(qa2.id)
FROM {quiz_attempts} qa2
WHERE qa2.quiz = $quizattemptsalias.quiz AND
qa2.userid = $quizattemptsalias.userid)";
SELECT MAX(qa2.id)
FROM {quiz_attempts} qa2
WHERE qa2.quiz = $quizattemptsalias.quiz AND
qa2.userid = $quizattemptsalias.userid)";
}
}

/**
* Get the nuber of students whose score was in a particular band for this quiz.
* Get the number of students whose score was in a particular band for this quiz.
* @param number $bandwidth the width of each band.
* @param int $bands the number of bands
* @param int $quizid the quiz id.
Expand Down Expand Up @@ -225,10 +237,10 @@ function quiz_report_grade_bands($bandwidth, $bands, $quizid, $userids = array()
$data = $DB->get_records_sql_menu($sql, $params);

// We need to create array elements with values 0 at indexes where there is no element.
$data = $data + array_fill(0, $bands + 1, 0);
$data = $data + array_fill(0, $bands + 1, 0);
ksort($data);

// Place the maximum (prefect grade) into the last band i.e. make last
// Place the maximum (perfect grade) into the last band i.e. make last
// band for example 9 <= g <=10 (where 10 is the perfect grade) rather than
// just 9 <= g <10.
$data[$bands - 1] += $data[$bands];
Expand Down
79 changes: 51 additions & 28 deletions mod/quiz/report/statistics/classes/calculated.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,43 @@
*/
class quiz_statistics_calculated {

public function __construct($allattempts = null) {
if ($allattempts !== null) {
$this->allattempts = $allattempts;
/**
* @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,
* the default null value is used when constructing an instance whose values will be
* populated from a db record.
*/
public function __construct($whichattempts = null) {
if ($whichattempts !== null) {
$this->whichattempts = $whichattempts;
}
}

/**
* @var bool whether we are calculating calculate stats from all attempts.
* @var int which attempts we are calculating calculate stats from.
*/
public $allattempts;
public $whichattempts;

/* Following stats all described here : http://docs.moodle.org/dev/Quiz_statistics_calculations#Test_statistics */

public $firstattemptscount = 0;

public $allattemptscount = 0;

public $lastattemptscount = 0;

public $highestattemptscount = 0;

public $firstattemptsavg;

public $allattemptsavg;

public $lastattemptsavg;

public $highestattemptsavg;

public $median;

public $standarddeviation;
Expand All @@ -68,20 +84,34 @@ public function __construct($allattempts = null) {
*/
public $timemodified;

/**
* Count of attempts selected by $this->whichattempts
*
* @return int
*/
public function s() {
if ($this->allattempts) {
return $this->allattemptscount;
} else {
return $this->firstattemptscount;
}
return $this->get_field('count');
}

/**
* Average grade for the attempts selected by $this->whichattempts
*
* @return float
*/
public function avg() {
if ($this->allattempts) {
return $this->allattemptsavg;
} else {
return $this->firstattemptsavg;
}
return $this->get_field('avg');
}

/**
* Get the right field name to fetch a stat for these attempts that is calculated for more than one $whichattempts (count or
* avg).
*
* @param string $field name of field
* @return int|float
*/
protected function get_field($field) {
$fieldname = quiz_statistics_calculator::using_attempts_string_id($this->whichattempts).$field;
return $this->{$fieldname};
}

/**
Expand All @@ -97,6 +127,8 @@ public function get_formatted_quiz_info_data($course, $cm, $quiz) {
'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',
Expand Down Expand Up @@ -149,27 +181,18 @@ public function get_formatted_quiz_info_data($course, $cm, $quiz) {
$formattedvalue = $value;
}

$quizinfo[get_string($property, 'quiz_statistics', $this->using_attempts_string())] = $formattedvalue;
$quizinfo[get_string($property, 'quiz_statistics',
quiz_statistics_calculator::using_attempts_lang_string($this->whichattempts))] = $formattedvalue;
}

return $quizinfo;
}

/**
* @return string the appropriate lang string to describe this option.
*/
protected function using_attempts_string() {
if ($this->allattempts) {
return get_string('allattempts', 'quiz_statistics');
} else {
return get_string('firstattempts', 'quiz_statistics');
}
}

/**
* @var array of names of properties of this class that are cached in db record.
*/
protected $fieldsindb = array('allattempts', 'firstattemptscount', 'allattemptscount', 'firstattemptsavg', 'allattemptsavg',
protected $fieldsindb = array('whichattempts', 'firstattemptscount', 'allattemptscount', 'firstattemptsavg', 'allattemptsavg',
'lastattemptscount', 'highestattemptscount', 'lastattemptsavg', 'highestattemptsavg',
'median', 'standarddeviation', 'skewness',
'kurtosis', 'cic', 'errorratio', 'standarderror');

Expand Down
Loading

0 comments on commit 8fe9bbd

Please sign in to comment.