-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ export function epiRange(from: string | number, to: string | number): string { | |
|
||
// find the current epiweek and date | ||
const date = new Date(); | ||
const epidate = new EpiDate(date.getFullYear() + 1900, date.getMonth() + 1, date.getDate()); | ||
const epidate = new EpiDate(date.getFullYear(), date.getMonth() + 1, date.getDate()); | ||
export const currentEpiWeek = epidate.getEpiYear() * 100 + epidate.getEpiWeek(); | ||
export const currentDate = epidate.getYear() * 10000 + epidate.getMonth() * 100 + epidate.getDay(); | ||
|
||
|
@@ -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 }[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this filled in by your IDE because you use the Why is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes!
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> { | ||
|
@@ -182,18 +186,24 @@ 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] Delphi COVIDcast: ${geo_value} ${signal} (${data_source}) ${time_type}`; | ||
rzats marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.log(epiRange(firstEpiWeek.covidcast, currentEpiWeek)); | ||
rzats marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return loadDataSet( | ||
title, | ||
'covidcast', | ||
{ | ||
time_type: 'day', | ||
time_values: epiRange(firstDate.covidcast, currentDate), | ||
}, | ||
time_type === 'day' | ||
? { | ||
time_type: 'day', | ||
time_values: epiRange(firstDate.covidcast, currentDate), | ||
} | ||
: { | ||
time_type: 'week', | ||
time_values: epiRange(firstEpiWeek.covidcast, currentEpiWeek), | ||
}, | ||
rzats marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ data_source, signal, time_type, geo_type, geo_value }, | ||
['value', 'stderr', 'sample_size'], | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,9 +158,9 @@ 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) { | ||
if (d.params) { | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
d.title = `${d.params._endpoint} | ${d.params.regions} | ${d.title}`; | ||
d.title = `${Object.values(d.params).join(' > ')} > ${d.title}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a definite improvement and works well for now, but i wouldnt call this a full solution for #42 ... It lacks clarity and doesnt reproduce the normal/typical instead of: (lets leave it the way it is for now in this PR and return to it later when other higher-priority PRs are out of the way) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I implemented this now, as it's fairly straightforward to modify the template. lmk what you think! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks great for now. We should keep #42 open to later support reproducing the full form dropdown with value/stderr/sample_size. |
||
} | ||
add(d); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently epivis makes queries with 3924 set as the end year 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that has been a curious artifact. I'm not sure how it slipped through QA, but it has no real ill effect, and it let us track epivis-based requests to the API servers. It looks like it came from an older piece of javascript where it presumably did the right thing (¯\_(ツ)_/¯). I am leaning towards leaving it as-is until #38 is done (especially so we can see the effect in our logs of more eyes on epivis with the signal discovery app's release). Do you have strong feelings either way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is already done by logging the referrer/origin in the delphi-epidata server? https://github.com/cmu-delphi/delphi-epidata/blob/dev/src/server/_common.py#L70-L71
If we want an even more reliable way to track API requests, a cleaner option is to
(a) start logging a certain custom HTTP header (like
Delphi-Api-Origin
) in the logging method I linked above;(b) set that header in EpiVis, and in other apps that we would like to keep track of - like the client, for instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That server logging would do it if, as cmu-delphi/delphi-epidata#1386 (comment) mentions and #38 references, we update the
Referrer-Policy
for epivis. Im not suggesting that adding 1900y is "clean", but can we leave it there for now and note that it should come out with #38?