Quiz total calculating wrong value

Quiz total calculating wrong value

by Susan Mangan -
Number of replies: 5

Version 2.6.10 (Build: 20150310)

We are at the end of term with online quizzes and grading and some quiz totals are just not adding up correctly. 

EG, 30 questions which should have a 33 point total but total of marks shows 34

Found this: https://tracker.moodle.org/browse/MDL-32791

Tried this: "On the edit quiz page, try changing the Mark for one question from 1 to 2 (and save changes) then change it back from 2 to 1 again. See if that sorts it out."

Did not work.

Ran query:  SELECT * FROM mdl_quiz_question_instances WHERE quiz = xxxx;

Found one more question in query that is not displayed in the actual quiz.  Tried making value of this question worth zero in database but this did not change the total of marks on the quiz page.

I'm reluctant to make direct database changes without consultation.  Can someone give me some advise for a fix here so we can get through our end of term exams?

Also, anything that can be changed in the code so we can make sure quiz totals are accurate for our next term? assuming this is not an issue in 2.7 2.8 branches so will not be an issue in the Fall (hopefully)

Thanks in advance!!!!!

 

Average of ratings: -
In reply to Susan Mangan

Re: Quiz total calculating wrong value

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There are other tracker issues too. E.g. MDL-38282, but that was fixed before 2.6, so you should be OK.

When you upgrade to 2.7 or 2.8, that should fix the problem due to the changes that were made, but that does not help you now.

You did the right thing by finding the extra row in the database, and setting its max mark to 0. (It would probably also be safe to delete that row.) However, after doing that, you need to repeat the "On the edit quiz page, try changing the Mark for one question from 1 to 2 (and save changes) then change it back from 2 to 1 again. See if that sorts it out." process, to make Moodle notices the change and re-computes the Total of marks.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Quiz total calculating wrong value

by Susan Mangan -

Brilliant.  Thank you so much for replying Tim - that did indeed work.

We will be running 2.6.10 for one more term unfortunately - I don't suppose there is something we can apply right now to make sure this doesn't happen again?

Or is there a query I can run to catch cases where this has occurred so I can apply the manual DB fix?

In reply to Susan Mangan

Re: Quiz total calculating wrong value

by Susan Mangan -

I am concerned about other quizzes that might be showing incorrect values and there are just too many to look at manually.  I'm thinking there should be a query I can run to get some sort of discrepancy report for this.  I'll start investigating this but if you know offhand what tables and fields I should be using that would be helpful.  Thanks again.

In reply to Susan Mangan

Re: Quiz total calculating wrong value

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It is difficult to get a patch to fix this in 2.6. The upgrade code that fixes things as you go from 2.6 to 2.7 is https://github.com/moodle/moodle/blob/d5d23acdf546ab33a052ad06869d8d65f038b666/mod/quiz/db/upgrade.php#L559, but that comes after other changes, so would not work in 2.6.

The problem in 2.6 is that there were two different sources of related information. The quiz_question_instances table, and the column questions in the quiz table. It is tricky to verify they are consistent, because the questions column is a comma-separated list of IDs. However, you can do it:

SELECT *
FROM mdl_quiz_question_instances qqi
JOIN mdl_quiz quiz ON quiz.id = qqi.quiz
WHERE CONCAT(',', quiz.questions, ',') NOT LIKE
        CONCAT('%,', qqi.question, ',%')

That will work in MySQL. (Well, something like that will work. I may have made a silly error as I wrote that out, but if so you should be able to sort it out.

If you use postgres, you need to change CONCAT(',', quiz.questions, ',') to ',' || quiz.questions || ',' (both calls to concat).

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Quiz total calculating wrong value

by Susan Mangan -

Thank you so much for taking the time to provide this to me.  This will help me to monitor any potential issues during our next term at which point we will be upgrading to 2.8.

Thanks Tim!