Quiz Score Breakdown by Category

Quiz Score Breakdown by Category

โดย Stephen Chasey -
Number of replies: 8
Hello everyone. I asked a while ago about by-category score details for quizzes and saw that many other people wanted this as well. Anyway, I made a quick way to do it that:
  • gives you the option to show the score details to the user for each category in the quiz in the order the category appears in the quiz
  • works with multiple-page quizzes
  • can easily be tweaked in format and content
If anyone's interested, give it a try and let me know what you think. It should also work in moodle 1.7, but I have not tested thoroughly in later versions. Hope you don't mind the big post. A zipped pdf of the instructions is attached as well.

Adding Question Category Grade Breakdown for Quizzes in Moodle 1.6.2

  1. Add a new column showcategorygrades to the quiz table. This will be used to make the category grade breakdown optional.

    ALTER TABLE mdl_quiz ADD COLUMN showcategorygrades int2;
    ALTER TABLE mdl_quiz ALTER COLUMN showcategorygrades SET STORAGE PLAIN;
    ALTER TABLE mdl_quiz ALTER COLUMN showcategorygrades SET DEFAULT 0;


  2. Add the following lines to quiz/config.html html to show the control for toggling the showcategorygrades property when configuring quizzes in your moodle.

    // SRC: Set the category grade control if it is not set
    if (!isset($form->showcategorygrades)) {
    $form->showcategorygrades = $CFG->quiz_showcategorygrades;
    }



    <!-- SRC: Show the category grade edit controls -->
    <tr valign="top">
    <td align="right"><b><?php print_string("showcategorygrades", "quiz") ?>:</b></td>
    <td>
    <?php
    choose_from_menu ($yesnooptions, "showcategorygrades", $form->showcategorygrades, "");
    helpbutton("showcategorygrades", get_string("showcategorygrades", "quiz"), "quiz");
    ?>
    </td>
    <td align="center">
    <input type="hidden" name="fix_showcategorygrades" value="0" />
    <input type="checkbox" name="fix_showcategorygrades" value="1" <?php p($CFG->quiz_fix_showcategorygrades ? “checked" : "") ?> />
    </td>
    </tr>


  3. Add the following lines to quiz/mod.html to show the control for toggling the showcategorygrades property when editing a quiz.

    // SRC: Set the category grade control if it is not set
    if (!isset($form->showcategorygrades)) {
    $form->showcategorygrades = $CFG->quiz_showcategorygrades;
    }



    <!-- SRC: Show the category grade edit controls -->

    <?php if (!$CFG->quiz_fix_decimalpoints) { ?>
    <tr valign="top">
    <td align="right"><b><?php print_string("showcategorygrades", "quiz") ?>:</b></td>
    <td>
    <?php
    choose_from_menu ($yesnooptions, "showcategorygrades", $form->showcategorygrades, "");
    helpbutton("showcategorygrades", get_string("showcategorygrades", "quiz"), "quiz");
    ?>
    </td>
    </tr>
    <?php } else $fix=1 ?>


  4. Add the following line to lang/en-UTF8/quiz.php. This is the English translation for the control label in the forms you edited in steps 2 and 3.
    $string['showcategorygrades'] = 'Show category grades';

  5. Add the following lines to quiz/review.php. This is what will actually show the category grade breakdown in the quiz report.

    // SRC: Add categories string for breakdown section label
    $strcategories = get_string("categories", "quiz");

    // SRC: Load all the questions for the category breakdown if report is paginated
    if (!$showall && $quiz->showcategorygrades == 1) {
    $allquizquestionids = quiz_questions_in_quiz($attempt->layout);
    $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
    " FROM {$CFG->prefix}question q,".
    " {$CFG->prefix}quiz_question_instances i".
    " WHERE i.quiz = '$quiz->id' AND q.id = i.question".
    " AND q.id IN ($allquizquestionids)";
    if (!$allquestions = get_records_sql($sql)) {
    error(
    'No questions found');
    }

    // Load the question type specific information
    if (!get_question_options($allquestions)) {
    error(
    'Could not load question options');
    }

    // Restore the question sessions to their most recent states
    // creating new sessions where required
    if (!$allstates = get_question_states($allquestions, $quiz, $attempt)) {
    error(
    'Could not restore question sessions');
    }
    }
    if ($showall && $quiz->showcategorygrades == 1) {
    $allquestions = $questions;
    $allstates = $states;
    }



    // SRC: Category breakdown if it is enabled.
    if ($quiz->showcategorygrades == 1) {
    $categorybreakdown = array();
    $gradescale = $quiz->grade/$quiz->sumgrades;
    foreach ($allquestions as $question) {
    if (!isset ($categorybreakdown[$question->category])) {
    $categorybreakdown[$question->category] = array();
    $questioncategory = get_record('question_categories', 'id', $question->category);
    $categorybreakdown[$question->category]["categoryname"] = $questioncategory->name;
    $categorybreakdown[$question->category]["maxgrade"] = 0;
    $categorybreakdown[$question->category]["scaledmaxgrade"] = 0;
    $categorybreakdown[$question->category]["rawgrade"] = 0;
    $categorybreakdown[$question->category]["scaledrawgrade"] = 0;
    $categorybreakdown[$question->category]["grade"] = 0;
    $categorybreakdown[$question->category]["scaledgrade"] = 0;
    }
    $categorybreakdown[$question->category]["maxgrade"] += $question->maxgrade;
    $categorybreakdown[$question->category]["scaledmaxgrade"] += $question->maxgrade*$gradescale;
    $categorybreakdown[$question->category]["rawgrade"] += $allstates[$question->id]->raw_grade;
    $categorybreakdown[$question->category]["scaledrawgrade"] += $allstates[$question->id]->raw_grade*$gradescale;
    $categorybreakdown[$question->category]["grade"] += $allstates[$question->id]->grade;
    $categorybreakdown[$question->category]["scaledgrade"] += $allstates[$question->id]->grade*$gradescale;
    }
    $cattable->align = array("right", "left");
    foreach ($categorybreakdown as $catinfo) {
    $categorypercentage = round(($catinfo["rawgrade"]/$catinfo["maxgrade"])*100,0);
    $cattable->data[] = array($catinfo["categoryname"], round($catinfo["scaledgrade"],$CFG->quiz_decimalpoints)."/".round($catinfo["scaledmaxgrade"],$CFG->quiz_decimalpoints)." (".$categorypercentage."%)");
    }
    }



    // SRC: Print category breakdown
    if ($cattable) {
    echo '<br/><center>'.$strcategories.'</center>';
    print_table(
    $cattable);
    }

  6. Create a new file in \lang\en_utf8\help\quiz named showcategorygrades.html. This is the help file for this setting.

    <p align="center"><b>Show Category Grades</b></p>

    <p>If you enable this option, a question category grade breakdown will be displayed on the quiz results page.</p>

    <p>Categories will be listed in the order they appear in the quiz.</p>

    <p>The intention is to provide students with more detailed feedback regarding their quiz performance.</p>
Steve
การประเมินโดยเฉลี่ย: -
In reply to Stephen Chasey

Re: Quiz Score Breakdown by Category

โดย Tony Ruggiero -
Stephen:

Have you ported this over to v1.8+ yet?

If you could share that if you have. It seems mod.html has been depreciated.

Thanks,
Tony
การประเมินโดยเฉลี่ย: -
In reply to Tony Ruggiero

Re: Quiz Score Breakdown by Category

โดย Tim Hunt -
รูปภาพของCore developers รูปภาพของDocumentation writers รูปภาพของParticularly helpful Moodlers รูปภาพของPeer reviewers รูปภาพของPlugin developers
The equivalent in 1.8 is mod_form.php, which is in a different, much nicer format.
การประเมินโดยเฉลี่ย: -
In reply to Tim Hunt

Re: Quiz Score Breakdown by Category

โดย Tony Ruggiero -
Tim:

You've done a wonderful job in fixing the Quiz mod. I am not a programmer by any means and just helping out a friend. I can't seem to figure out where to put his code on the new mod_form.php page.

Thanks,
Tony
การประเมินโดยเฉลี่ย: -
In reply to Tony Ruggiero

Re: Quiz Score Breakdown by Category

โดย Tim Hunt -
รูปภาพของCore developers รูปภาพของDocumentation writers รูปภาพของParticularly helpful Moodlers รูปภาพของPeer reviewers รูปภาพของPlugin developers
It will need to be different code in mod_form.php, doing roughly the same thing, but using the new libraries. Sorry, I don't have the time to work out the details.
การประเมินโดยเฉลี่ย: -
In reply to Tim Hunt

Re: Quiz Score Breakdown by Category

โดย Stephen Chasey -
Hi Guys,

Sorry I've been out of touch. Just got back to Tokyo after three weeks in Amsterdam on business. I will be happy to migrate this feature into 1.8 this week. I'll post new instructions soon.

Steve
การประเมินโดยเฉลี่ย: -
In reply to Stephen Chasey

Re: Quiz Score Breakdown by Category

โดย Stephen Chasey -
Still quite busy at the regular job. If this is urgent to anyone, let me know and I will try to get to it quicker.

Steve
การประเมินโดยเฉลี่ย: -
In reply to Stephen Chasey

Re: Quiz Score Breakdown by Category

โดย Skippy Bosco -
Hey Stephen,

I know it has been almost a year, checking to see if you ever made any progress on getting this ported to 1.8 (or now 1.9) or if there is a new way to do it that I'm missing (gradebook?)

Thanks,
Frank
การประเมินโดยเฉลี่ย: -