starting SymptomVsSymptomChartDataProviderTest
This commit is contained in:
20
docs/SymptomsCausedByCOVIDLots/js/Sets.js
Normal file
20
docs/SymptomsCausedByCOVIDLots/js/Sets.js
Normal file
@@ -0,0 +1,20 @@
|
||||
class Sets {
|
||||
|
||||
static filterSet(set, predicate) {
|
||||
return new Set([...set].filter(predicate));
|
||||
}
|
||||
|
||||
static union(sets) {
|
||||
return sets.reduce(
|
||||
(union, set) => new Set([...union, ...set]),
|
||||
new Set());
|
||||
}
|
||||
|
||||
static intersection(set1, set2) {
|
||||
return new Set([...set1].filter(x => set2.has(x)));
|
||||
}
|
||||
|
||||
static isEmpty(set) {
|
||||
return set.size == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
class SymptomVsSymptomChartDataProvider {
|
||||
|
||||
static retainCommonLots({ prrByLotX, prrByLotY }) {
|
||||
const commonLots = SymptomVsSymptomChartDataProvider.#getCommonKeys(prrByLotX, prrByLotY);
|
||||
return {
|
||||
prrByLotX: SymptomVsSymptomChartDataProvider.#retainKeysOfDict(prrByLotX, commonLots),
|
||||
prrByLotY: SymptomVsSymptomChartDataProvider.#retainKeysOfDict(prrByLotY, commonLots)
|
||||
};
|
||||
}
|
||||
|
||||
static #getCommonKeys(dict1, dict2) {
|
||||
return Sets.intersection(
|
||||
SymptomVsSymptomChartDataProvider.#getKeySet(dict1),
|
||||
SymptomVsSymptomChartDataProvider.#getKeySet(dict2));
|
||||
}
|
||||
|
||||
static #getKeySet(dict) {
|
||||
return new Set(Object.keys(dict));
|
||||
}
|
||||
|
||||
static #retainKeysOfDict(dict, keys2Retain) {
|
||||
const entries2Retain =
|
||||
Object
|
||||
.entries(dict)
|
||||
.filter(([key, _]) => keys2Retain.has(key));
|
||||
return Object.fromEntries(entries2Retain);
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,13 @@ class SymptomVsSymptomChartView {
|
||||
// FK-TODO: fetch multiple files: https://stackoverflow.com/a/31711496 or https://stackoverflow.com/a/53892713
|
||||
PrrByVaccineProvider.getPrrByVaccine(symptom1)
|
||||
.then(
|
||||
prrByKey1 => {
|
||||
prrByLot1 => {
|
||||
PrrByVaccineProvider.getPrrByVaccine(symptom2)
|
||||
.then(
|
||||
prrByKey2 => {
|
||||
prrByLot2 => {
|
||||
const myData =
|
||||
Object
|
||||
.values(prrByKey2)
|
||||
.values(prrByLot2)
|
||||
.map(
|
||||
val =>
|
||||
({
|
||||
|
||||
Reference in New Issue
Block a user