Skip to content
Snippets Groups Projects
Commit 46b91c91 authored by Jonathan Foucher's avatar Jonathan Foucher
Browse files

Fix bugs in calculator

parent 5654e4cd
No related branches found
No related tags found
No related merge requests found
......@@ -7,13 +7,15 @@
class MaturityAnswerLevelCalculator
{
public function calculateFundamentalLevel(Evaluation $evaluation): float|int|null
public function calculateFundamentalLevel(Evaluation $evaluation): int
{
return $evaluation->measureLevels->filter(function (MeasureLevel $ml) {
$level = $evaluation->measureLevels->filter(function (MeasureLevel $ml) {
return true === $ml->measure->fundamental;
})->average(function (MeasureLevel $ml) {
return $ml->actual_level;
});
return (int)floor($level);
}
public function calculateExecutionLevel(Evaluation $evaluation): int
......@@ -23,7 +25,7 @@ public function calculateExecutionLevel(Evaluation $evaluation): int
* @var Evaluation|null $previousEvaluation
*/
$previousEvaluation = Evaluation::where('status', Evaluation::STATUS_DONE)
->where('updated_at', '<', $evaluation->updatedAt)
->whereDate('updated_at', '<', $evaluation->updated_at->toDateString())
->orderBy('updated_at', 'DESC')
->first();
if ($previousEvaluation) {
......@@ -42,7 +44,11 @@ public function calculateExecutionLevel(Evaluation $evaluation): int
});
// Calculate score
$score = $expectedLevelMeasures->count() / $attainedLevelMeasures->count();
$atc = $attainedLevelMeasures->count();
if ($atc === 0) {
return 0;
}
$score = $expectedLevelMeasures->count() / $atc;
// Return level from score
if ($score > 80) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment