Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Added Variant_code and order #4343

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
54 changes: 22 additions & 32 deletions packages/app/schema/nl/__named_difference.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,31 @@
"required": ["variants__percentage"],
"additionalProperties": false,
"definitions": {
"named_diff_integer": {
"title": "named_difference_integer",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"old_value": {
"type": "integer"
},
"difference": {
"type": "integer"
},
"old_date_unix": {
"type": "integer"
},
"new_date_unix": {
"type": "integer"
}
},
"required": [
"name",
"old_value",
"difference",
"old_date_unix",
"new_date_unix"
],
"additionalProperties": false
},
"named_diff_decimal": {
"title": "named_difference_decimal",
"type": "object",
"properties": {
"name": {
"type": "string"
"variant_code": {
"type": "string",
"enum": [
"B_1_1_529",
"BA_1",
"BA_2",
"BA_4",
"BA_5",
"BA_2+S:L452X",
"BA_2_12_1",
"BA_3",
"B_1_617_2",
"B_1_351",
"P_1",
"B_1_1_7",
"B_1_621",
"C_37",
"BA_2_75",
"other_table",
"other_graph"
]
},
"old_value": {
"type": "number"
Expand All @@ -63,7 +53,7 @@
}
},
"required": [
"name",
"variant_code",
"old_value",
"difference",
"old_date_unix",
Expand Down
33 changes: 30 additions & 3 deletions packages/app/schema/nl/variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,29 @@
"type": "object",
"title": "nl_variants_variant",
"additionalProperties": false,
"required": ["name", "values", "last_value"],
"required": ["variant_code", "values", "last_value"],
"properties": {
"name": {
"type": "string"
"variant_code": {
"type": "string",
"enum": [
"B_1_1_529",
"BA_1",
"BA_2",
"BA_4",
"BA_5",
"BA_2+S:L452X",
"BA_2_12_1",
"BA_3",
"B_1_617_2",
"B_1_351",
"P_1",
"B_1_1_7",
"B_1_621",
"C_37",
"BA_2_75",
"other_table",
"other_graph"
]
},
"values": {
"type": "array",
Expand All @@ -38,16 +57,21 @@
"title": "nl_variants_variant_value",
"additionalProperties": false,
"required": [
"order",
"occurrence",
"percentage",
"is_variant_of_concern",
"has_historical_significance",
"sample_size",
"date_start_unix",
"date_end_unix",
"date_of_report_unix",
"date_of_insertion_unix"
],
"properties": {
"order": {
"type": "integer"
},
"occurrence": {
"type": "integer"
},
Expand All @@ -71,6 +95,9 @@
},
"date_of_insertion_unix": {
"type": "integer"
},
"date_of_report_unix": {
"type": "integer"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { NlVariants } from '@corona-dashboard/common';
import { isDefined } from 'ts-is-present';
import { SiteText } from '~/locale';

type VariantName = keyof SiteText['common']['variants'];
export type VariantCode = keyof SiteText['common']['variant_codes'];

export type VariantChartValue = {
date_start_unix: number;
date_end_unix: number;
is_reliable: boolean;
} & Partial<{
[key in `${VariantName}_percentage`]: number;
[key in `${VariantCode}_percentage`]: number;
}>;

const EMPTY_VALUES = {
variantChart: null,
dates: {
date_of_insertion_unix: 0,
date_of_report_unix: 0,
date_start_unix: 0,
date_end_unix: 0,
},
Expand All @@ -26,22 +26,15 @@ export function getVariantChartData(variants: NlVariants | undefined) {
return EMPTY_VALUES;
}

const firstOccurences = variants.values.sort().reverse().reduce<Record<string, number>>(
(acc, x) =>
Object.assign(acc, {
[x.name]: x.values.find((value) => value.percentage > 0)
?.date_start_unix,
}),
{}
);

const variantsOfConcern = variants.values
.filter(
(x) =>
x.last_value.is_variant_of_concern ||
x.last_value.has_historical_significance
(variant) =>
variant.last_value.is_variant_of_concern ||
variant.last_value.has_historical_significance
)
.sort((a, b) => firstOccurences[b.name] - firstOccurences[a.name]);
.sort((a, b) => b.last_value.order - a.last_value.order);



const firstVariant = variantsOfConcern.shift();

Expand All @@ -54,12 +47,12 @@ export function getVariantChartData(variants: NlVariants | undefined) {
is_reliable: true,
date_start_unix: value.date_start_unix,
date_end_unix: value.date_end_unix,
[`${firstVariant.name}_percentage`]: value.percentage,
[`${firstVariant.variant_code}_percentage`]: value.percentage,
};

variantsOfConcern.forEach((variant) => {
(item as unknown as Record<string, number>)[
`${variant.name}_percentage`
`${variant.variant_code}_percentage`
] = variant.values[index].percentage;
});

Expand All @@ -69,7 +62,7 @@ export function getVariantChartData(variants: NlVariants | undefined) {
return {
variantChart: values,
dates: {
date_of_insertion_unix: firstVariant.last_value.date_of_insertion_unix,
date_of_report_unix: firstVariant.last_value.date_of_report_unix,
date_start_unix: firstVariant.last_value.date_start_unix,
date_end_unix: firstVariant.last_value.date_end_unix,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { NlVariants, colors } from '@corona-dashboard/common';
import { isDefined } from 'ts-is-present';
import { VariantCode } from './'

export type ColorMatch = {
variant: VariantCode;
color: string;
};

const getColorForVariant = (variantCode: VariantCode, index: number): string => {
if (variantCode === 'other_table') return colors.data.variants.other_table;
if (variantCode === 'other_graph') return colors.data.variants.other_graph;

return colors.data.variants.colorList[index];
}

export function getVariantOrderColors(
variants: NlVariants | undefined
): ColorMatch[] {
if (!isDefined(variants) || !isDefined(variants.values)) {
return [];
}

const colorOrder = variants.values
.filter(
(variant) =>
variant.last_value.is_variant_of_concern ||
variant.last_value.has_historical_significance
)
.sort((a, b) => a.last_value.order - b.last_value.order)
.map((variant, index) => {
const variantColor = getColorForVariant(variant.variant_code, index)
return {
variant: variant.variant_code,
color: variantColor
};
});

return colorOrder;
}

This file was deleted.

Loading