/** * @param object $question * @return mixed either a integer score out of 1 that the average random * guess by a student might give or an empty string which means will not * calculate. */ function get_random_guess_score($question) { $totalfraction = 0; foreach (array_keys($question->options->questions) as $key) { $totalfraction += question_get_random_guess_score($question->options->questions[$key]); } return $totalfraction / count($question->options->questions); }
function col_random_guess_score($question){ $randomguessscore = question_get_random_guess_score($question); if (is_numeric($randomguessscore)){ return number_format($randomguessscore * 100, 2).'%'; } else { return $randomguessscore; // empty string returned by random question. } }