You are here

private function LpSteps::courseGetScore in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/LpSteps.php \Drupal\opigno_learning_path\LpSteps::courseGetScore()

Calculate course score.

1 call to LpSteps::courseGetScore()
LpSteps::getCourseStep in src/LpSteps.php
Builds up a training course step.

File

src/LpSteps.php, line 219

Class

LpSteps

Namespace

Drupal\opigno_learning_path

Code

private function courseGetScore(array $course_steps) : float {
  $step_count = count($course_steps);

  // If a course contains a mandatory module that has a total max score of 0
  // (because all activities inside have max score 0) then we should
  // consider that score is 100%.
  $set_full = TRUE;
  foreach ($course_steps as $step) {
    if ($step['best score'] != 100 || $step['mandatory'] != 1) {
      $set_full = FALSE;
    }
  }
  if ($set_full) {
    return 100;
  }
  return round(array_sum(array_map(function ($step) {
    return $step['current attempt score'];
  }, $course_steps)) / $step_count);
}