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

Update COVIDcast export integration #1252

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/blocks/HistoryLineChart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
<Toggle bind:checked={singleRaw}>Raw Data</Toggle>
{/if}
<div class="spacer" />
<DownloadMenu {fileName} {vegaRef} {data} {sensor} {raw} {stderr} />
<DownloadMenu {fileName} {vegaRef} {data} {date} {region} {sensor} {raw} {stderr} />
</div>

{#if showAgeStratifications}
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/RegionCountyMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<DownloadMenu
{vegaRef}
{data}
{date}
{region}
{sensor}
absolutePos
fileName="{sensor.name}_US Counties_{formatDateISO(date.value)}"
Expand Down
9 changes: 8 additions & 1 deletion src/blocks/RegionHexMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@
<div>Hex fill color: value at selected date</div>
</div>
<ColorLegend {sensor} level="state" gradientLength={$isMobileDevice ? 250 : 280}>
<DownloadMenu fileName="{sensor.name}_US_States_{formatDateISO(date.value)}" data={dumpData} absolutePos {sensor} />
<DownloadMenu
fileName="{sensor.name}_US_States_{formatDateISO(date.value)}"
data={dumpData}
absolutePos
{date}
{region}
{sensor}
/>
</ColorLegend>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/RegionMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
on:click={onClickHandler}
eventListeners={['click']}
/>
<DownloadMenu {vegaRef} {data} {sensor} absolutePos {fileName} />
<DownloadMenu {vegaRef} {data} {date} {region} {sensor} absolutePos {fileName} />
</div>
</FullWidthWrapper>

Expand Down
32 changes: 28 additions & 4 deletions src/components/DownloadMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { downloadUrl, scrollToTop } from '../util';
import { downloadUrl } from '../util';
import { csvFormat } from 'd3-dsv';
import { formatDateISO } from '../formats';
import { modeByID } from '../modes';
Expand All @@ -13,6 +13,14 @@

export let data = null;

/**
* @type {import("../stores/params").DateParam}
*/
export let date = null;
/**
* @type {import("../stores/params").RegionParam}
*/
export let region = null;
/**
* @type {import("../stores/params").SensorParam}
*/
Expand Down Expand Up @@ -112,8 +120,24 @@
function exportData() {
// switch to export mode
currentMode.set(modeByID.export);
sensor.set(sensor.value, true);
scrollToTop();
}

let exportURL = '';
$: {
exportURL = '';
if (sensor && sensor.key.split('-').length >= 2) {
// Given a sensor key formatted "sensor-name-here-signal_name_here", split on the last dash
let [last, ...rest] = sensor.key.split('-').reverse();
rest = rest.reverse().join('-');
exportURL += `data_source=${rest}&signal=${last}`;

if (region) {
exportURL += `&geo_type=${region.level}&geo_value=${region.propertyId}`;
}
if (date) {
exportURL += `&start_day=${formatDateISO(date.value)}&end_day=${formatDateISO(date.value)}`;
}
}
}
</script>

Expand All @@ -140,7 +164,7 @@
{#if advanced}
<li class="uk-nav-divider" />
<li>
<a href="../{modeByID.export.id}" on:click|preventDefault={exportData}>Advanced Data Export</a>
<a href={`../${modeByID.export.id}/?${exportURL}`} on:click={exportData}>Advanced Data Export</a>
</li>
{/if}
</ul>
Expand Down
10 changes: 8 additions & 2 deletions src/modes/exportdata/ExportData.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
startDate = urlParams.has('start_day') ? new Date(urlParams.get('start_day')) : param.sparkLineTimeFrame.min;
endDate = urlParams.has('end_day') ? new Date(urlParams.get('end_day')) : param.sparkLineTimeFrame.max;

// Also normalize the dates to the current timezone
// Normalize the datest to the current timezone by *subtracting* the timezone
// offset (to account for negative timezones), multiplied by 60000 (minutes -> ms)
startDate = new Date(startDate.getTime() - startDate.getTimezoneOffset() * -60000);
endDate = new Date(endDate.getTime() - endDate.getTimezoneOffset() * -60000);
}
Expand Down Expand Up @@ -88,7 +89,12 @@

// Populate region based on URL params... but let the user override this later
if (urlParams.has('geo_value') && !geoURLSet) {
let infos = infosByLevel[geoType].filter((d) => d.propertyId == urlParams.get('geo_value'));
let geo_value = urlParams.get('geo_value');
// Allow for lowercase state names e.g. 'ca' -> 'CA'
if (geoType == 'state') {
geo_value = geo_value.toUpperCase();
}
let infos = infosByLevel[geoType].filter((d) => d.propertyId == geo_value);
addRegion(infos[0]);
geoURLSet = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modes/indicator/GeoTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@

<div class="uk-position-relative">
<FancyHeader anchor="table">{title.title}</FancyHeader>
<DownloadMenu {fileName} data={loadedData} absolutePos prepareRow={(row) => row.dump} />
<DownloadMenu {fileName} data={loadedData} absolutePos prepareRow={(row) => row.dump} {date} {region} {sensor} />
<p class="uk-text-center uk-text-italic ux-hint">
<span class="inline-svg-icon">
{@html mousePointerIcon}
Expand Down
2 changes: 1 addition & 1 deletion src/modes/indicator/Indicator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<HistoryLineChart {sensor} {date} {region} {fetcher} />
</div>
</div>
<IndicatorAbout {sensor} />
<IndicatorAbout {sensor} {region} {date} />
<div class="grid-3-11">
<hr />
<GeoTable {sensor} {region} {date} {fetcher} />
Expand Down
34 changes: 29 additions & 5 deletions src/modes/indicator/IndicatorAbout.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
<script>
import { modeByID } from '..';
import { currentMode } from '../../stores';
import { formatDateISO } from '../../formats';
import AboutSection from '../../components/AboutSection.svelte';

/**
* @type {import('../../stores/params').SensorParam}
* @type {import("../../stores/params").DateParam}
*/
export let date;
/**
* @type {import("../../stores/params").RegionParam}
*/
export let region;
/**
* @type {import("../../stores/params").SensorParam}
*/
export let sensor;

function exportData() {
sensor.set(sensor.value);
// switch to export mode
currentMode.set(modeByID.export);
}

let exportURL = '';
$: {
exportURL = '';
if (sensor && sensor.key.split('-').length >= 2) {
// Given a sensor key formatted "sensor-name-here-signal_name_here", split on the last dash
let [last, ...rest] = sensor.key.split('-').reverse();
rest = rest.reverse().join('-');
exportURL += `data_source=${rest}&signal=${last}`;

if (region) {
exportURL += `&geo_type=${region.level}&geo_value=${region.propertyId}`;
}
if (date) {
exportURL += `&start_day=${formatDateISO(date.value)}&end_day=${formatDateISO(date.value)}`;
}
}
}
</script>

{#if sensor.value.description}
Expand All @@ -33,9 +59,7 @@
</li>
{/each}
<li>
<a href={`../${modeByID.export.id}?sensor=${sensor.key}`} on:click|preventDefault={exportData}
>Export Data</a
>
<a href={`../${modeByID.export.id}/?${exportURL}`} on:click={exportData}>Export Data</a>
</li>
</ul>
{/if}
Expand Down
Loading