Skip to content

Commit 3d21ee8

Browse files
committed
feat: split cases/death data source
1 parent 45f8a1c commit 3d21ee8

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

src/modes/data-anomalies/AnnotationTable.svelte

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,28 @@
33
import SortColumnIndicator from '../mobile/components/SortColumnIndicator.svelte';
44
import { SortHelper } from '../mobile/components/tableUtils';
55
import ExternalLinkIcon from '!raw-loader!@fortawesome/fontawesome-free/svgs/solid/external-link-alt.svg';
6-
import { getDataSource, CASES_DEATH_SOURCE } from '../../stores/dataSourceLookup';
6+
import { getDataSource, CASES_SOURCE, DEATH_SOURCE } from '../../stores/dataSourceLookup';
77
import { formatDateISO } from '../../formats';
88
import chevronRightIcon from '!raw-loader!@fortawesome/fontawesome-free/svgs/solid/chevron-right.svg';
99
import { getInfoByName } from '../../maps';
1010
import { isCasesSignal, isDeathSignal } from '../../data';
1111
12+
/**
13+
* @param {import ('../../data/annotations').Annotation} d
14+
*/
15+
function resolveDataSource(d) {
16+
if (d.source !== 'indicator-combination') {
17+
return getDataSource(d.source);
18+
}
19+
const signals = [...d.signals];
20+
if (signals.every((d) => isCasesSignal(d))) {
21+
return getDataSource(CASES_SOURCE);
22+
}
23+
if (signals.every((d) => isDeathSignal(d))) {
24+
return getDataSource(DEATH_SOURCE);
25+
}
26+
return getDataSource(d.source);
27+
}
1228
/**
1329
*
1430
* @param {import ('../../data/annotations').Annotation} d
@@ -19,10 +35,7 @@
1935
annotation: d,
2036
problem: d.problem,
2137
// in case just of cases/death replace with custom data source name
22-
source:
23-
[...d.signals].every((s) => isCasesSignal(s) || isDeathSignal(s)) && d.source === 'indicator-combination'
24-
? getDataSource(CASES_DEATH_SOURCE)
25-
: getDataSource(d.source),
38+
source: resolveDataSource(d),
2639
reference: d.reference,
2740
dateRange: `${formatDateISO(d.dates[0])} - ${formatDateISO(d.dates[1])}`,
2841
};

src/modes/mobile/IndicatorTable.svelte

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import { SensorParam } from '../../stores/params';
55
import { formatDateISO, formatDateShortNumbers } from '../../formats';
66
import filterIcon from '!raw-loader!@fortawesome/fontawesome-free/svgs/solid/filter.svg';
7-
import { CASES_DEATH_SOURCE } from '../../stores/dataSourceLookup';
87
import { currentMode } from '../../stores';
98
import { modeByID } from '..';
109
import TrendIndicator from './TrendIndicator.svelte';
@@ -38,7 +37,7 @@
3837
e.sensors.push(sensor);
3938
} else {
4039
map.set(ds, {
41-
name: sensor.isCasesOrDeath ? CASES_DEATH_SOURCE : sensor.id,
40+
name: ds,
4241
label: ds,
4342
sensors: [sensor],
4443
});
@@ -58,12 +57,7 @@
5857
}
5958
6059
function matchDataSource(sensor, selected) {
61-
return (
62-
selected === '' ||
63-
selected === 'all' ||
64-
(sensor.isCasesOrDeath && selected === CASES_DEATH_SOURCE) ||
65-
(!sensor.isCasesOrDeath && sensor.value.id === selected)
66-
);
60+
return selected === '' || selected === 'all' || sensor.dataSourceName === selected;
6761
}
6862
/**
6963
* @param {import("../../stores/params").SensorParam} sensor

src/stores/dataSourceLookup.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { isCasesSignal, isDeathSignal } from '../data/signals';
22

3-
export const CASES_DEATH_SOURCE = 'cases-deaths';
3+
export const CASES_SOURCE = 'cases';
4+
export const DEATH_SOURCE = 'deaths';
45

56
const sourceNameLookup = {
67
chng: 'Change Healthcare',
78
'doctor-visits': 'Doctor Visits',
89
'fb-survey': 'Delphi Pandemic Survey via Facebook',
910
ght: 'Google Search Trends',
1011
'hospital-admissions': 'Hospital Admissions',
11-
[CASES_DEATH_SOURCE]: 'Public Health Reports',
12+
[CASES_SOURCE]: 'COVID Cases',
13+
[DEATH_SOURCE]: 'COVID Deaths',
1214
'indicator-combination': 'COVID Indicator Combination',
1315
quidel: 'Quidel Antigen Tests',
1416
safegraph: 'SafeGraph Mobility Data',
@@ -22,8 +24,11 @@ export function getDataSource(sensor) {
2224
if (typeof sensor === 'string') {
2325
return sourceNameLookup[sensor] || sensor;
2426
}
25-
if (isCasesSignal(sensor.signal) || isDeathSignal(sensor.signal)) {
26-
return sourceNameLookup[CASES_DEATH_SOURCE];
27+
if (isCasesSignal(sensor.signal)) {
28+
return sourceNameLookup[CASES_SOURCE];
29+
}
30+
if (isDeathSignal(sensor.signal)) {
31+
return sourceNameLookup[DEATH_SOURCE];
2732
}
2833
return sourceNameLookup[sensor.id] || sensor.id;
2934
}

src/stores/params.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ export class SensorParam {
628628
this.value = sensor;
629629
this.rawValue = sensor.rawSensor;
630630
this.isCasesOrDeath = sensor.isCasesOrDeath || false;
631+
this.dataSourceName = sensor.dataSourceName;
631632
// fractions as percentages here
632633
this.factor = sensor.format === 'fraction' ? 100 : 1;
633634
this.isPercentage = sensor.format == 'percent' || sensor.format === 'fraction';

0 commit comments

Comments
 (0)