Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Donut Chart #62

Merged
merged 5 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])}
)

return {"current": current_level, "residual": residual_level}


Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)})


Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/components/Chart/DonutChart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,4 +76,4 @@
});
</script>

<div class="bg-white w-auto h-full" bind:this={chart_element} />
<div class="bg-white w-auto h-full" bind:this={chart_element} />
7 changes: 5 additions & 2 deletions frontend/src/routes/(app)/analytics/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,20 @@
<span class="text-sm font-semibold">{m.currentRiskLevelPerScenario()}</span>

<DonutChart
name="current_risk"
s_label={cur_rsk_label}
values={risk_level.current}
colors={RISK_COLOR_PALETTE}
colors={risk_level.current.map(object => object.color)}
/>
</div>
<div class="h-96 p-2 m-2 w-1/3">
<span class="text-sm font-semibold">{m.residualRiskLevelPerScenario()}</span>

<DonutChart
name="residual_risk"
s_label={rsd_rsk_label}
values={risk_level.residual}
colors={RISK_COLOR_PALETTE}
colors={risk_level.residual.map(object => object.color)}
/>
</div>
<div class="h-96 p-2 m-2 w-1/3">
Expand Down Expand Up @@ -620,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)}
/>
</div>
<div class="absolute top-0 right-0 mt-2 space-x-1">
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/routes/(app)/analytics/composer/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@

<div class="items-center h-96">
<DonutChart
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)}
/>
</div>
</div>
Expand All @@ -52,9 +53,10 @@
<div class="p-2 text-sm font-semibold">Residual risk level per risk scenario</div>
<div class="items-center h-96">
<DonutChart
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)}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@
</div>
<div class="w-full">
<DonutChart
name="compliance_assessments"
s_label="compliance_assessments"
values={compliance_assessment_donut_values.values}
colors={compliance_assessment_donut_values.values.map(object => object.itemStyle.color)}
/>
</div>
<div class="flex flex-row space-x-2 ml-4">
Expand Down
Loading