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
Comments
Comment #2
catchOK 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.
Comment #3
catchThe 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.
Comment #4
catchMoving 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.