Multiple grade quizzes

Multiple grade quizzes

de Paul Tero -
Número de respuestas: 13
Hello,

I've been looking at ways for quizzes to give multiple grades. For example, I want to implement a simplified personality test which tells you how creative, numerical, analytical, etc you are.

As far as I can see, quizzes currently only give a single grade, like 83%. And I would like them to give multiple grades, like 80% creative, 40% numerical, etc.

I found a simplish way of doing this, by computing grades by question category. So the administrator could create Creative and Numerical categories, and put questions from both categories onto the same quiz. When the quiz results are comuputed it will compute separate results on a category-by-category basis. A sample set of results is shown in the attached image.

So my questions are: Is there a built-in way for Moodle to already do this? If not, can anyone see any problems with the method I've adopted?

To test out this method, you'll need to a new field in the quiz_attempts table:
ALTER TABLE `mdl_quiz_attempts` ADD `categorygrades` VARCHAR( 255 ) NOT NULL AFTER `sumgrades`

And some changes to the code between the indicated bold lines in mod/quiz/attempt.php (around like 294):  
        $questionidarray = explode(',', $questionids);
        $catraw = $catmax = $catperc = array(); // blank arrays to store category information
         foreach($questionidarray as $i) {
            if (!isset($actions[$i])) {
                $actions[$i]->responses = array('' => '');
            }
            $actions[$i]->timestamp = $timestamp;
            quiz_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt);
            if (!isset ($catraw[$questions[$i]->category])) { // if this category has not been seen before
                $catraw[$questions[$i]->category] = 0; // set the raw total to 0
                $catmax[$questions[$i]->category] = 0; // set the maximum possible points to 0
            }
            $catraw[$questions[$i]->category] += $states[$i]->raw_grade; // add to the raw grade achieved for this category
            $catmax[$questions[$i]->category] += $questions[$i]->maxgrade; // add to the max grade possible
            quiz_save_question_session($questions[$i], $states[$i]);
        }

        foreach ($catraw as $categoryid=>$categorygrade) { // for each category involved in this quiz
            if ($category = get_record('quiz_categories', 'id', $categoryid)) { // look up the category name
                array_push ($catperc, $category->name.': '.round ($categorygrade/$catmax[$categoryid]*100).'%');
            }
        }
        sort ($catperc); // sort the categories by key
        $attempt->categorygrades = join ("\n", $catperc); // put this information in the new categorygrades field
        $attempt->timemodified = $timestamp;

Displaying the results required a change to mod/quiz/review.php around line 178:
        $table->data[] = array("$strgrade:", $grade.get_string('outof', 'quiz').$quiz->grade.nl2br("\n".$attempt->categorygrades));

Thank you,
Paul


Adjunto categorygrades.gif
Promedio de valoraciones: -
En respuesta a Paul Tero

Re: Multiple grade quizzes

de Chardelle Busch -
Imagen de Core developers
Paul I think I love you.

Just yesterday I created a quiz and was wishing I could show scale scores.

I was hoping to be able to add a title to the scale scores. However, I cannot get the line break to work. Any ideas on that? Here's the line I added to review.php (without the break):

$table->data[] = array(get_string('catgrade', 'quiz'), "\n".$attempt->categorygrades);

and here's a screenshot:
Adjunto scalescores.gif
En respuesta a Chardelle Busch

Re: Multiple grade quizzes

de Timothy Takemoto -

the \n will produce a new line in the source html but you need <br /> to have new lines on the page as displayed in the browser. Hence I would try

$table->data[] = array(get_string('catgrade', 'quiz'), "<br />\n".$attempt->categorygrades);

Ah, I see that Paul is doing this using the function nl2br, which inserts <br /> for you
http://php.net/nl2br

perhaps
$table->data[] = array(get_string('catgrade', 'quiz'), nl2br("\n".$attempt->categorygrades));
might work too?

En respuesta a Timothy Takemoto

Re: Multiple grade quizzes

de Chardelle Busch -
Imagen de Core developers
Oh thank you for the explanation Timothy. That was what I needed--so, this way the "\n" was superfluous, and this works great: $table->data[] = array(get_string('catgrade', 'quiz'), nl2br($attempt->categorygrades));
En respuesta a Chardelle Busch

Re: Multiple grade quizzes

de Paul Tero -

Hi Chardelle,

Thank you - that's a nice way to begin Monday morning. And I'm glad you were able to resolve the newline problem.

I thought it better to use new lines in the actual data field, and just convert them to <br/>'s when the data was displayed. In case the data ever needs to be displayed in a non-HTML context too.

En respuesta a Chardelle Busch

Re: Multiple grade quizzes

de Nilesh Pancholi -

Hi, I was looking for such a solution and came across this solution. I tried what Paul has mentioned but found few problems.

1. Paul's code has the function quiz_save_question_session and whereas in attempt.php its save_question_session. If i use paul's function, the quiz module breaks when i try to do a test. I also tried to use paul's code and just replace the function name with the original name, in this case the test works fine but i see nothing inserted in the database. I have added the field as mentioned by paul in the table.

2. I have also put the relevanr code in review.php but cannot see any output as data didnt got inserted in db for that new field.

Since, you got it working, i would appreciate what exactly you did so that i can test and make it working.

Thanks in advacne.

En respuesta a Paul Tero

Re: Multiple grade quizzes

de Tony Ruggiero -
Thank you!

just got this feature request on Friday and stumbled on your code.

Awesome!

Thanks,
Tony
En respuesta a Tony Ruggiero

Re: Multiple grade quizzes

de Chardelle Busch -
Imagen de Core developers

Hi again Paul,

There are a couple of things that need some tweaking and I hope to get it all straightened out since I think this is a great option to have for quizzes.

1. Your category grade % code in attempt.php is not handling a "description" question. If a description is added, I get the Warning: division by zero error message.

2. The code is also not compatible with pagination. Which is really a shame since this feature is nice to have with long quizzes. If I paginate the quiz, then only the scores for the categories appearing on the last page of the quiz get shown.

Any ideas on how to fix?

Thanks,

Chardelle

En respuesta a Chardelle Busch

Re: Multiple grade quizzes

de Paul Tero -

Hi Chardelle,

The first issue should be easy to resolve. The second will take more time, as I'll have to learn how quizzes work better. But I will try and implement both over the holidays.

1) I think the division by zero error comes from when it's computing the percentage. So you can replace 7th line from the bottom with (note that I haven't tested this, but I think it should work):

       if (($category=get_record('quiz_categories', 'id', $categoryid)) && $catmax[$categoryid]>0) { // look up the category name

2) I guess that the quiz results are only computed on a page by page basis. So I'll have to either keep a running total of the results-by-category, or loop over the whole quiz when a single page is submitted.

I'll keep you posted,
Kind regards,
Paul

En respuesta a Paul Tero

Re: Multiple grade quizzes

de frank weissman -

Dear Paul

Great tool

I have implemented. For now it only works if I give a grade to the student. If I select no grade it seems to get lost somewhere. Maybe a problem on my site. All and all I like it.

Frank

En respuesta a frank weissman

Re: Multiple grade quizzes

de Sunita T -
Guys, I am unable to get category wise result. I am on version 1.9 Beta 3.

After "Submit & Save" or "Submit All" it displays blank page. Looking at the error log, it says "Call to undefined function quiz_process_responses()"

I changed it to question_process_responses()

Also error on "Call to undefined function quiz_save_question_session()"

I changed it to "
save_question_session()"

Because both were referrenced in the code prior to this change.

Now it shows results but without grouping by category code. Seems like there is no change in the code. I changed the table as suggested as well as review.php

Kindly guide.

If some one who can do that I am even ready for pay for it.

Regards,
Sunita

En respuesta a Sunita T

Re: Multiple grade quizzes

de Tim Hunt -
Imagen de Core developers Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Peer reviewers Imagen de Plugin developers
Looking at the date, I would guess this thread is about changes to Moodle 1.5. Considering how many changes there have been to the quiz module since then, I would be amazed if it worked, without extensive fixing.
En respuesta a Paul Tero

Re: Multiple grade quizzes

de Sahejin Mansuri -

What is the same process for moodle 2.0?

I can't find it.