Skip to content

Commit 8baf276

Browse files
authored
Improve handling for URL-based signals & support COVIDcast EpiWeeks (#53)
* Improve handling for URL-based signals
1 parent bd9aa45 commit 8baf276

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

src/api/EpiData.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,17 @@ export function loadDataSet(
150150
});
151151
}
152152

153-
export function fetchCOVIDcastMeta(): Promise<{ geo_type: string; signal: string; data_source: string }[]> {
153+
export function fetchCOVIDcastMeta(): Promise<
154+
{ geo_type: string; signal: string; data_source: string; time_type?: string }[]
155+
> {
154156
const url = new URL(ENDPOINT + `/covidcast_meta/`);
155157
url.searchParams.set('format', 'json');
156-
return fetchImpl<{ geo_type: string; signal: string; data_source: string }[]>(url).catch((error) => {
157-
console.warn('failed fetching data', error);
158-
return [];
159-
});
158+
return fetchImpl<{ geo_type: string; signal: string; data_source: string; time_type?: string }[]>(url).catch(
159+
(error) => {
160+
console.warn('failed fetching data', error);
161+
return [];
162+
},
163+
);
160164
}
161165

162166
export function importCDC({ locations, auth }: { locations: string; auth?: string }): Promise<DataGroup | null> {
@@ -182,17 +186,20 @@ export function importCOVIDcast({
182186
}: {
183187
data_source: string;
184188
signal: string;
185-
time_type?: 'day';
189+
time_type?: string;
186190
geo_type: string;
187191
geo_value: string;
188192
}): Promise<DataGroup | null> {
189-
const title = `[API] Delphi CODIDcast: ${geo_value} ${signal} (${data_source})`;
193+
const title = `[API] COVIDcast: ${data_source}:${signal} (${geo_type}:${geo_value})`;
190194
return loadDataSet(
191195
title,
192196
'covidcast',
193197
{
194-
time_type: 'day',
195-
time_values: epiRange(firstDate.covidcast, currentDate),
198+
time_type: time_type,
199+
time_values:
200+
time_type === 'day'
201+
? epiRange(firstDate.covidcast, currentDate)
202+
: epiRange(firstEpiWeek.covidcast, currentEpiWeek),
196203
},
197204
{ data_source, signal, time_type, geo_type, geo_value },
198205
['value', 'stderr', 'sample_size'],

src/components/dialogs/dataSources/COVIDcast.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@
4747
});
4848
4949
export function importDataSet() {
50-
return importCOVIDcast({ data_source, signal, geo_type, geo_value });
50+
return fetchCOVIDcastMeta().then((res) => {
51+
const meta = res.filter((row) => row.data_source === data_source && row.signal === signal);
52+
const time_type = meta[0].time_type;
53+
return importCOVIDcast({ data_source, signal, geo_type, geo_value, time_type });
54+
});
5155
}
5256
</script>
5357

src/data/data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ export const firstEpiWeek = {
385385
quidel: 201535,
386386
sensors: 201030,
387387
nowcast: 200901,
388+
covidcast: 202001,
388389
};
389390

390391
// first available date for each data source

src/deriveLinkDefaults.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,21 @@ export function initialLoader(datasets: ILinkConfig['datasets']) {
158158
return Promise.all(resolvedDataSets).then((data) => {
159159
const cleaned = data.filter((d): d is DataSet => d != null);
160160
cleaned.forEach((d) => {
161-
if (d.params && !Array.isArray(d.params) && d.params._endpoint && d.params.regions) {
162-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
163-
d.title = `${d.params._endpoint} | ${d.params.regions} | ${d.title}`;
161+
if (d.params && !Array.isArray(d.params) && d.params._endpoint) {
162+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
163+
const col_name = d.title;
164+
d.title = `${d.params._endpoint}`;
165+
if (d.params.data_source && d.params.signal) {
166+
d.title += ` > ${d.params.data_source}:${d.params.signal}`;
167+
}
168+
if (d.params.geo_type && d.params.geo_value) {
169+
d.title += ` > ${d.params.geo_type}:${d.params.geo_value}`;
170+
}
171+
if (d.params.regions) {
172+
d.title += ` > ${d.params.regions}`;
173+
}
174+
d.title += ` > ${col_name}`;
175+
/* eslint-enable @typescript-eslint/restrict-template-expressions */
164176
}
165177
add(d);
166178
});

0 commit comments

Comments
 (0)