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 5 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
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/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
36 changes: 30 additions & 6 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 { formatDateISO } from '../../formats';
import { currentMode } from '../../stores';
import AboutSection from '../../components/AboutSection.svelte';

/**
* @type {import('../../stores/params').SensorParam}
* @type {import("../stores/params").DateParam}
Copy link
Contributor

@dshemetov dshemetov Jun 21, 2024

Choose a reason for hiding this comment

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

Is the path here off? It was ../.. before? Same for the two imports below.

*/
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);
function setExportMode() {
// 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={`../export/?${exportURL}`} on:click={setExportMode}>Export Data</a>
</li>
</ul>
{/if}
Expand Down
Loading