Feature #8307

Add feature to recalculate score in exercises

Added by Yannick Warnier almost 3 years ago. Updated almost 3 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:
SCRUM pts - complexity:


If a question had one error and the teacher sees it and wants to fix it, there should be a button to "recalculate" the score of the student based on his (unchanged) answers and the (changed) question.

The button to recalculate should appear on this page: main/exercice/exercise_report.php: one icon in the action bar, to recalculate all scores, and one icon next to each student separately.

The icon main/img/icons/22/reload.png can be used for that.

The feature should just reprocess the results. Look for "exe_result" of the track_e_exercises table. Possibly calls to exercise.class.php::save_stat_track_exercise_info() but maybe it's not the only place where it is modified.

Associated revisions

Revision 238763ae (diff)
Added by Angel Fernando Quiroz Campos almost 3 years ago

Allow recalculate the students score - refs #8307



Updated by Yannick Warnier almost 3 years ago

An example from a filled database, where exe_result varies from one user to another:

MariaDB [chamilocourses]> select exe_user_id, exe_exo_id, exe_date, status, exe_duration, exe_weighting, exe_result from track_e_exercises;

|         587 |         33 | 2016-06-24 03:30:44 |            |         1779 |            50 |                 36 |
|         634 |         33 | 2016-06-27 21:24:46 |            |         1173 |            50 |               44.5 |
|         635 |         33 | 2016-06-27 21:20:54 |            |          965 |            50 |                 40 |
|         636 |         33 | 2016-06-27 21:22:31 |            |         1039 |            50 |                 48 |
235 rows in set (0.00 sec)


Updated by Yannick Warnier almost 3 years ago

  • Assignee changed from Angel Quiroz to Yannick Warnier

Updated by Yannick Warnier almost 3 years ago

  • Assignee changed from Yannick Warnier to Angel Quiroz
  • % Done changed from 0 to 10

This code from exercise_report.php recalculates the total score, but does not recalculate each answer's score (line 209):

    $qry = 'SELECT DISTINCT question_id, marks
            FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id.'
            GROUP BY question_id';
    $res = Database::query($qry);
    $tot = 0;
    while ($row = Database :: fetch_array($res, 'ASSOC')) {
        $tot += $row['marks'];

            SET exe_result = '".floatval($tot)."'
            WHERE exe_id = ".$id;


Just before that, there is code to update answers on the basis of a POST element. The ID here is to recalculate all answers score on the basis of the answers that are already in the database, considering that the questions score and correct answers might have been changed.

There's interesting code in main/inc/ajax/exercise.ajax.php::save_exercise_by_now but it also saves the session duration, and that it not an option in our case, so it would probably be a good idea to just copy this code in a new function and clean it up.

I've added the basic changes at the places where this code needs to be inserted here:


Updated by Yannick Warnier almost 3 years ago

The function should be called ExerciseLib::recalculateAttemptScore($attemptId) {} and only recalculate the total score, but also make sure an event is stored for that (who did it, when, what the old score was) through the Events library (like update_event_exercice()).


Updated by Angel Quiroz almost 3 years ago

  • Status changed from Assigned to Needs testing
  • Assignee deleted (Angel Quiroz)
  • % Done changed from 10 to 50

For now, the main/exercise/recalculate.php script works with the question types Multiple choice, Multiple answers, Exact selection, Unique answer with unknown, Multiple answer true/false/unknown, Combination true/false/don't-know and Global multiple answer

There are bugs with the other question types, because these questions need to be "processed"


Updated by Yannick Warnier almost 3 years ago

  • Status changed from Needs testing to New
  • Target version changed from 1.11.0 to 2.0

This is good enough for me (for 1.11.x). I'm transferring this task to 2.0, to be completed then (I'm sure we'll find a way to do it).
Good job!

Also available in: Atom PDF