From 95d6365c492a590156652e177abcec892d42bd92 Mon Sep 17 00:00:00 2001 From: "mael.joumier" Date: Tue, 20 Feb 2024 09:21:32 +0100 Subject: [PATCH 1/5] Fix Donut Chart --- backend/core/helpers.py | 16 ++++++++-------- backend/core/views.py | 2 +- .../src/lib/components/Chart/DonutChart.svelte | 4 +++- frontend/src/routes/(app)/analytics/+page.svelte | 2 ++ .../routes/(app)/analytics/composer/+page.svelte | 2 ++ .../[id=uuid]/+page.svelte | 1 + 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/backend/core/helpers.py b/backend/core/helpers.py index fe2b09699..c38f9aba8 100644 --- a/backend/core/helpers.py +++ b/backend/core/helpers.py @@ -516,16 +516,16 @@ def aggregate_risks_per_field( count = ( RiskScenario.objects.filter(id__in=object_ids_view) .filter(residual_level=i) - .filter(risk_assessment__risk_matrix__name=["name"]) + # .filter(risk_assessment__risk_matrix__name=["name"]) .count() - ) + ) # What the second filter does ? Is this usefull ? else: count = ( RiskScenario.objects.filter(id__in=object_ids_view) .filter(current_level=i) - .filter(risk_assessment__risk_matrix__name=["name"]) + # .filter(risk_assessment__risk_matrix__name=["name"]) .count() - ) + ) # What the second filter does ? Is this usefull ? if "count" not in values[m["risk"][i][field]]: values[m["risk"][i][field]]["count"] = count @@ -535,17 +535,17 @@ def aggregate_risks_per_field( return values def risks_count_per_level(user: User, risk_assessments: list | None = None): - current_level = list() - residual_level = list() + current_level = [] + residual_level = [] - for r in aggregate_risks_per_field( + for level_name, level_data in aggregate_risks_per_field( user, "name", risk_assessments=risk_assessments ).items(): current_level.append( {"name": r[0], "value": r[1]["count"], "color": r[1]["color"], "localName": camel_case(r[0])} ) - for r in aggregate_risks_per_field( + for level_name, level_data in aggregate_risks_per_field( user, "name", residual=True, risk_assessments=risk_assessments ).items(): residual_level.append( diff --git a/backend/core/views.py b/backend/core/views.py index fcff38bfd..8d7ee541b 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -682,7 +682,7 @@ def impact(self, request, pk): return Response(choices) @action(detail=False, name="Get risk count per level") - def count_per_level(self, request): # _per_level + def count_per_level(self, request): return Response({"results": risks_count_per_level(request.user)}) diff --git a/frontend/src/lib/components/Chart/DonutChart.svelte b/frontend/src/lib/components/Chart/DonutChart.svelte index 38f56f66e..0020503a5 100644 --- a/frontend/src/lib/components/Chart/DonutChart.svelte +++ b/frontend/src/lib/components/Chart/DonutChart.svelte @@ -3,6 +3,7 @@ import { localItems } from '$lib/utils/locales'; import { languageTag } from '$paraglide/runtime'; + export let name: string; export let s_label: string; export let values: any[]; // Set the types for these variables later on @@ -15,6 +16,7 @@ let chart_element: HTMLElement | null = null; onMount(async () => { const echarts = await import('echarts'); + const chart_element = document.getElementById(chart_id); let chart = echarts.init(chart_element, null, { renderer: 'svg' }); // specify chart configuration item and data @@ -75,4 +77,4 @@ }); -
+
diff --git a/frontend/src/routes/(app)/analytics/+page.svelte b/frontend/src/routes/(app)/analytics/+page.svelte index cbdcb9cf9..3ef032865 100644 --- a/frontend/src/routes/(app)/analytics/+page.svelte +++ b/frontend/src/routes/(app)/analytics/+page.svelte @@ -306,6 +306,7 @@ {m.currentRiskLevelPerScenario()} {m.residualRiskLevelPerScenario()} Residual risk level per risk scenario
From 89d10f76406a0a7d0c0d8c41be59716dcf67bf69 Mon Sep 17 00:00:00 2001 From: monsieurswag Date: Sat, 24 Feb 2024 17:22:16 +0100 Subject: [PATCH 2/5] Make donut chart colors based on the choosen matrix colors --- frontend/src/routes/(app)/analytics/+page.svelte | 5 +++-- frontend/src/routes/(app)/analytics/composer/+page.svelte | 4 ++-- .../(app)/compliance-assessments/[id=uuid]/+page.svelte | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/routes/(app)/analytics/+page.svelte b/frontend/src/routes/(app)/analytics/+page.svelte index 3ef032865..c7b8ccd67 100644 --- a/frontend/src/routes/(app)/analytics/+page.svelte +++ b/frontend/src/routes/(app)/analytics/+page.svelte @@ -309,7 +309,7 @@ name="current_risk" s_label={cur_rsk_label} values={risk_level.current} - colors={RISK_COLOR_PALETTE} + colors={risk_level.current.map(object => object.color)} />
@@ -319,7 +319,7 @@ name="residual_risk" s_label={rsd_rsk_label} values={risk_level.residual} - colors={RISK_COLOR_PALETTE} + colors={risk_level.residual.map(object => object.color)} />
@@ -622,6 +622,7 @@ c0.27-0.268,0.707-0.268,0.979,0l7.908,7.83c0.27,0.268,0.27,0.701,0,0.969c-0.271, name="compliance_assessments" s_label={m.complianceAssessments()} values={compliance_assessment.donut.values} + colors={compliance_assessment.donut.values.map(object => object.itemStyle.color)} />
diff --git a/frontend/src/routes/(app)/analytics/composer/+page.svelte b/frontend/src/routes/(app)/analytics/composer/+page.svelte index 0c9b489fa..cb3c19395 100644 --- a/frontend/src/routes/(app)/analytics/composer/+page.svelte +++ b/frontend/src/routes/(app)/analytics/composer/+page.svelte @@ -32,7 +32,7 @@ name="current_risk_level" s_label="Current risk level per risk scenario" values={data.current_level} - colors={RISK_COLOR_PALETTE} + colors={data.current_level.map(object => object.color)} />
@@ -56,7 +56,7 @@ name="residual_risk_level" s_label="Residual risk level per risk scenario" values={data.residual_level} - colors={RISK_COLOR_PALETTE} + colors={data.residual_level.map(object => object.color)} />
diff --git a/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte b/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte index a940bcde5..be8dcb9c8 100644 --- a/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte +++ b/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte @@ -141,6 +141,7 @@ name="compliance_assessments" s_label="compliance_assessments" values={compliance_assessment_donut_values.values} + colors={compliance_assessment_donut_values.values.map(object => object.itemStyle.color)} />
From d48cf8a5bfd7c2c23097c8776128fd53c2f1cd24 Mon Sep 17 00:00:00 2001 From: eric-intuitem <71850047+eric-intuitem@users.noreply.github.com> Date: Sun, 25 Feb 2024 03:27:11 +0100 Subject: [PATCH 3/5] fix regression --- backend/core/helpers.py | 10 +++++----- frontend/src/lib/components/Chart/DonutChart.svelte | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/core/helpers.py b/backend/core/helpers.py index c38f9aba8..3333f25da 100644 --- a/backend/core/helpers.py +++ b/backend/core/helpers.py @@ -535,23 +535,23 @@ def aggregate_risks_per_field( return values def risks_count_per_level(user: User, risk_assessments: list | None = None): - current_level = [] - residual_level = [] + current_level = list() + residual_level = list() - for level_name, level_data in aggregate_risks_per_field( + for r in aggregate_risks_per_field( user, "name", risk_assessments=risk_assessments ).items(): current_level.append( {"name": r[0], "value": r[1]["count"], "color": r[1]["color"], "localName": camel_case(r[0])} ) - for level_name, level_data in aggregate_risks_per_field( + for r in aggregate_risks_per_field( user, "name", residual=True, risk_assessments=risk_assessments ).items(): residual_level.append( {"name": r[0], "value": r[1]["count"], "color": r[1]["color"], "localName": camel_case(r[0])} ) - + print("current", current_level, "residual", residual_level) return {"current": current_level, "residual": residual_level} diff --git a/frontend/src/lib/components/Chart/DonutChart.svelte b/frontend/src/lib/components/Chart/DonutChart.svelte index 0020503a5..42a40acc7 100644 --- a/frontend/src/lib/components/Chart/DonutChart.svelte +++ b/frontend/src/lib/components/Chart/DonutChart.svelte @@ -16,7 +16,7 @@ let chart_element: HTMLElement | null = null; onMount(async () => { const echarts = await import('echarts'); - const chart_element = document.getElementById(chart_id); + const chart_element = document.getElementById('chart_id'); let chart = echarts.init(chart_element, null, { renderer: 'svg' }); // specify chart configuration item and data @@ -77,4 +77,4 @@ }); -
+
From 67e8dee9d26716a6a66576f1fbb759f795bbcadb Mon Sep 17 00:00:00 2001 From: eric-intuitem <71850047+eric-intuitem@users.noreply.github.com> Date: Sun, 25 Feb 2024 03:45:58 +0100 Subject: [PATCH 4/5] Update DonutChart.svelte fix rebase regression --- frontend/src/lib/components/Chart/DonutChart.svelte | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/lib/components/Chart/DonutChart.svelte b/frontend/src/lib/components/Chart/DonutChart.svelte index 42a40acc7..13c203b1f 100644 --- a/frontend/src/lib/components/Chart/DonutChart.svelte +++ b/frontend/src/lib/components/Chart/DonutChart.svelte @@ -16,7 +16,6 @@ let chart_element: HTMLElement | null = null; onMount(async () => { const echarts = await import('echarts'); - const chart_element = document.getElementById('chart_id'); let chart = echarts.init(chart_element, null, { renderer: 'svg' }); // specify chart configuration item and data @@ -77,4 +76,4 @@ }); -
+
\ No newline at end of file From b18684284ca935bd2943118c8acb08778ad80edb Mon Sep 17 00:00:00 2001 From: eric-intuitem <71850047+eric-intuitem@users.noreply.github.com> Date: Sun, 25 Feb 2024 03:51:24 +0100 Subject: [PATCH 5/5] Update helpers.py remove debug --- backend/core/helpers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/core/helpers.py b/backend/core/helpers.py index 3333f25da..1d74ac39e 100644 --- a/backend/core/helpers.py +++ b/backend/core/helpers.py @@ -551,7 +551,6 @@ def risks_count_per_level(user: User, risk_assessments: list | None = None): residual_level.append( {"name": r[0], "value": r[1]["count"], "color": r[1]["color"], "localName": camel_case(r[0])} ) - print("current", current_level, "residual", residual_level) return {"current": current_level, "residual": residual_level} @@ -709,7 +708,6 @@ def risk_status(user: User, risk_assessment_list): names.append(str(risk_assessment.project) + " " + str(risk_assessment.version)) y_max_rsk = max(max_tmp, default=0) + 1 - print("y_max_rsk: ", y_max_rsk) return { "names": names,