MDL-14204 "Content for Quiz Statistics report table - Random_guess_score" added method random_guess_score to question type objects and a new function in questionlib that calls the question type method.

This commit is contained in:
jamiesensei 2008-06-16 13:29:00 +00:00
parent ed48af75b4
commit 6f51ed72be
12 changed files with 201 additions and 96 deletions

View file

@ -425,6 +425,16 @@ class question_match_qtype extends default_questiontype {
// This should almost certainly be overridden
return substr(implode(', ', $this->get_actual_response($question, $state)), 0, $length);
}
/**
* @param object $question
* @return integer a score out of 1 that the average random guess by a
* student might give.
*/
function get_random_guess_score($question) {
return 1 / count($question->options->subquestions);
}
/// BACKUP FUNCTIONS ////////////////////////////

View file

@ -514,6 +514,19 @@ class embedded_cloze_qtype extends default_questiontype {
}
return $responses;
}
/**
* @param object $question
* @return integer a score out of 1 that the average random guess by a
* student might give.
*/
function get_random_guess_score($question) {
$totalfraction = 0;
foreach (array_keys($question->options->questions) as $key){
$totalfraction += get_random_guess_score($question->options->questions[$key]);
}
return $totalfraction / count($question->options->questions);
}
/// BACKUP FUNCTIONS ////////////////////////////

View file

@ -396,7 +396,18 @@ class question_multichoice_qtype extends default_questiontype {
function response_summary($question, $state, $length = 80) {
return implode(',', $this->get_actual_response($question, $state));
}
/**
* @param object $question
* @return integer a score out of 1 that the average random guess by a
* student might give.
*/
function get_random_guess_score($question) {
$totalfraction = 0;
foreach ($question->options->answers as $answer){
$totalfraction += $answer->fraction;
}
return $totalfraction / count($question->options->answers);
}
/// BACKUP FUNCTIONS ////////////////////////////
/*

View file

@ -674,7 +674,15 @@ class default_questiontype {
return null;
}
}
/**
* @param object $question
* @return integer a score out of 1 that the average random guess by a
* student might give.
*/
function get_random_guess_score($question) {
return 0;
}
/**
* Return the actual response to the question in a given state
* for the question

View file

@ -101,7 +101,7 @@ class random_qtype extends default_questiontype {
AND parent = '0'
AND hidden = '0'
AND id NOT IN ($cmoptions->questionsinuse)
AND qtype NOT IN ($QTYPE_EXCLUDE_FROM_RANDOM)", '', 'id')) {
AND qtype NOT IN ($QTYPE_EXCLUDE_FROM_RANDOM)", array(), '', 'id')) {
$this->catrandoms[$question->category][$question->questiontext] =
draw_rand_array($catrandoms, count($catrandoms));
} else {

View file

@ -272,7 +272,20 @@ class question_randomsamatch_qtype extends question_match_qtype {
$result->responses = $answers;
return $result;
}
/**
* @param object $question
* @return integer a score out of 1 that the average random guess by a
* student might give.
*/
function get_random_guess_score($question) {
//Effectively $subquestions multi choice questions with equal weighting
//assuming a student has the intelligence to not select the same answer twice
//there is in each subquestion factorial($subquestions-1) chance of getting
//the answer right. There are factorial($subquestions) possible combinations of
//answers and it works out to an average grade of 1/$subquestions.
$subquestions = count($question->options->subquestions);
return 1/$subquestions;
}
/// BACKUP FUNCTIONS ////////////////////////////
/*

View file

@ -239,7 +239,20 @@ class question_shortanswer_qtype extends default_questiontype {
}
return $response;
}
/**
* @param object $question
* @return integer a score out of 1 that the average random guess by a
* student might give.
*/
function get_random_guess_score($question) {
$answers = &$question->options->answers;
foreach($answers as $aid => $answer) {
if ('*' == trim($answer->answer)){
return $answer->fraction;
}
}
return 0;
}
/// BACKUP FUNCTIONS ////////////////////////////
/*

View file

@ -245,6 +245,14 @@ class question_truefalse_qtype extends default_questiontype {
}
return $responses;
}
/**
* @param object $question
* @return integer a score out of 1 that the average random guess by a
* student might give.
*/
function get_random_guess_score($question) {
return 0.5;
}
/// BACKUP FUNCTIONS ////////////////////////////