OK, I think I have worked out what we would need to do to compute the score afresh each time, instead of adjusting it incrementally. However, I would, of course, like to be really sure I have got the right formula! Therefore it would be helpful if people with direct access to their
database could run the following query:
SELECT qa.id AS quizattempt, sess.attemptid, SUM(state.grade) AS computedgrade, qa.sumgrades AS storedgrade
FROM mdl_question_sessions sess
JOIN mdl_question_states state ON state.id = sess.newgraded
JOIN mdl_quiz_attempts qa ON qa.uniqueid = sess.attemptid
GROUP BY attemptid, qa.sumgrades
HAVING SUM(state.grade) <> qa.sumgrades
What this does is to compare the stored grade for each quiz with the result of applying what I think is the correct formula. So:
1. If you have never had problems with Moodle computing the score for attempts, no records should be returned. (Or only records where the two scores differ because of rounding errors.)
2. If you have a site where problems like the one discussed in this thread have occurred, this query should list just the problem attempts. You can double check that by going to .../mod/quiz/review.php?attempt=[quizattempt]
The more people who can confirm that the formula is right, the better. Thanks.