Skip to content

Commit 6ae5874

Browse files
Merge branch 'improvement/dashboardCharts'
2 parents e96a3e5 + 3147c78 commit 6ae5874

File tree

3 files changed

+193
-30
lines changed

3 files changed

+193
-30
lines changed

src/Service/AnrCartoRiskService.php

+182-20
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public function getCartoReal($anrId)
4444
$this->buildListScalesAndHeaders($anrId);
4545
$this->buildListScalesOpRisk($anrId);
4646

47-
list($counters, $distrib) = $this->getCountersRisks('raw');
48-
list($countersRiskOP, $distribRiskOp) = $this->getCountersOpRisks('raw');
47+
list($counters, $distrib, $riskMaxSum, $byTreatment) = $this->getCountersRisks('raw');
48+
list($countersRiskOP, $distribRiskOp, $riskOpMaxSum, $byTreatmentRiskOp) = $this->getCountersOpRisks('raw');
4949

5050
return [
5151
'Impact' => $this->listScales[Scale::TYPE_IMPACT],
@@ -56,10 +56,14 @@ public function getCartoReal($anrId)
5656
'riskInfo' => [
5757
'counters' => $counters,
5858
'distrib' => $distrib,
59+
'riskMaxSum' => $riskMaxSum,
60+
'byTreatment' => $byTreatment,
5961
],
6062
'riskOp' => [
6163
'counters' => $countersRiskOP,
6264
'distrib' => $distribRiskOp,
65+
'riskOpMaxSum' => $riskOpMaxSum,
66+
'byTreatment' => $byTreatmentRiskOp,
6367
],
6468
];
6569
}
@@ -74,8 +78,8 @@ public function getCartoTargeted($anrId)
7478
$this->buildListScalesAndHeaders($anrId);
7579
$this->buildListScalesOpRisk($anrId);
7680

77-
list($counters, $distrib) = $this->getCountersRisks('target');
78-
list($countersRiskOP, $distribRiskOp) = $this->getCountersOpRisks('target');
81+
list($counters, $distrib, $riskMaxSum, $byTreatment) = $this->getCountersRisks('target');
82+
list($countersRiskOP, $distribRiskOp, $riskOpMaxSum, $byTreatmentRiskOp) = $this->getCountersOpRisks('target');
7983

8084
return [
8185
'Impact' => $this->listScales[Scale::TYPE_IMPACT],
@@ -86,10 +90,14 @@ public function getCartoTargeted($anrId)
8690
'riskInfo' => [
8791
'counters' => $counters,
8892
'distrib' => $distrib,
93+
'riskMaxSum' => $riskMaxSum,
94+
'byTreatment' => $byTreatment,
8995
],
9096
'riskOp' => [
9197
'counters' => $countersRiskOP,
9298
'distrib' => $distribRiskOp,
99+
'riskOpMaxSum' => $riskOpMaxSum,
100+
'byTreatment' => $byTreatmentRiskOp,
93101
],
94102
];
95103
}
@@ -187,7 +195,10 @@ public function getCountersRisks($mode = 'raw')
187195
$changeField = $mode == 'raw' ? 'ir.cacheMaxRisk' : 'ir.cacheTargetedRisk';
188196
$query = $this->get('instanceRiskTable')->getRepository()->createQueryBuilder('ir');
189197
$result = $query->select([
190-
'ir.id as myid', 'IDENTITY(ir.amv) as amv', 'IDENTITY(ir.asset) as asset', 'IDENTITY(ir.threat) as threat', 'IDENTITY(ir.vulnerability) as vulnerability', $changeField . ' as maximus',
198+
'ir.id as myid',
199+
'ir.kindOfMeasure as treatment',
200+
'IDENTITY(ir.amv) as amv', 'IDENTITY(ir.asset) as asset', 'IDENTITY(ir.threat) as threat', 'IDENTITY(ir.vulnerability) as vulnerability',
201+
$changeField . ' as maximus',
191202
'i.c as ic', 'i.i as ii', 'i.d as id', 'IDENTITY(i.object) as object',
192203
'm.c as mc', 'm.i as mi', 'm.a as ma',
193204
'o.scope',
@@ -198,7 +209,23 @@ public function getCountersRisks($mode = 'raw')
198209
->innerJoin('ir.threat', 'm')
199210
->innerJoin('i.object', 'o')->getQuery()->getResult();
200211

201-
$counters = $distrib = $temp = [];
212+
$counters = $distrib = $riskMaxSum = $temp = [];
213+
$byTreatment = [
214+
'treated' => [],
215+
'not_treated' => [],
216+
'reduction' => [],
217+
'denied' => [],
218+
'accepted' => [],
219+
'shared' => [],
220+
'all' => [
221+
'reduction' => [],
222+
'denied' => [],
223+
'accepted' => [],
224+
'shared' => [],
225+
'not_treated' => [],
226+
]
227+
];
228+
202229
foreach ($result as $r) {
203230
if (!isset($r['threat']) || !isset($r['vulnerability'])) {
204231
continue;
@@ -227,7 +254,7 @@ public function getCountersRisks($mode = 'raw')
227254
'amv' => $r['asset'] . ';' . $r['threat'] . ';' . $r['vulnerability'],
228255
'max' => $max,
229256
'color' => $this->getColor($max,'riskInfo'),
230-
'uuid' => $r['amv']
257+
'treatment' => $r['treatment']
231258
];
232259

233260
// on est obligé de faire l'algo en deux passes pour pouvoir compter les objets globaux qu'une seule fois
@@ -261,19 +288,79 @@ public function getCountersRisks($mode = 'raw')
261288
}
262289

263290
if (!isset($counters[$context['impact']][$context['right']])) {
264-
$counters[$context['impact']][$context['right']] = [];
291+
$counters[$context['impact']][$context['right']] = 0;
265292
}
266293

267294
if (!isset($distrib[$context['color']])) {
268-
$distrib[$context['color']] = [];
295+
$distrib[$context['color']] = 0;
296+
}
297+
298+
if (!isset($riskMaxSum[$context['color']])) {
299+
$riskMaxSum[$context['color']] = 0;
300+
}
301+
302+
$counters[$context['impact']][$context['right']] += 1;
303+
$distrib[$context['color']] += 1;
304+
$riskMaxSum[$context['color']] += $context['max'];
305+
306+
if ($context['treatment'] !== 5) {
307+
if (!isset($byTreatment['treated'][$context['color']]['count'])) {
308+
$byTreatment['treated'][$context['color']]['count'] = 0;
309+
}
310+
311+
if (!isset($byTreatment['treated'][$context['color']]['sum'])) {
312+
$byTreatment['treated'][$context['color']]['sum'] = 0;
313+
}
314+
315+
$byTreatment['treated'][$context['color']]['count'] += 1;
316+
$byTreatment['treated'][$context['color']]['sum'] += $context['max'];
317+
}
318+
319+
switch($context['treatment']) {
320+
case 1:
321+
$kindOfTreatment = 'reduction';
322+
break;
323+
case 2:
324+
$kindOfTreatment = 'denied';
325+
break;
326+
case 3:
327+
$kindOfTreatment = 'accepted';
328+
break;
329+
case 4:
330+
$kindOfTreatment = 'shared';
331+
break;
332+
case 5:
333+
$kindOfTreatment = 'not_treated';
334+
break;
335+
}
336+
337+
338+
if (!isset($byTreatment['all'][$kindOfTreatment]['count'])) {
339+
$byTreatment['all'][$kindOfTreatment]['count'] = 0;
340+
}
341+
342+
if (!isset($byTreatment['all'][$kindOfTreatment]['sum'])) {
343+
$byTreatment['all'][$kindOfTreatment]['sum'] = 0;
269344
}
270-
array_push($counters[$context['impact']][$context['right']],$context['uuid']);
271-
array_push($distrib[$context['color']],$context['uuid']);
345+
346+
if (!isset($byTreatment[$kindOfTreatment][$context['color']]['count'])) {
347+
$byTreatment[$kindOfTreatment][$context['color']]['count'] = 0;
348+
}
349+
350+
if (!isset($byTreatment[$kindOfTreatment][$context['color']]['sum'])) {
351+
$byTreatment[$kindOfTreatment][$context['color']]['sum'] = 0;
352+
}
353+
354+
$byTreatment[$kindOfTreatment][$context['color']]['count'] += 1;
355+
$byTreatment[$kindOfTreatment][$context['color']]['sum'] += $context['max'];
356+
357+
$byTreatment['all'][$kindOfTreatment]['count'] += 1;
358+
$byTreatment['all'][$kindOfTreatment]['sum'] += $context['max'];
272359
}
273360
}
274361
}
275362

276-
return [$counters, $distrib];
363+
return [$counters, $distrib, $riskMaxSum, $byTreatment];
277364
}
278365

279366
/**
@@ -287,14 +374,31 @@ public function getCountersOpRisks($mode = 'raw')
287374
$query = $this->get('instanceRiskOpTable')->getRepository()->createQueryBuilder('iro');
288375
$result = $query->select([
289376
'iro as instanceRiskOp', 'iro.cacheNetRisk as netRisk', 'iro.cacheTargetedRisk as targetedRisk',
377+
'iro.kindOfMeasure as treatment',
290378
implode(',', $valuesField)
291379
])->where('iro.anr = :anrid')
292380
->setParameter(':anrid', $this->anr->get('id'))
293381
->andWhere("iro.cacheNetRisk != -1")
294382
->getQuery()->getResult();
295383

296384

297-
$countersRiskOP = $distribRiskOp = $temp = [];
385+
$countersRiskOP = $distribRiskOp = $riskOpMaxSum = $temp = [];
386+
$byTreatment = [
387+
'treated' => [],
388+
'not_treated' => [],
389+
'reduction' => [],
390+
'denied' => [],
391+
'accepted' => [],
392+
'shared' => [],
393+
'all' => [
394+
'reduction' => [],
395+
'denied' => [],
396+
'accepted' => [],
397+
'shared' => [],
398+
'not_treated' => [],
399+
]
400+
];
401+
298402
foreach ($result as $r) {
299403
foreach ($r['instanceRiskOp']->getOperationalInstanceRiskScales() as $operationalInstanceRiskScale) {
300404
$operationalRiskScaleType = $operationalInstanceRiskScale->getOperationalRiskScaleType();
@@ -318,22 +422,80 @@ public function getCountersOpRisks($mode = 'raw')
318422
$max = $r['targetedRisk'];
319423
$prob = $r['targetedProb'];
320424
}
321-
322-
$id = $r['id'];
425+
$treatment = $r['treatment'];
323426
$color = $this->getColor($max, 'riskOp');
324427

325428
if (!isset($countersRiskOP[$imax][$prob])) {
326-
$countersRiskOP[$imax][$prob] = [];
429+
$countersRiskOP[$imax][$prob] = 0;
327430
}
328431

329432
if (!isset($distribRiskOp[$color])) {
330-
$distribRiskOp[$color] = [];
433+
$distribRiskOp[$color] = 0;
434+
}
435+
436+
if (!isset($riskOpMaxSum[$color])) {
437+
$riskOpMaxSum[$color] = 0;
438+
}
439+
440+
$countersRiskOP[$imax][$prob] += 1;
441+
$distribRiskOp[$color] += 1;
442+
$riskOpMaxSum[$color] += $max;
443+
444+
if ($treatment !== 5) {
445+
if (!isset($byTreatment['treated'][$color]['count'])) {
446+
$byTreatment['treated'][$color]['count'] = 0;
447+
}
448+
449+
if (!isset($byTreatment['treated'][$color]['sum'])) {
450+
$byTreatment['treated'][$color]['sum'] = 0;
451+
}
452+
453+
$byTreatment['treated'][$color]['count'] += 1;
454+
$byTreatment['treated'][$color]['sum'] += $max;
331455
}
332-
array_push($countersRiskOP[$imax][$prob],$r['id']);
333-
array_push($distribRiskOp[$color],$r['id']);
456+
457+
switch($treatment) {
458+
case 1:
459+
$kindOfTreatment = 'reduction';
460+
break;
461+
case 2:
462+
$kindOfTreatment = 'denied';
463+
break;
464+
case 3:
465+
$kindOfTreatment = 'accepted';
466+
break;
467+
case 4:
468+
$kindOfTreatment = 'shared';
469+
break;
470+
case 5:
471+
$kindOfTreatment = 'not_treated';
472+
break;
473+
}
474+
475+
if (!isset($byTreatment['all'][$kindOfTreatment]['count'])) {
476+
$byTreatment['all'][$kindOfTreatment]['count'] = 0;
477+
}
478+
479+
if (!isset($byTreatment['all'][$kindOfTreatment]['sum'])) {
480+
$byTreatment['all'][$kindOfTreatment]['sum'] = 0;
481+
}
482+
483+
if (!isset($byTreatment[$kindOfTreatment][$color]['count'])) {
484+
$byTreatment[$kindOfTreatment][$color]['count'] = 0;
485+
}
486+
487+
if (!isset($byTreatment[$kindOfTreatment][$color]['sum'])) {
488+
$byTreatment[$kindOfTreatment][$color]['sum'] = 0;
489+
}
490+
491+
$byTreatment[$kindOfTreatment][$color]['count'] += 1;
492+
$byTreatment[$kindOfTreatment][$color]['sum'] += $max;
493+
494+
$byTreatment['all'][$kindOfTreatment]['count'] += 1;
495+
$byTreatment['all'][$kindOfTreatment]['sum'] += $max;
334496
}
335497

336-
return [$countersRiskOP, $distribRiskOp];
498+
return [$countersRiskOP, $distribRiskOp, $riskOpMaxSum, $byTreatment];
337499

338500
}
339501

src/Service/DeliverableGenerationService.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ protected function generateCartographyMap($data, $section, $params)
14291429
foreach ($axisX as $x) {
14301430
$value = $x * $y;
14311431
if (isset($data[$y]) && isset($data[$y][$x])) {
1432-
$result = count($data[$y][$x]);
1432+
$result = $data[$y][$x];
14331433
} else {
14341434
$result = null;
14351435
}
@@ -1568,9 +1568,9 @@ protected function generateRisksGraph($infoRisk = true)
15681568
];
15691569

15701570
$series = [
1571-
count($distrib[0] ?? []),
1572-
count($distrib[1] ?? []),
1573-
count($distrib[2] ?? []),
1571+
$distrib[0] ?? 0,
1572+
$distrib[1] ?? 0,
1573+
$distrib[2] ?? 0,
15741574
];
15751575

15761576
$PhpWord = new PhpWord();
@@ -2417,9 +2417,9 @@ protected function getRisksDistribution($infoRisk = true)
24172417

24182418
foreach ($colors as $c) {
24192419
if (!isset($distrib[$c])) {
2420-
$distrib[$c] = [];
2420+
$distrib[$c] = 0;
24212421
}
2422-
$sum += count($distrib[$c]);
2422+
$sum += $distrib[$c];
24232423
}
24242424

24252425
$intro = sprintf(
@@ -2431,17 +2431,17 @@ protected function getRisksDistribution($infoRisk = true)
24312431

24322432
return $intro .
24332433
"<!--block-->&nbsp;&nbsp;- " .
2434-
count($distrib[2]) .
2434+
$distrib[2] .
24352435
' ' .
24362436
$this->anrTranslate('critical risk(s) to be treated as priority') .
24372437
"<!--block-->" .
24382438
"<!--block-->&nbsp;&nbsp;- " .
2439-
count($distrib[1]) .
2439+
$distrib[1] .
24402440
' ' .
24412441
$this->anrTranslate('medium risk(s) to be partially treated') .
24422442
"<!--block-->" .
24432443
"<!--block-->&nbsp;&nbsp;- " .
2444-
count($distrib[0]) .
2444+
$distrib[0] .
24452445
' ' .
24462446
$this->anrTranslate('low risk(s) negligible') . "<!--block-->";
24472447
}
@@ -5614,7 +5614,7 @@ protected function generateAssetContextTable()
56145614
$translationLabel = $translations[$metadata->getLabelTranslationKey()] ?? null;
56155615
$headersMetadata[] = $translationLabel !== null ? $translationLabel->getValue() : '';
56165616
}
5617-
if (!$headersMetadata) {
5617+
if (!isset($headersMetadata)) {
56185618
return;
56195619
}
56205620
$sizeColumn = 13 / count($headersMetadata);

view/layout/layout.phtml

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
->appendFile('js/anr/VerticalBarChartService.js')
103103
->appendFile('js/anr/MultiHorizontalBarChartService.js')
104104
->appendFile('js/anr/HorizontalBarChartService.js')
105+
->appendFile('js/anr/MiniHorizontalBarChartsService.js')
105106
->appendFile('js/anr/LineChartService.js')
106107
->appendFile('js/anr/MultiLineChartService.js')
107108
->appendFile('js/anr/RadarChartService.js')

0 commit comments

Comments
 (0)