Problem/Motivation

function opigno_learning_path_get_score($gid, $uid, $current_attempt = FALSE, $latest_cert_date = NULL) {
  $steps = !$current_attempt ? opigno_learning_path_get_steps($gid, $uid, NULL, $latest_cert_date) :
    opigno_learning_path_get_steps_current_attempt($gid, $uid);
  $mandatory_steps = array_filter($steps, function ($step) {
    return $step['mandatory'];
  });
  if (!empty($mandatory_steps)) {
    $score = round(array_sum(array_map(function ($step) {
      return $step['best score'];
    }, $mandatory_steps)) / count($mandatory_steps));
  }
  else {
    $score = 0;
  }

  return $score;
}

The / count ($mandatory_steps) always results in dividing the score by the number of mandatory steps. It seems like it should be dividing the score by the total possible score - i.e. the sum of maximum score available for all mandatory steps.

The maximum available score isn't available in the steps array at the moment so not just a case of swapping this out - we'd need to make the data available first.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 3202889.patch622 bytescatch

Comments

catch created an issue. See original summary.

catch’s picture

Title: opigno_learning_path_get_score() always divides total score by the number of mandatory steps » Improve documentation for opigno_learning_path_get_score()
Category: Bug report » Task
Priority: Major » Minor
Status: Active » Needs review
StatusFileSize
new622 bytes

OK the logic is fine, just the code is slightly confusing.

What it's doing is getting the percentage (not absolute) score for each step, which means we have a sum of percentages. Then dividing that sum of percentages by the number of steps gives you the mean percentage overall.

Here's a patch to add some inline docs.

catch’s picture

The other issue here is that if you have a learning path with no manual steps, even if a score is recorded for activities, it shows as 0 - so an informational score isn't available.

catch’s picture

Title: Improve documentation for opigno_learning_path_get_score() » opigno_learning_path_get_score() doesn't return a score for optional modules
Category: Task » Bug report
Priority: Minor » Normal

Moving back to a bug - I think there ought to be an API function for getting scores including optional modules, even if it's not this one.