From: jamiesensei Date: Tue, 10 Jun 2008 16:18:10 +0000 (+0000) Subject: MDL-14203 "split report into two seperate reports - Quiz Statistics report and Indivi... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0c1c764e8257d6db589ed0d89371d4b49b8972d7;p=moodle.git MDL-14203 "split report into two seperate reports - Quiz Statistics report and Individual Item Analysis report" started quiz statistics report in directory 'statistics' --- diff --git a/lang/en_utf8/quiz_statistics.php b/lang/en_utf8/quiz_statistics.php new file mode 100644 index 0000000000..dfed5f6110 --- /dev/null +++ b/lang/en_utf8/quiz_statistics.php @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index eb0254c53e..42304c9800 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -243,4 +243,16 @@ function quiz_report_feedback_for_grade($grade, $quizid) { return $feedbacktext; } + +function quiz_report_scale_sumgrades_as_percentage($rawgrade, $quiz, $round = true) { + if ($quiz->sumgrades) { + $grade = $rawgrade * 100 / $quiz->sumgrades; + if ($round) { + $grade = number_format($grade, $quiz->decimalpoints); + } + } else { + $grade = 0; + } + return $grade.' %'; +} ?> diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php new file mode 100644 index 0000000000..57eab21a08 --- /dev/null +++ b/mod/quiz/report/statistics/report.php @@ -0,0 +1,223 @@ +libdir.'/tablelib.php'); +require_once($CFG->dirroot.'/mod/quiz/report/statistics/statistics_form.php'); +require_once($CFG->dirroot.'/mod/quiz/report/statistics/statistics_table.php'); + +class quiz_report extends quiz_default_report { + + /** + * Display the report. + */ + function display($quiz, $cm, $course) { + global $CFG, $DB; + + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + + $download = optional_param('download', '', PARAM_ALPHA); + + $pageoptions = array(); + $pageoptions['id'] = $cm->id; + $pageoptions['q'] = $quiz->id; + $pageoptions['mode'] = 'statistics'; + + $reporturl = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions); + + $mform = new mod_quiz_report_statistics($reporturl); + if ($fromform = $mform->get_data()){ + $useallattempts = $fromform->useallattempts; + if ($fromform->useallattempts){ + set_user_preference('quiz_report_statistics_useallattempts', $fromform->useallattempts); + } else { + unset_user_preference('quiz_report_statistics_useallattempts'); + } + } else { + $useallattempts = get_user_preferences('quiz_report_statistics_useallattempts', 0); + } + + /// find out current groups mode + $currentgroup = groups_get_activity_group($cm, true); + + if (!empty($currentgroup)) { + // all users who can attempt quizzes and who are in the currently selected group + if (!$groupstudents = get_users_by_capability($context, 'mod/quiz:attempt','','','','',$currentgroup,'',false)){ + $groupstudents = array(); + } + $groupstudentslist = join(',', array_keys($groupstudents)); + $allowedlist = $groupstudentslist; + } + + $questions = quiz_report_load_questions($quiz); + + $table = new quiz_report_statistics_table($quiz , $questions, $reporturl); + $table->is_downloading($download, get_string('reportstatistics','quiz_statistics'), + "$course->shortname ".format_string($quiz->name,true)); + if (!$table->is_downloading()) { + // Only print headers if not asked to download data + $this->print_header_and_tabs($cm, $course, $quiz, "statistics"); + } + + if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used + if (!$table->is_downloading()) { + groups_print_activity_menu($cm, $reporturl->out()); + } + } + + + // Print information on the number of existing attempts + if (!$table->is_downloading()) { //do not print notices when downloading + print_heading(get_string('quizinformation', 'quiz_statistics')); + $quizinformationtable = new object(); + $quizinformationtable->align = array('center', 'center'); + $quizinformationtable->width = '60%'; + $quizinformationtable->class = 'generaltable titlesleft'; + $quizinformationtable->data = array(); + $quizinformationtable->data[] = array(get_string('quizname', 'quiz_statistics'), $quiz->name); + $quizinformationtable->data[] = array(get_string('coursename', 'quiz_statistics'), $course->fullname); + if ($cm->idnumber){ + $quizinformationtable->data[] = array(get_string('coursename', 'quiz_statistics'), $cm->idnumber); + } + if ($quiz->timeopen){ + $quizinformationtable->data[] = array(get_string('quizopen', 'quiz'), userdate($quiz->timeopen)); + } + if ($quiz->timeclose){ + $quizinformationtable->data[] = array(get_string('quizclose', 'quiz'), userdate($quiz->timeclose)); + } + if ($quiz->timeopen && $quiz->timeclose){ + $quizinformationtable->data[] = array(get_string('duration'), format_time($quiz->timeclose - $quiz->timeopen)); + } + print_table($quizinformationtable); + } + if (!$table->is_downloading()) { + // Print display options + $mform->set_data(array('useallattempts' => $useallattempts)); + $mform->display(); + } + + $sql = 'SELECT (attempt=1) AS isfirst, COUNT(1) AS countrecs, SUM(sumgrades) AS total ' . + 'FROM {quiz_attempts} ' . + 'WHERE quiz = :quiz AND preview=0 AND timefinish !=0 ' . + 'GROUP BY (attempt=1)'; + + if (!$attempttotals = $DB->get_records_sql($sql, array('quiz' => $quiz->id))){ + print_heading(get_string('noattempts','quiz')); + return true; + } else { + $firstattempt = $attempttotals[1]; + $allattempts = new object(); + $allattempts->countrecs = $firstattempt->countrecs + + (isset($attempttotals[0])?$attempttotals[0]->countrecs:0); + $allattempts->total = $firstattempt->total + + (isset($attempttotals[0])?$attempttotals[0]->total:0); + } + + if (!$table->is_downloading()) { + print_heading(get_string('quizoverallstatistics', 'quiz_statistics')); + $quizoverallstatistics = new object(); + $quizoverallstatistics->align = array('center', 'center'); + $quizoverallstatistics->width = '60%'; + $quizoverallstatistics->class = 'generaltable titlesleft'; + $quizoverallstatistics->data = array(); + $quizoverallstatistics->data[] = array(get_string('nooffirstattempts', 'quiz_statistics'), $firstattempt->countrecs); + $quizoverallstatistics->data[] = array(get_string('noofallattempts', 'quiz_statistics'), $allattempts->countrecs); + $quizoverallstatistics->data[] = array(get_string('firstattemptsavg', 'quiz_statistics'), quiz_report_scale_sumgrades_as_percentage($firstattempt->total / $firstattempt->countrecs, $quiz)); + $quizoverallstatistics->data[] = array(get_string('allattemptsavg', 'quiz_statistics'), quiz_report_scale_sumgrades_as_percentage($allattempts->total / $allattempts->countrecs, $quiz)); + print_table($quizoverallstatistics); + } + //get the median + + + if (!$table->is_downloading()) { + if ($useallattempts){ + $usingattempts = $allattempts; + $usingattempts->heading = get_string('statsforallattempts', 'quiz_statistics'); + $usingattempts->sql = ''; + } else { + $usingattempts = $firstattempt; + $usingattempts->heading = get_string('statsforfirstattempts', 'quiz_statistics'); + $usingattempts->sql = 'AND attempt=1 '; + } + print_heading($usingattempts->heading); + if (($usingattempts->countrecs/2)==floor($usingattempts->countrecs/2)){ + //even number of attempts + $limitoffset = (floor($usingattempts->countrecs/2)) - 1; + $limit = 2; + } else { + $limitoffset = ($usingattempts->countrecs/2) - 1; + $limit = 1; + } + $sql = 'SELECT id, sumgrades ' . + 'FROM {quiz_attempts} ' . + 'WHERE quiz = :quiz AND preview=0 AND timefinish !=0 ' . + $usingattempts->sql. + 'ORDER BY sumgrades'; + if (!$mediangrades = $DB->get_records_sql_menu($sql, array('quiz' => $quiz->id), $limitoffset, $limit)){ + print_error('errormedian', 'quiz_statistics'); + } + if (count($mediangrades)==1){ + $median = array_shift($mediangrades); + } else { + $median = array_shift($mediangrades); + $median += array_shift($mediangrades); + $median = $median /2; + } + //fetch sum of squared, cubed and power 4d + //differences between grades and mean grade + $mean = $usingattempts->total / $usingattempts->countrecs; + $sql = "SELECT " . + "SUM(POWER((sumgrades - ?),2)) AS power2, " . + "SUM(POWER((sumgrades - ?),3)) AS power3, ". + "SUM(POWER((sumgrades - ?),4)) AS power4 ". + "FROM {quiz_attempts} " . + "WHERE quiz = ? AND preview=0 AND timefinish !=0 " . + $usingattempts->sql. + "ORDER BY sumgrades"; + $params = array($mean, $mean, $mean, $quiz->id); + if (!$powers = $DB->get_record_sql($sql, $params)){ + print_error('errorpowers', 'quiz_statistics'); + } + + $s = $usingattempts->countrecs; + + $sd = sqrt($powers->power2 / ($s -1)); + + $m2= $powers->power2 / $s; + $m3= $powers->power3 / $s; + $m4= $powers->power4 / $s; + + $k2= $s*$m2/($s-1); + $k3= $s*$s*$m3/(($s-1)*($s-2)); + $k3= $s*$s*$s*$m3/(($s-1)*($s-2)*($s-3)); + $k4= $s*$s*$s*(($s+1)*$m4-3*($s-1)*$m2*$m2)/(($s-1)*($s-2)*($s-3)); + + $skewness = $k3 / (pow($k2, 2/3)); + $kurtosis = $k4 / ($k2*$k2); + + $quizattsstatistics = new object(); + $quizattsstatistics->align = array('center', 'center'); + $quizattsstatistics->width = '60%'; + $quizattsstatistics->class = 'generaltable titlesleft'; + $quizattsstatistics->data = array(); + + $quizattsstatistics->data[] = array(get_string('median', 'quiz_statistics'), quiz_report_scale_sumgrades_as_percentage($median, $quiz)); + $quizattsstatistics->data[] = array(get_string('standarddeviation', 'quiz_statistics'), quiz_report_scale_sumgrades_as_percentage($sd, $quiz)); + $quizattsstatistics->data[] = array(get_string('skewness', 'quiz_statistics'), $skewness); + $quizattsstatistics->data[] = array(get_string('kurtosis', 'quiz_statistics'), $kurtosis); + print_table($quizattsstatistics); + } + + return true; + } + +} + + +?> diff --git a/mod/quiz/report/statistics/statistics_form.php b/mod/quiz/report/statistics/statistics_form.php new file mode 100644 index 0000000000..4c599c544d --- /dev/null +++ b/mod/quiz/report/statistics/statistics_form.php @@ -0,0 +1,20 @@ +libdir/formslib.php"; +class mod_quiz_report_statistics extends moodleform { + + function definition() { + global $COURSE; + $mform =& $this->_form; +//------------------------------------------------------------------------------- + $mform->addElement('header', 'preferencespage', get_string('preferencespage', 'quiz_overview')); + + $options = array(); + $options[0] = get_string('attemptsfirst','quiz_statistics'); + $options[1] = get_string('attemptsall','quiz_statistics'); + $mform->addElement('select', 'useallattempts', get_string('calculatefrom', 'quiz_statistics'), $options); + $mform->setDefault('useallattempts', 0); +//------------------------------------------------------------------------------- + $this->add_action_buttons(false, get_string('preferencessave', 'quiz_overview')); + } +} +?> diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index ae797c0d80..eb2d96a221 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -3933,6 +3933,10 @@ table.quizreviewsummary td.cell { width: 80%; margin: auto; } +#mod-quiz-report table.titlesleft td.c0 +{ + font-weight: bold; +} #mod-quiz-report table#attempts, #mod-quiz-report h2.main { clear: both;