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

Commit

Permalink
Add functionality to use archived vr_collection data (#4832)
Browse files Browse the repository at this point in the history
* Add functionality to use archived vr_collection data

* Apply corrections from review

* Update keyname in root of object

* update types with correct archivedVrCollectionId

* Refactor ArchivedVrDataCollection to prevent typeerrors

---------

Co-authored-by: VWSCoronaDashboard29 <[email protected]>
  • Loading branch information
ben-van-eekelen and VWSCoronaDashboard29 authored Aug 8, 2023
1 parent 2ed48f0 commit 5879a92
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 13 deletions.
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": ["VR_COLLECTION"]
}
}
}
24 changes: 12 additions & 12 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,27 +46,26 @@ 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];

/**
* Here we map a MapType to a corresponding DataCollection type
*/
export type MappedDataCollection<T extends MapType> = T extends 'gm' ? GmCollection : T extends 'vr' ? VrCollection : never;

/**
* Here we map a MapType to a corresponding DataItem type
*/
export type MappedDataItem<T extends MapType> = T extends 'gm' ? GmDataItem : T extends 'vr' ? VrDataItem : never;
export type ArchivedVrDataCollection = [];
export type ArchivedVrDataItem = ArchivedVrDataCollection[number];

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 {
archivedChoropleth: {
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
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 = 'VR_COLLECTION';

export interface ArchivedVrCollection {
last_generated: string;
proto_name: ArchivedVrCollectionId;
name: ArchivedVrCollectionId;
code: ArchivedVrCollectionId;
}

export type GmCode = string;

export interface Gm {
Expand Down

0 comments on commit 5879a92

Please sign in to comment.