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

Update calculations for order of measures

parent 3001cbfd
No related branches found
No related tags found
No related merge requests found
Pipeline #31654 failed
...@@ -158,36 +158,6 @@ public function getFutureRisksDataForEvaluation(Evaluation $evaluation): array ...@@ -158,36 +158,6 @@ public function getFutureRisksDataForEvaluation(Evaluation $evaluation): array
]; ];
} }
public function getBestMeasuresForEvaluation(Evaluation $evaluation): array
{
$measureLevels = collect($evaluation->measureLevels);
// For each danger, add all points of all measures that apply to the danger scenarios
$dangers = Danger::all();
$scenarios = Scenario::all();
$measures = Measure::all();
$bestMeasures = array_map(function($i) {return 0;}, array_flip($measures->pluck('id')->toArray()));
foreach ($scenarios as $scenario) {
// Get current exposition points for this scenarion
$exposition1 = $this->getExpositionPointsForScenario($scenario, $measureLevels);
// Get exposition points for this scenario if all measures are lifted by one point
$exposition2 = $this->getExpositionPointsForScenario($scenario, $measureLevels->map(function (MeasureLevel $l) {
$l->actual_level = min($l->actual_level + 2, 3);
return $l;
}));
// Add points for this measure if there is a difference in exposition
foreach ($scenario->measures as $measure) {
// Fundamental measures count double
$bestMeasures[$measure->id] += (($exposition1 - $exposition2) * ($measure->fundamental ? 2 : 1));
}
}
return collect($bestMeasures)->sortDesc()->keys()->toArray();
}
public function getAttackDataForEvaluation(Evaluation $evaluation): array public function getAttackDataForEvaluation(Evaluation $evaluation): array
{ {
...@@ -227,6 +197,40 @@ public function getMaturityDataForEvaluation(Evaluation $evaluation): array ...@@ -227,6 +197,40 @@ public function getMaturityDataForEvaluation(Evaluation $evaluation): array
]; ];
} }
public function getBestMeasuresForEvaluation(Evaluation $evaluation): array
{
$measureLevels = collect($evaluation->measureLevels);
// For each danger, add all points of all measures that apply to the danger scenarios
$scenarios = Scenario::all();
$measures = Measure::all();
$bestMeasures = array_map(function($i) {return 0;}, array_flip($measures->pluck('id')->toArray()));
foreach ($evaluation->dangerLevels as $dangerLevel) {
/**
* @var DangerLevelEvaluation $dangerLevel
*/
foreach ($dangerLevel->danger->scenarios as $scenario) {
// Add points for this measure if there is a difference in exposition
foreach ($scenario->measures as $measure) {
$selectedLevel = $measureLevels->first(function (MeasureLevel $level) use ($measure) {
return $measure->id === $level->measure_id;
});
// Fundamental measures count double
if ($selectedLevel) {
$l1 = $measure->{'level' . $selectedLevel->actual_level . '_value'};
$l2 = $measure->{'level' . (min($selectedLevel->actual_level + 1, 3)) . '_value'};
$bestMeasures[$measure->id] += ($l2 - $l1) * $dangerLevel->level->value;
}
}
}
}
return collect($bestMeasures)->sortDesc()->keys()->toArray();
}
private function getExpositionPointsForScenario(Scenario $scenario, $measureLevels): float private function getExpositionPointsForScenario(Scenario $scenario, $measureLevels): float
{ {
// Get prorated count of measures // Get prorated count of measures
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
<div v-if="measureInformations"> <div v-if="measureInformations">
<div class="card" :style="cssProps" role="radio"> <div class="card" :style="cssProps" role="radio">
<div class="card-header h5 font-weight-bold text-center"> <div class="card-header h5 font-weight-bold text-center">
{{ measure.short_name }} {{ measure.short_name }}<br>
<small v-if="index < 4">
(Préconisé)
</small>
</div> </div>
<div class="card-body"> <div class="card-body">
<!-- Affiche un bouton radio et le détail du niveau --> <!-- Affiche un bouton radio et le détail du niveau -->
......
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