From bfbff521da3fb505cf57849155363d459533240c Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard29 Date: Mon, 7 Aug 2023 15:18:59 +0200 Subject: [PATCH] Add functionality to use archived vr_collection data --- .../archived_vr_collection/__index.json | 32 ++++++++++++++++++ .../src/components/choropleth/logic/types.ts | 16 +++++++-- packages/app/src/static-props/get-data.ts | 33 ++++++++++++++++++- packages/common/src/types/data.ts | 9 +++++ 4 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 packages/app/schema/archived_vr_collection/__index.json diff --git a/packages/app/schema/archived_vr_collection/__index.json b/packages/app/schema/archived_vr_collection/__index.json new file mode 100644 index 0000000000..2a8ba49809 --- /dev/null +++ b/packages/app/schema/archived_vr_collection/__index.json @@ -0,0 +1,32 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "archived_vr_collection", + "additionalProperties": false, + "required": [ + "last_generated", + "proto_name", + "name", + "code" + ], + "properties": { + "last_generated": { + "type": "string" + }, + "proto_name": { + "$ref": "#/$defs/archived_vr_collection_id" + }, + "name": { + "$ref": "#/$defs/archived_vr_collection_id" + }, + "code": { + "$ref": "#/$defs/archived_vr_collection_id" + } + }, + "$defs": { + "archived_vr_collection_id": { + "type": "string", + "enum": ["ARCHIVED_VR_COLLECTION"] + } + } +} \ No newline at end of file diff --git a/packages/app/src/components/choropleth/logic/types.ts b/packages/app/src/components/choropleth/logic/types.ts index 30e350258a..52eca5f786 100644 --- a/packages/app/src/components/choropleth/logic/types.ts +++ b/packages/app/src/components/choropleth/logic/types.ts @@ -5,6 +5,7 @@ import type { GmCollectionTestedOverall, GmCollectionVaccineCoveragePerAgeGroup, VrCollection, + ArchivedVrCollection, VrCollectionDisabilityCareArchived_20230126, VrCollectionElderlyAtHomeArchived_20230126, VrCollectionVulnerableNursingHome, @@ -45,9 +46,15 @@ export const mapToCodeType: Record = { export type ChoroplethCollection = GmCollection | VrCollection; -export type InferedMapType = T extends GmDataItem ? 'gm' : T extends VrDataItem ? 'vr' : never; +export type InferedMapType = T extends GmDataItem ? 'gm' : T extends VrDataItem | ArchivedVrDataItem ? 'vr' : never; -export type InferedDataCollection = T extends GmDataItem ? GmCollection : T extends VrDataItem ? VrCollection : never; +export type InferedDataCollection = T extends GmDataItem + ? GmCollection + : T extends VrDataItem + ? VrCollection + : T extends ArchivedVrDataItem + ? ArchivedVrCollection + : never; export type VrDataCollection = VrCollectionDisabilityCareArchived_20230126[] | VrCollectionElderlyAtHomeArchived_20230126[] | VrCollectionVulnerableNursingHome[]; export type VrDataItem = VrDataCollection[number]; @@ -55,6 +62,9 @@ export type VrDataItem = VrDataCollection[number]; export type GmDataCollection = GmCollectionHospitalNice[] | GmCollectionTestedOverall[] | GmCollectionSewer[] | GmCollectionVaccineCoveragePerAgeGroup[]; export type GmDataItem = GmDataCollection[number]; +export type ArchivedVrDataCollection = null[] | null[]; +export type ArchivedVrDataItem = ArchivedVrDataCollection[number]; + /** * Here we map a MapType to a corresponding DataCollection type */ @@ -65,7 +75,7 @@ export type MappedDataCollection = T extends 'gm' ? GmCollect */ export type MappedDataItem = T extends 'gm' ? GmDataItem : T extends 'vr' ? VrDataItem : never; -export type ChoroplethDataItem = GmDataItem | VrDataItem; +export type ChoroplethDataItem = GmDataItem | VrDataItem | ArchivedVrDataItem; export type CodedGeoProperties = { code: string; diff --git a/packages/app/src/static-props/get-data.ts b/packages/app/src/static-props/get-data.ts index fcaaf45c40..000d7e96dc 100644 --- a/packages/app/src/static-props/get-data.ts +++ b/packages/app/src/static-props/get-data.ts @@ -1,4 +1,16 @@ -import { ArchivedGm, ArchivedNl, assert, Gm, GmCollection, gmData, Nl, sortTimeSeriesInDataInPlace, VrCollection } from '@corona-dashboard/common'; +import { + ArchivedGm, + ArchivedGmCollection, + ArchivedNl, + ArchivedVrCollection, + assert, + Gm, + GmCollection, + gmData, + Nl, + sortTimeSeriesInDataInPlace, + VrCollection, +} from '@corona-dashboard/common'; import { SanityClient } from '@sanity/client'; import { get } from 'lodash'; import set from 'lodash/set'; @@ -48,6 +60,8 @@ const json = { gmCollection: initializeFeatureFlaggedData(loadJsonFromDataFile('GM_COLLECTION.json'), 'gm_collection'), archived: { nl: initializeFeatureFlaggedData(loadJsonFromDataFile('NL.json', 'json/archived'), 'nl'), + vrCollection: initializeFeatureFlaggedData(loadJsonFromDataFile('VR_COLLECTION.json', 'json/archived'), 'vr_collection'), + gmCollection: initializeFeatureFlaggedData(loadJsonFromDataFile('GM_COLLECTION.json', 'json/archived'), 'gm_collection'), }, }; @@ -288,6 +302,23 @@ export function createGetChoroplethData(settings?: { }; } +export function createGetArchivedChoroplethData(settings?: { + vr?: (collection: ArchivedVrCollection, context: GetStaticPropsContext) => T1; + gm?: (collection: ArchivedGmCollection, context: GetStaticPropsContext) => T2; +}) { + return (context: GetStaticPropsContext) => { + const filterVr = settings?.vr ?? NOOP; + const filterGm = settings?.gm ?? NOOP; + + return { + choropleth: { + vr: filterVr(json.archived.vrCollection, context) as T1, + gm: filterGm(json.archived.gmCollection, context) as T2, + }, + }; + }; +} + /** * This function makes sure that for metrics with inaccurate data for the last x * items, the last_value is replaced with the last accurate value. For now only diff --git a/packages/common/src/types/data.ts b/packages/common/src/types/data.ts index 413568d401..272357a4e8 100644 --- a/packages/common/src/types/data.ts +++ b/packages/common/src/types/data.ts @@ -267,6 +267,15 @@ export interface NlReproductionValue { date_of_insertion_unix: number; } +export type ArchivedVrCollectionId = 'ARCHIVED_VR_COLLECTION'; + +export interface ArchivedVrCollection { + last_generated: string; + proto_name: ArchivedVrCollectionId; + name: ArchivedVrCollectionId; + code: ArchivedVrCollectionId; +} + export type GmCode = string; export interface Gm {