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

Add functionality to use archived vr_collection data #4832

Merged
merged 5 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions packages/app/schema/archived_vr_collection/__index.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
Jorrik-Klijnsma-Work marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 13 additions & 3 deletions packages/app/src/components/choropleth/logic/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
GmCollectionTestedOverall,
GmCollectionVaccineCoveragePerAgeGroup,
VrCollection,
ArchivedVrCollection,
VrCollectionDisabilityCareArchived_20230126,
VrCollectionElderlyAtHomeArchived_20230126,
VrCollectionVulnerableNursingHome,
Expand Down Expand Up @@ -45,16 +46,25 @@ export const mapToCodeType: Record<MapType, CodeProp> = {

export type ChoroplethCollection = GmCollection | VrCollection;

export type InferedMapType<T extends ChoroplethDataItem> = T extends GmDataItem ? 'gm' : T extends VrDataItem ? 'vr' : never;
export type InferedMapType<T extends ChoroplethDataItem> = T extends GmDataItem ? 'gm' : T extends VrDataItem | ArchivedVrDataItem ? 'vr' : never;

export type InferedDataCollection<T extends ChoroplethDataItem> = T extends GmDataItem ? GmCollection : T extends VrDataItem ? VrCollection : never;
export type InferedDataCollection<T extends ChoroplethDataItem> = 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];

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
*/
ben-van-eekelen marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -65,7 +75,7 @@ export type MappedDataCollection<T extends MapType> = T extends 'gm' ? GmCollect
*/
export type MappedDataItem<T extends MapType> = 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;
Expand Down
33 changes: 32 additions & 1 deletion packages/app/src/static-props/get-data.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -48,6 +60,8 @@ const json = {
gmCollection: initializeFeatureFlaggedData<GmCollection>(loadJsonFromDataFile<GmCollection>('GM_COLLECTION.json'), 'gm_collection'),
archived: {
nl: initializeFeatureFlaggedData<ArchivedNl>(loadJsonFromDataFile<ArchivedNl>('NL.json', 'json/archived'), 'nl'),
vrCollection: initializeFeatureFlaggedData<ArchivedVrCollection>(loadJsonFromDataFile<ArchivedVrCollection>('VR_COLLECTION.json', 'json/archived'), 'vr_collection'),
gmCollection: initializeFeatureFlaggedData<ArchivedGmCollection>(loadJsonFromDataFile<ArchivedGmCollection>('GM_COLLECTION.json', 'json/archived'), 'gm_collection'),
},
};

Expand Down Expand Up @@ -288,6 +302,23 @@ export function createGetChoroplethData<T1, T2>(settings?: {
};
}

export function createGetArchivedChoroplethData<T1, T2>(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,
ben-van-eekelen marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
9 changes: 9 additions & 0 deletions packages/common/src/types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading