Add risk charts

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Jonathan
2025-05-22 15:30:02 +02:00
committed by Sacha Al Himdani
parent fc45d2f00d
commit 08bf65d919
13 changed files with 386 additions and 23 deletions

View File

@@ -0,0 +1,20 @@
export function times<T>(n: number, cb: (i: number) => T): T[] {
return Array.from({ length: n }, (_, i) => cb(i));
}
export function groupBy<T>(
arr: T[],
key: (item: T) => string,
): Record<string, T[]> {
return arr.reduce(
(acc, item) => {
const k = key(item);
if (!acc[k]) {
acc[k] = [];
}
acc[k].push(item);
return acc;
},
{} as Record<string, T[]>,
);
}

View File

@@ -1,2 +1,5 @@
export { objectKeys } from "./object";
export { sprintf } from "./string";
export { getRiskImpacts, getRiskLikelihoods } from "./risk";
export { times, groupBy } from "./array";
export { randomInt } from "./number";

View File

@@ -0,0 +1,3 @@
export function randomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

View File

@@ -0,0 +1,51 @@
type Translator = (s: string) => string;
export function getRiskImpacts(__: Translator) {
return [
{
value: 1,
label: __("Negligible"),
},
{
value: 2,
label: __("Low"),
},
{
value: 3,
label: __("Moderate"),
},
{
value: 4,
label: __("Significant"),
},
{
value: 5,
label: __("Catastrophic"),
},
];
}
export function getRiskLikelihoods(__: Translator) {
return [
{
value: 1,
label: __("Improbable"),
},
{
value: 2,
label: __("Remote"),
},
{
value: 3,
label: __("Occasional"),
},
{
value: 4,
label: __("Probable"),
},
{
value: 5,
label: __("Frequent"),
},
];
}