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

Show territory graph data even if structure has a single evaluation. Fixes...

Show territory graph data even if structure has a single evaluation. Fixes #28
parent c3f30e33
No related branches found
No related tags found
No related merge requests found
Pipeline #60648 failed
......@@ -90,7 +90,7 @@ public function evaluations(): HasMany
public function doneEvaluations(): HasMany
{
return $this->evaluations()->where('status', Evaluation::STATUS_DONE);
return $this->evaluations()->where('status', Evaluation::STATUS_DONE)->orderBy('updated_at', 'desc');
}
public function address(): BelongsTo
......
......@@ -370,7 +370,7 @@ public function getActionTerritoryGraphData(): array
return $org->active;
})->reduce(function ($acc, Organization $org) {
$doneEvaluations = $org->doneEvaluations;
if ($doneEvaluations->count() >= 2) {
if ($doneEvaluations->count() >= 1) {
/**
* @var Evaluation $currentEval
*/
......@@ -389,6 +389,7 @@ public function getActionTerritoryGraphData(): array
return $org->active;
})->reduce(function ($acc, Organization $org) {
$doneEvaluations = $org->doneEvaluations;
if ($doneEvaluations->count() >= 2) {
/**
* @var Evaluation $currentEval
......@@ -401,12 +402,13 @@ public function getActionTerritoryGraphData(): array
// Get the number of planned actions in the previous evaluation
// that have reached the expected_level in the current evaluation
return $acc + $currentEval->measureLevels->filter(function (MeasureLevel $ml) use ($previousEval) {
$prevML = $previousEval->measureLevels->first(function (MeasureLevel $pml) use ($ml) {
return $ml->measure_id === $pml->measure_id;
});
return $prevML && $ml->actual_level >= $prevML->expected_level;
return $prevML && 0 !== $prevML->expected_level && null !== $prevML->expected_level && $ml->actual_level >= $prevML->expected_level;
})->count();
}
......@@ -416,7 +418,7 @@ public function getActionTerritoryGraphData(): array
return [
'labels' => $labels,
'data' => [$plannedMeasures, $doneMeasures],
'data' => [$doneMeasures, $plannedMeasures],
];
}
......
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