Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling for URL-based signals & support COVIDcast EpiWeeks #53

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 16 additions & 9 deletions src/api/EpiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@ export function loadDataSet(
});
}

export function fetchCOVIDcastMeta(): Promise<{ geo_type: string; signal: string; data_source: string }[]> {
export function fetchCOVIDcastMeta(): Promise<
{ geo_type: string; signal: string; data_source: string; time_type?: string }[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this filled in by your IDE because you use the .time_type member accessed in COVIDcast.svelte?

Why is the time_type marked "optional" with the question mark modifier? Is that just inherited from the importCOVIDcast() call signature definition? Or is it because the argument has a default value for time_type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this filled in by your IDE because you use the .time_type member accessed in COVIDcast.svelte?

yes!

Was this filled in by your IDE because you use the .time_type member accessed in COVIDcast.svelte? Why is the time_type marked "optional" with the question mark modifier? Is that just inherited from the importCOVIDcast() call signature definition? Or is it because the argument has a default value for time_type?

Just inherited from that call.

> {
const url = new URL(ENDPOINT + `/covidcast_meta/`);
url.searchParams.set('format', 'json');
return fetchImpl<{ geo_type: string; signal: string; data_source: string }[]>(url).catch((error) => {
console.warn('failed fetching data', error);
return [];
});
return fetchImpl<{ geo_type: string; signal: string; data_source: string; time_type?: string }[]>(url).catch(
(error) => {
console.warn('failed fetching data', error);
return [];
},
);
}

export function importCDC({ locations, auth }: { locations: string; auth?: string }): Promise<DataGroup | null> {
Expand All @@ -182,17 +186,20 @@ export function importCOVIDcast({
}: {
data_source: string;
signal: string;
time_type?: 'day';
time_type?: string;
geo_type: string;
geo_value: string;
}): Promise<DataGroup | null> {
const title = `[API] Delphi CODIDcast: ${geo_value} ${signal} (${data_source})`;
const title = `[API] COVIDcast: ${data_source}:${signal} (${geo_type}:${geo_value})`;
return loadDataSet(
title,
'covidcast',
{
time_type: 'day',
time_values: epiRange(firstDate.covidcast, currentDate),
time_type: time_type,
time_values:
time_type === 'day'
? epiRange(firstDate.covidcast, currentDate)
: epiRange(firstEpiWeek.covidcast, currentEpiWeek),
},
{ data_source, signal, time_type, geo_type, geo_value },
['value', 'stderr', 'sample_size'],
Expand Down
6 changes: 5 additions & 1 deletion src/components/dialogs/dataSources/COVIDcast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
});

export function importDataSet() {
return importCOVIDcast({ data_source, signal, geo_type, geo_value });
return fetchCOVIDcastMeta().then((res) => {
const meta = res.filter((row) => row.data_source === data_source && row.signal === signal);
const time_type = meta[0].time_type;
return importCOVIDcast({ data_source, signal, geo_type, geo_value, time_type });
});
}
</script>

Expand Down
1 change: 1 addition & 0 deletions src/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export const firstEpiWeek = {
quidel: 201535,
sensors: 201030,
nowcast: 200901,
covidcast: 202001,
};

// first available date for each data source
Expand Down
18 changes: 15 additions & 3 deletions src/deriveLinkDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,21 @@ export function initialLoader(datasets: ILinkConfig['datasets']) {
return Promise.all(resolvedDataSets).then((data) => {
const cleaned = data.filter((d): d is DataSet => d != null);
cleaned.forEach((d) => {
if (d.params && !Array.isArray(d.params) && d.params._endpoint && d.params.regions) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
d.title = `${d.params._endpoint} | ${d.params.regions} | ${d.title}`;
if (d.params && !Array.isArray(d.params) && d.params._endpoint) {
melange396 marked this conversation as resolved.
Show resolved Hide resolved
/* eslint-disable @typescript-eslint/restrict-template-expressions */
const col_name = d.title;
d.title = `${d.params._endpoint}`;
if (d.params.data_source && d.params.signal) {
d.title += ` > ${d.params.data_source}:${d.params.signal}`;
}
if (d.params.geo_type && d.params.geo_value) {
d.title += ` > ${d.params.geo_type}:${d.params.geo_value}`;
}
if (d.params.regions) {
d.title += ` > ${d.params.regions}`;
}
d.title += ` > ${col_name}`;
/* eslint-enable @typescript-eslint/restrict-template-expressions */
}
add(d);
});
Expand Down