getAttemptScore() calculates scores incorrectly

Created on 25 April 2025, 11 days ago

Problem/Motivation

The UserModuleStatus entity stores the score value as a percent, rather than in points. Here is from a recently launched 3.2.8 site:

When ::getAttemptScore() is called, it produces erroneous results:

  public function getAttemptScore() {
    $score = (int) $this->getScore();  // This is in 0-100 integer percent
    $max_score = (int) $this->calculateMaxScore(); // This is in points

    if ($max_score <= 0) {
      return 0;
    }

    // Clamp score.
    $score = max(0, $score); // Okay, make sure it's >= 0.
    $score = min($max_score, $score); // But if the max score is <100, the max score always wins

    // Convert absolute values to percent.
    return round(100 * $score / $max_score);
  }

Steps to reproduce

  1. Create a new training.
  2. Create a new mandatory module with max score of 10.
  3. Add a single file upload activity to the module. Make it manually scored, max of 10 points.
  4. Save the training
  5. Complete the training as a student
  6. Score the activity as 8
  7. View the training details for the student, score in the sidebar reads as 10/10

Proposed resolution

Either:

  • The Score field for UserModuleStatus needs to store points, rather than percent
  • The Score column for UserModuleStatus should be renamed to score_percent, and resulting logic needs to be changed to account for it returning an integer percent of the max of the score.

Remaining tasks

Create patch.

User interface changes

Likely none.

API changes

None.

Data model changes

None, although the column may need to be renamed for clarity.

πŸ› Bug report
Status

Active

Version

3.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States socketwench

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @socketwench
  • πŸ‡ΊπŸ‡ΈUnited States socketwench

    Further examination of the module and other Opigno modules suggests that the correct output for this method is an integer percent. This patch then corrects the clamping on the outputted value so as to always be between 0 and 100.

Production build 0.71.5 2024