diff --git a/src/components/dialogs/ImportAPIDialog.svelte b/src/components/dialogs/ImportAPIDialog.svelte index 121130e..08fe4b8 100644 --- a/src/components/dialogs/ImportAPIDialog.svelte +++ b/src/components/dialogs/ImportAPIDialog.svelte @@ -21,27 +21,12 @@ import CoviDcast from './dataSources/COVIDcast.svelte'; import { navMode, storeApiKeys } from '../../store'; import { NavMode } from '../chartUtils'; + import { formSelections } from '../../store'; const dispatch = createEventDispatcher(); const id = randomId(); - let dataSource: - | 'fluview' - | 'flusurv' - | 'gft' - | 'ght' - | 'twitter' - | 'wiki' - | 'cdc' - | 'quidel' - | 'nidss_flu' - | 'nidss_dengue' - | 'sensors' - | 'nowcast' - | 'covidcast' - | 'covid_hosp' = 'fluview'; - let loading = false; let handler: unknown = null; @@ -71,47 +56,89 @@
Data Source
+ FluSurv (source: + cdc.gov) + Google Flu Trends (source: google.com) + Google Health Trends (source: private Google API) + CDC Page Hits (source: private CDC dataset) Quidel Data (source: private Quidel dataset) delphi.cmu.edu) + Delphi Sensors (source: delphi.cmu.edu) + Delphi Nowcast (source: delphi.cmu.edu) + Delphi COVIDcast (source: delphi.cmu.edu)
- {#if dataSource === 'fluview'} + {#if $formSelections.dataSource === 'fluview'} - {:else if dataSource === 'flusurv'} + {:else if $formSelections.dataSource === 'flusurv'} - {:else if dataSource === 'gft'} + {:else if $formSelections.dataSource === 'gft'} - {:else if dataSource === 'ght'} + {:else if $formSelections.dataSource === 'ght'} - {:else if dataSource === 'twitter'} + {:else if $formSelections.dataSource === 'twitter'} - {:else if dataSource === 'wiki'} + {:else if $formSelections.dataSource === 'wiki'} - {:else if dataSource === 'quidel'} + {:else if $formSelections.dataSource === 'quidel'} - {:else if dataSource === 'nidss_dengue'} + {:else if $formSelections.dataSource === 'nidss_dengue'} - {:else if dataSource === 'nidss_flu'} + {:else if $formSelections.dataSource === 'nidss_flu'} - {:else if dataSource === 'cdc'} + {:else if $formSelections.dataSource === 'cdc'} - {:else if dataSource === 'sensors'} + {:else if $formSelections.dataSource === 'sensors'} - {:else if dataSource === 'nowcast'} + {:else if $formSelections.dataSource === 'nowcast'} - {:else if dataSource === 'covid_hosp'} + {:else if $formSelections.dataSource === 'covid_hosp'} - {:else if dataSource === 'covidcast'} + {:else if $formSelections.dataSource === 'covidcast'} {/if} diff --git a/src/components/dialogs/dataSources/CDC.svelte b/src/components/dialogs/dataSources/CDC.svelte index ace1d29..89ac684 100644 --- a/src/components/dialogs/dataSources/CDC.svelte +++ b/src/components/dialogs/dataSources/CDC.svelte @@ -3,14 +3,12 @@ import { cdcLocations as regions } from '../../../data/data'; import SelectField from '../inputs/SelectField.svelte'; import TextField from '../inputs/TextField.svelte'; - import { apiKey } from '../../../store'; + import { apiKey, formSelections } from '../../../store'; export let id: string; - let locations = regions[0].value; - export function importDataSet() { - return importCDC({ locations, auth: $apiKey }); + return importCDC({ locations: $formSelections.cdc.locations, auth: $apiKey }); } @@ -21,4 +19,4 @@ bind:value={$apiKey} placeholder="authorization token" /> - + diff --git a/src/components/dialogs/dataSources/COVIDHosp.svelte b/src/components/dialogs/dataSources/COVIDHosp.svelte index b3c5fac..0393274 100644 --- a/src/components/dialogs/dataSources/COVIDHosp.svelte +++ b/src/components/dialogs/dataSources/COVIDHosp.svelte @@ -3,17 +3,14 @@ import { covidHospLocations as regions } from '../../../data/data'; import SelectField from '../inputs/SelectField.svelte'; import SelectIssue from '../inputs/SelectIssue.svelte'; - import { DEFAULT_ISSUE } from '../utils'; + import { formSelections } from '../../../store'; export let id: string; - let states = regions[0].value; - let issue = DEFAULT_ISSUE; - export function importDataSet() { - return importCOVIDHosp({ states, ...issue }); + return importCOVIDHosp({ states: $formSelections.covidHosp.states, ...$formSelections.covidHosp.issue }); } - - + + diff --git a/src/components/dialogs/dataSources/COVIDcast.svelte b/src/components/dialogs/dataSources/COVIDcast.svelte index 9da4bef..20199ea 100644 --- a/src/components/dialogs/dataSources/COVIDcast.svelte +++ b/src/components/dialogs/dataSources/COVIDcast.svelte @@ -4,14 +4,13 @@ import type { LabelValue } from '../../../data/data'; import SelectField from '../inputs/SelectField.svelte'; import TextField from '../inputs/TextField.svelte'; - import { apiKey } from '../../../store'; + import { apiKey, formSelections } from '../../../store'; export let id: string; - - let data_source = ''; - let signal = ''; - let geo_type = ''; - let geo_value = ''; + let data_source = $formSelections.covidcast.dataSource; + let signal = $formSelections.covidcast.signal; + let geo_type = $formSelections.covidcast.geoType; + let geo_value = $formSelections.covidcast.geoValue; let valid_key = true; let dataSources: (LabelValue & { signals: string[] })[] = []; @@ -20,8 +19,9 @@ $: dataSignals = (dataSources.find((d) => d.value === data_source) || { signals: [] }).signals; $: { - if (data_source) { - signal = ''; + if ($formSelections.covidcast.dataSource) { + dataSignals = (dataSources.find((d) => d.value === $formSelections.covidcast.dataSource) || { signals: [] }) + .signals; } } @@ -95,13 +95,31 @@ {/if} - - - + + + diff --git a/src/components/dialogs/dataSources/FluSurv.svelte b/src/components/dialogs/dataSources/FluSurv.svelte index cf6c27b..d3d03ed 100644 --- a/src/components/dialogs/dataSources/FluSurv.svelte +++ b/src/components/dialogs/dataSources/FluSurv.svelte @@ -4,17 +4,14 @@ import { fluSurvRegions as regions } from '../../../data/data'; import SelectField from '../inputs/SelectField.svelte'; import SelectIssue from '../inputs/SelectIssue.svelte'; - import { DEFAULT_ISSUE } from '../utils'; + import { formSelections } from '../../../store'; export let id: string; - let locations = regions[0].value; - let issue = DEFAULT_ISSUE; - export function importDataSet() { - return importFluSurv({ locations, ...issue }); + return importFluSurv({ locations: $formSelections.fluSurv.locations, ...$formSelections.fluSurv.issue }); } - - + + diff --git a/src/components/dialogs/dataSources/FluView.svelte b/src/components/dialogs/dataSources/FluView.svelte index 3fc4cad..caf90d5 100644 --- a/src/components/dialogs/dataSources/FluView.svelte +++ b/src/components/dialogs/dataSources/FluView.svelte @@ -1,24 +1,24 @@ - - + + - + diff --git a/src/components/dialogs/dataSources/GHT.svelte b/src/components/dialogs/dataSources/GHT.svelte index b0f12f7..d599dae 100644 --- a/src/components/dialogs/dataSources/GHT.svelte +++ b/src/components/dialogs/dataSources/GHT.svelte @@ -1,17 +1,14 @@ @@ -22,5 +19,5 @@ bind:value={$apiKey} placeholder="authorization token" /> - - + + diff --git a/src/components/dialogs/dataSources/NIDSSDengue.svelte b/src/components/dialogs/dataSources/NIDSSDengue.svelte index 4797946..46f4235 100644 --- a/src/components/dialogs/dataSources/NIDSSDengue.svelte +++ b/src/components/dialogs/dataSources/NIDSSDengue.svelte @@ -2,14 +2,13 @@ import { importNIDSSDengue } from '../../../api/EpiData'; import { nidssDengueLocations as regions } from '../../../data/data'; import SelectField from '../inputs/SelectField.svelte'; + import { formSelections } from '../../../store'; export let id: string; - let locations = regions[0].value; - export function importDataSet() { - return importNIDSSDengue({ locations }); + return importNIDSSDengue({ locations: $formSelections.nidssDengue.locations }); } - + diff --git a/src/components/dialogs/dataSources/NIDSSFlu.svelte b/src/components/dialogs/dataSources/NIDSSFlu.svelte index 72b9069..69052c5 100644 --- a/src/components/dialogs/dataSources/NIDSSFlu.svelte +++ b/src/components/dialogs/dataSources/NIDSSFlu.svelte @@ -3,17 +3,14 @@ import { nidssFluLocations as regions } from '../../../data/data'; import SelectField from '../inputs/SelectField.svelte'; import SelectIssue from '../inputs/SelectIssue.svelte'; - import { DEFAULT_ISSUE } from '../utils'; + import { formSelections } from '../../../store'; export let id: string; - let locations = regions[0].value; - let issue = DEFAULT_ISSUE; - export function importDataSet() { - return importNIDSSFlu({ regions: locations, ...issue }); + return importNIDSSFlu({ regions: $formSelections.nidssFlu.locations, ...$formSelections.nidssFlu.issue }); } - - + + diff --git a/src/components/dialogs/dataSources/Nowcast.svelte b/src/components/dialogs/dataSources/Nowcast.svelte index 0dfa662..a904fe5 100644 --- a/src/components/dialogs/dataSources/Nowcast.svelte +++ b/src/components/dialogs/dataSources/Nowcast.svelte @@ -2,14 +2,13 @@ import { importNowcast } from '../../../api/EpiData'; import { nowcastLocations as regions } from '../../../data/data'; import SelectField from '../inputs/SelectField.svelte'; + import { formSelections } from '../../../store'; export let id: string; - let locations = regions[0].value; - export function importDataSet() { - return importNowcast({ locations }); + return importNowcast({ locations: $formSelections.nowcast.locations }); } - + diff --git a/src/components/dialogs/dataSources/Quidel.svelte b/src/components/dialogs/dataSources/Quidel.svelte index f4b8ebf..c63b6d8 100644 --- a/src/components/dialogs/dataSources/Quidel.svelte +++ b/src/components/dialogs/dataSources/Quidel.svelte @@ -1,16 +1,14 @@ @@ -21,4 +19,4 @@ bind:value={$apiKey} placeholder="authorization token" /> - + diff --git a/src/components/dialogs/dataSources/Sensors.svelte b/src/components/dialogs/dataSources/Sensors.svelte index 0a577ce..13729cd 100644 --- a/src/components/dialogs/dataSources/Sensors.svelte +++ b/src/components/dialogs/dataSources/Sensors.svelte @@ -1,17 +1,18 @@ @@ -22,5 +23,5 @@ bind:value={$apiKey} placeholder="authorization token" /> - - + + diff --git a/src/components/dialogs/dataSources/Twitter.svelte b/src/components/dialogs/dataSources/Twitter.svelte index 950c58e..ce9ab48 100644 --- a/src/components/dialogs/dataSources/Twitter.svelte +++ b/src/components/dialogs/dataSources/Twitter.svelte @@ -1,17 +1,18 @@ @@ -22,13 +23,27 @@ bind:value={$apiKey} placeholder="authorization token" /> - +
Temporal Resolution
- Daily +
diff --git a/src/components/dialogs/dataSources/Wiki.svelte b/src/components/dialogs/dataSources/Wiki.svelte index c00dc4c..64da12a 100644 --- a/src/components/dialogs/dataSources/Wiki.svelte +++ b/src/components/dialogs/dataSources/Wiki.svelte @@ -2,15 +2,10 @@ import { importWiki } from '../../../api/EpiData'; import { wikiArticles } from '../../../data/data'; import SelectField from '../inputs/SelectField.svelte'; + import { formSelections } from '../../../store'; export let id: string; - let articles = wikiArticles[0].value; - let resolution: 'daily' | 'weekly' = 'daily'; - let hour = 0; - let useHour = false; - let language = 'en'; - const languages = [ { value: 'en', @@ -19,29 +14,63 @@ ]; export function importDataSet() { - return importWiki({ articles, resolution, hour: useHour ? hour : null, language }); + return importWiki({ + articles: $formSelections.wiki.articles, + resolution: $formSelections.wiki.resolution, + hour: $formSelections.wiki.useHour ? $formSelections.wiki.hour : null, + language: $formSelections.wiki.language, + }); } - +
Temporal Resolution
- Daily +
Specific Hour (filter by + hour else return sum: 0-23, timezone is UTC)
- +
- + diff --git a/src/components/dialogs/formSelections.ts b/src/components/dialogs/formSelections.ts new file mode 100644 index 0000000..c030af9 --- /dev/null +++ b/src/components/dialogs/formSelections.ts @@ -0,0 +1,123 @@ +import { + cdcLocations, + covidHospLocations, + fluSurvRegions, + fluViewRegions, + gftLocations, + ghtLocations, + nidssDengueLocations, + nidssFluLocations, + nowcastLocations, + quidelLocations, + sensorLocations, + sensorNames, + twitterLocations, + wikiArticles, +} from '../../data/data'; +import { DEFAULT_ISSUE } from './utils'; + +// The following classes define default values for the various "data source" forms, and will store modifications to those values as the user interacts with the forms. + +export class CdcSelections { + locations = cdcLocations[0].value; +} + +export class CovidcastSelections { + dataSource = ''; + signal = ''; + geoType = ''; + geoValue = ''; +} + +export class CovidHospSelections { + states = covidHospLocations[0].value; + issue = DEFAULT_ISSUE; +} + +export class FluSurvSelections { + locations = fluSurvRegions[0].value; + issue = DEFAULT_ISSUE; +} + +export class FluViewSelections { + locations = fluViewRegions[0].value; + issue = DEFAULT_ISSUE; +} + +export class GftSelections { + locations = gftLocations[0].value; +} + +export class GhtSelections { + locations = ghtLocations[0].value; + query = ''; +} + +export class NidssDengueSelections { + locations = nidssDengueLocations[0].value; +} + +export class NidssFluSelections { + locations = nidssFluLocations[0].value; + issue = DEFAULT_ISSUE; +} + +export class NowcastSelections { + locations = nowcastLocations[0].value; +} + +export class QuidelSelections { + locations = quidelLocations[0].value; +} + +export class SensorSelections { + locations = sensorLocations[0].value; + names = sensorNames[0].value; +} + +export class TwitterSelections { + locations = twitterLocations[0].value; + resolution: 'daily' | 'weekly' = 'daily'; +} + +export class WikiSelections { + articles = wikiArticles[0].value; + resolution: 'daily' | 'weekly' = 'daily'; + hour = 0; + useHour = false; + language = 'en'; +} + +// The FormSelections class defines the default form choice, stores changes to that choice, and holds references to the values used in each "data source" form. + +export default class FormSelections { + dataSource: + | 'fluview' + | 'flusurv' + | 'gft' + | 'ght' + | 'twitter' + | 'wiki' + | 'cdc' + | 'quidel' + | 'nidss_flu' + | 'nidss_dengue' + | 'sensors' + | 'nowcast' + | 'covidcast' + | 'covid_hosp' = 'fluview'; + cdc = new CdcSelections(); + covidcast = new CovidcastSelections(); + covidHosp = new CovidHospSelections(); + fluSurv = new FluSurvSelections(); + fluView = new FluViewSelections(); + gft = new GftSelections(); + ght = new GhtSelections(); + nidssDengue = new NidssDengueSelections(); + nidssFlu = new NidssFluSelections(); + nowcast = new NowcastSelections(); + quidel = new QuidelSelections(); + sensors = new SensorSelections(); + twitter = new TwitterSelections(); + wiki = new WikiSelections(); +} diff --git a/src/store.ts b/src/store.ts index 9ea8339..397ffb1 100644 --- a/src/store.ts +++ b/src/store.ts @@ -2,6 +2,7 @@ import { get, writable } from 'svelte/store'; import { NavMode } from './components/chartUtils'; import DataSet, { DataGroup } from './data/DataSet'; import deriveLinkDefaults, { getDirectLinkImpl } from './deriveLinkDefaults'; +import FormSelections from './components/dialogs/formSelections'; declare const __VERSION__: string; @@ -17,6 +18,23 @@ export const isShowingPoints = writable(defaults.showPoints); export const initialViewport = writable(defaults.viewport); export const navMode = writable(NavMode.autofit); +export function getFormSelections() { + try { + if (sessionStorage.getItem('form')) { + return JSON.parse(sessionStorage.getItem('form')!) as FormSelections; + } + } catch { + // we are probably here because parsing failed, so remove bad JSON from sessionStorage + sessionStorage.removeItem('form'); + } + return new FormSelections(); +} + +export const formSelections = writable(getFormSelections()); +formSelections.subscribe((val) => { + sessionStorage.setItem('form', JSON.stringify(val)); +}); + export const storeApiKeys = writable(localStorage.getItem('store-api-key') === 'true'); storeApiKeys.subscribe((val) => { localStorage.setItem('store-api-key', val.toString());