Skip to content

Commit 6d7ba2c

Browse files
committed
Update COVIDcast export integration
1 parent d98c513 commit 6d7ba2c

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/modes/exportdata/ExportData.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
startDate = urlParams.has('start_day') ? new Date(urlParams.get('start_day')) : param.sparkLineTimeFrame.min;
5656
endDate = urlParams.has('end_day') ? new Date(urlParams.get('end_day')) : param.sparkLineTimeFrame.max;
5757
58-
// Also normalize the dates to the current timezone
58+
// Normalize the datest to the current timezone by *subtracting* the timezone
59+
// offset (to account for negative timezones), multiplied by 60000 (minutes -> ms)
5960
startDate = new Date(startDate.getTime() - startDate.getTimezoneOffset() * -60000);
6061
endDate = new Date(endDate.getTime() - endDate.getTimezoneOffset() * -60000);
6162
}
@@ -88,7 +89,7 @@
8889
8990
// Populate region based on URL params... but let the user override this later
9091
if (urlParams.has('geo_value') && !geoURLSet) {
91-
let infos = infosByLevel[geoType].filter((d) => d.propertyId == urlParams.get('geo_value'));
92+
let infos = infosByLevel[geoType].filter((d) => d.propertyId == urlParams.get('geo_value').toUpperCase());
9293
addRegion(infos[0]);
9394
geoURLSet = true;
9495
}

src/modes/indicator/Indicator.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<HistoryLineChart {sensor} {date} {region} {fetcher} />
9797
</div>
9898
</div>
99-
<IndicatorAbout {sensor} />
99+
<IndicatorAbout {sensor} {region} {date} />
100100
<div class="grid-3-11">
101101
<hr />
102102
<GeoTable {sensor} {region} {date} {fetcher} />

src/modes/indicator/IndicatorAbout.svelte

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<script>
22
import { modeByID } from '..';
3+
import { formatDateISO } from '../../formats';
34
import { currentMode } from '../../stores';
45
import AboutSection from '../../components/AboutSection.svelte';
56
67
/**
7-
* @type {import('../../stores/params').SensorParam}
8+
* @type {import("../stores/params").DateParam}
9+
*/
10+
export let date;
11+
/**
12+
* @type {import("../stores/params").RegionParam}
13+
*/
14+
export let region;
15+
/**
16+
* @type {import("../stores/params").SensorParam}
817
*/
918
export let sensor;
1019
@@ -13,6 +22,24 @@
1322
// switch to export mode
1423
currentMode.set(modeByID.export);
1524
}
25+
26+
function buildExportURL() {
27+
let exportURL = '';
28+
if (sensor.key.split('-').length >= 2) {
29+
// account for dashes in the sensor
30+
let [first, ...rest] = sensor.key.split('-');
31+
rest = rest.join('-');
32+
exportURL += `data_source=${first}&signal=${rest}`;
33+
}
34+
if (region) {
35+
exportURL += `&geo_type=${region.level}&geo_value=${region.propertyId}`;
36+
}
37+
if (date) {
38+
console.log(date);
39+
exportURL += `&start_day=${formatDateISO(date.value)}&end_day=${formatDateISO(date.value)}`;
40+
}
41+
return exportURL;
42+
}
1643
</script>
1744

1845
{#if sensor.value.description}
@@ -33,7 +60,7 @@
3360
</li>
3461
{/each}
3562
<li>
36-
<a href={`../${modeByID.export.id}?sensor=${sensor.key}`} on:click|preventDefault={exportData}
63+
<a href={`../${modeByID.export.id}/?${buildExportURL()}`} on:click|preventDefault={exportData}
3764
>Export Data</a
3865
>
3966
</li>

0 commit comments

Comments
 (0)