Example #1
0
 public function getEvaluation($evaluation, $course = "*")
 {
     $reviewed = $this->student->context->find($evaluation);
     $total = $reviewed->count();
     $average = 1 / ($total ?: 1);
     $accumulator = 0;
     $collect = Criterion::collect(function ($criterion, $index) use($evaluation, $total, $reviewed, $average, &$accumulator) {
         $map = [$evaluation => Data::FACTORY($evaluation, $reviewed->pick($index))->loadCriterion($criterion), 'schedule' => $this->student->section->schedule[$criterion['@assigned'] ?: $index], 'due' => $this->student->section->schedule[$criterion['@due'] ?: $index]];
         $score = $map[$evaluation]->score;
         if (($evaluation === 'quiz' || $evaluation === 'project') && $total > $criterion['@index']) {
             $stats = $this->collective($this->student->section, $criterion);
             if ($score > 0 && $stats['sd'] > 0) {
                 $z = ($score - $stats['mean']) / $stats['sd'];
                 $score = round($stats['wmean'] + $z * $stats['sd'], 2);
             }
             $stats['standard'] = $score * 100;
             $map['stats'] = $stats;
         }
         $accumulator = $accumulator + $score * $average;
         return $map;
     }, "[@type='{$evaluation}' and @course = '{$course}']");
     $weight = Assessment::$weight[$evaluation];
     return new \bloc\types\dictionary(['list' => iterator_to_array($collect, false), 'score' => $average === 1 && $total == 0 ? $weight : max(0, round($accumulator * $weight, 1)), 'weight' => $weight]);
 }