Skip to content

Commit

Permalink
feat: add node score
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Apr 26, 2024
1 parent fb8561c commit 1ce126b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
if (node.status && node.assessable) {
statusCounts[node.status] = (statusCounts[node.status] || 0) + 1;
}
if (node.score && node.assessable && node.status !== 'not_applicable') {
statusCounts['scored'] = (statusCounts['scored'] || 0) + 1;
statusCounts['total_score'] = (statusCounts['total_score'] || 0) + node.score;
}
if (node.children && Object.keys(node.children).length > 0) {
for (const childId in node.children) {
Expand Down Expand Up @@ -160,7 +164,7 @@
{/each}
</div>
{#if data.global_score.score >= 0}
<div class="flex items-center cursor-pointer">
<div class="flex items-center">
<ProgressRadial
stroke={100}
meter={displayScoreColor(data.global_score.score, data.global_score.max_score)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { page } from '$app/stores';
import type { z } from 'zod';
import type { ReferenceControlSchema, ThreatSchema } from '$lib/utils/schemas';
import { ProgressRadial } from '@skeletonlabs/skeleton';
import { displayScoreColor, formatScoreValue } from '$lib/utils/helpers';
export let ref_id: string;
export let name: string;
Expand All @@ -15,6 +17,7 @@
export let status: string | undefined = undefined;
export let statusCounts: Record<string, number> | undefined;
export let assessable: boolean;
export let max_score: number;
const node = {
ref_id,
Expand All @@ -26,6 +29,7 @@
children,
canEditRequirementAssessment,
status,
max_score,
statusCounts,
assessable,
...$$restProps
Expand Down Expand Up @@ -86,6 +90,12 @@
}
);
function nodeScore(): number {
if (!statusCounts) return -1;
let mean = statusCounts['total_score'] / statusCounts['scored'];
return Math.floor(mean * 10) / 10;
}
$: classesShowInfo = (show: boolean) => (!show ? 'hidden' : '');
$: classesShowInfoText = (show: boolean) => (show ? 'text-primary-500' : '');
$: classesPercentText = (statusColor: string) => (statusColor === '#000000' ? 'text-white' : '');
Expand Down Expand Up @@ -197,19 +207,32 @@
{/if}
</div>
{#if hasAssessableChildren}
<div class="flex max-w-96 grow bg-gray-200 rounded-full overflow-hidden h-4 shrink self-center">
{#each orderedStatusPercentages as sp}
<div
class="flex flex-col justify-center overflow-hidden text-xs text-center {classesPercentText(
complianceColorMap[sp.status]
)}"
style="width: {sp.percentage.value}%; background-color: {complianceColorMap[sp.status]}"
>
{#if sp.status !== 'to_do'}
{sp.percentage.display}%
{/if}
</div>
{/each}
<div class="flex max-w-96 grow items-center space-x-2">
<div class="flex max-w-96 grow bg-gray-200 rounded-full overflow-hidden h-4 shrink self-center">
{#each orderedStatusPercentages as sp}
<div
class="flex flex-col justify-center overflow-hidden text-xs text-center {classesPercentText(
complianceColorMap[sp.status]
)}"
style="width: {sp.percentage.value}%; background-color: {complianceColorMap[sp.status]}"
>
{#if sp.status !== 'to_do'}
{sp.percentage.display}%
{/if}
</div>
{/each}
</div>
{#if nodeScore() >= 0}
<span>
<ProgressRadial
stroke={100}
meter={displayScoreColor(nodeScore(), node.max_score)}
font={150}
value={formatScoreValue(nodeScore(), node.max_score)}
width={'w-10'}>{nodeScore()}</ProgressRadial
>
</span>
{/if}
</div>
{/if}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface Node {
style: string;
children?: Record<string, Node>;
status?: string; // Assuming that the status field exists in nodes similar to leaves
score?: number; // Assuming that the score field exists in nodes similar to leaves
}

0 comments on commit 1ce126b

Please sign in to comment.