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

OKRS-24-55 #1243

Merged
Merged
Show file tree
Hide file tree
Changes from 11 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
9 changes: 7 additions & 2 deletions src/blocks/IndicatorWarning.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@
<div data-uk-alert class="uk-alert-warning">
The indicator "{sensor.name}" is not available for {formatDateYearDayOfWeekAbbr(date.value)}, yet. The latest
known data is available on
<a href="?date={formatAPITime(sensor.timeFrame.max)}" on:click={switchDate}
>{formatDateYearDayOfWeekAbbr(sensor.timeFrame.max)}</a
<!--
window.location.search.split('&').slice(1).join('&') is used to keep the query parameters except the date parameter.
So we are getting query params from url, splitting them by & and removing the first element which is date parameter.
-->
<a
href="?date={formatAPITime(sensor.timeFrame.max)}&{window.location.search.split('&').slice(1).join('&')}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file still used anywhere? It looks like it has been replaced by your new NoRecentDataWarning.svelte...

If we are keeping the file, we should include a comment describing what this split/slice/join operation is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't mean to replace "IndicatorWarning.svelte" by "NoRecentDataWarning.svelte", but I didn't want to change existing "Indicator.svelte" either.
I would prefer to add comment and leave both of them (at least for now).

on:click={switchDate}>{formatDateYearDayOfWeekAbbr(sensor.timeFrame.max)}</a
>.
</div>
{/if}
Expand Down
47 changes: 47 additions & 0 deletions src/blocks/NoRecentDataWarning.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script>
import { formatDateYearDayOfWeekAbbr } from '../formats';
import { formatAPITime } from '../data';
/**
* @type {import("../stores/params").DateParam}
*/
export let minMaxDate;
/**
* @type {import("../stores/params").DateParam}
*/
export let date;

export let warningType;

function switchDate() {
date.set(minMaxDate);
}
</script>

{#if warningType === 1}
<div data-uk-alert class="uk-alert-warning">
<p>
This date {formatDateYearDayOfWeekAbbr(minMaxDate)} is the most recent that has data for all three of the highlighted
dmytrotsko marked this conversation as resolved.
Show resolved Hide resolved
indicators. You can mouse over the tooltips just below this message to see the latest available date for each indicator.
Note that the latest available date may be different for each indicator.
</p>
</div>
{/if}

{#if warningType === 2}
<div data-uk-alert class="uk-alert-warning">
<p>
This date {formatDateYearDayOfWeekAbbr(date.value)} does not yet have data for all of the highlighted indicators.
dmytrotsko marked this conversation as resolved.
Show resolved Hide resolved
<br />
<!--
window.location.search.split('&').slice(1).join('&') is used to keep the query parameters except the date parameter.
So we are getting query params from url, splitting them by & and removing the first element which is date parameter.
-->
<a
href="?date={formatAPITime(minMaxDate)}&{window.location.search.split('&').slice(1).join('&')}"
on:click={switchDate}>{formatDateYearDayOfWeekAbbr(minMaxDate)}</a
>
is the most recent that has data for all three. You can mouse over the tooltips just below this message to see the
latest available date for each indicator. Note that the latest available date may be different for each indicator.
</p>
</div>
{/if}
88 changes: 55 additions & 33 deletions src/modes/summary/Overview.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<script>
import KPIValue from '../../components/KPIValue.svelte';
import KPIChange from '../../components/KPIChange.svelte';
import { DateParam, SensorParam } from '../../stores/params';
import { formatDateDayOfWeek } from '../../formats';
import { SensorParam } from '../../stores/params';
import SensorUnit from '../../components/SensorUnit.svelte';
import IndicatorAnnotations from '../../components/IndicatorAnnotations.svelte';
import MaxDateHint from '../../blocks/MaxDateHint.svelte';
import IndicatorWarning from '../../blocks/IndicatorWarning.svelte';
import NoRecentDataWarning from '../../blocks/NoRecentDataWarning.svelte';
melange396 marked this conversation as resolved.
Show resolved Hide resolved
import { defaultDeathSensor, defaultCasesSensor, defaultHospitalSensor, metaDataManager } from '../../stores';
import IndicatorFallbackWarning from '../../blocks/IndicatorFallbackWarning.svelte';
import { onMount, beforeUpdate } from 'svelte';

/**
* @type {import("../../stores/params").DateParam}
Expand All @@ -27,33 +25,56 @@
$: DEATHS = new SensorParam($defaultDeathSensor, $metaDataManager);
$: HOSPITAL_ADMISSION = new SensorParam($defaultHospitalSensor, $metaDataManager);

function fetchFallback(fetcher, sensor, region, trend) {
return trend.then((t) => {
if (t && t.value != null) {
return t;
}
return fetcher.fetch1Sensor1Region1DateTrend(sensor, region, DateParam.box(sensor.timeFrame.max));
});
}

$: trends = fetcher.fetchNSensors1Region1DateTrend([CASES, HOSPITAL_ADMISSION, DEATHS], region, date);
$: casesTrend = trends[0];
$: hospitalTrend = fetchFallback(fetcher, HOSPITAL_ADMISSION, region, trends[1]);
$: hospitalTrend = trends[1];
melange396 marked this conversation as resolved.
Show resolved Hide resolved
$: deathTrend = trends[2];
</script>

<IndicatorWarning sensor={CASES} {date} {region} {fetcher} />
<IndicatorAnnotations {date} {region} sensor={CASES} range="sparkLine" />
let minMaxDate = new Date();

onMount(() => {
[CASES, HOSPITAL_ADMISSION].map((s) => {
if (s.timeFrame.max < minMaxDate) {
minMaxDate = s.timeFrame.max;
}
});
let urlSearchParams = new URLSearchParams(window.location.search);
if (!urlSearchParams.has('date')) {
// if no date is specified in the URL, default to the latest day before today with data from all 3 highlighted indicators
date.set(minMaxDate);
dmytrotsko marked this conversation as resolved.
Show resolved Hide resolved
}
});

// warningType is indicator of which exact warning message should be shown.
// By default, when user opens page with no specified date, the date will be set to the latest date we have data for all 3 indicators.
// In this case, warningType should be set to 1.
// In case selected date is set to future date (date > minMaxDate, where we don't have recent data for all 3 indicators), the warningType will be set to 2
// which has different warning message.
// In case selected date is set to some date which is < minMaxDate, the warningType will be set to 0 which means that we will not show
// any warning message.

// warningType should be set in beforeUpdate() method, to guess correct warningType.

let warningType = 1;
beforeUpdate(() => {
if (date.value > minMaxDate) {
warningType = 2;
} else if (date.value < minMaxDate) {
warningType = 0;
} else {
warningType = 1;
}
});
Comment on lines +48 to +67
Copy link
Contributor

Choose a reason for hiding this comment

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

can we do the date.value != minMaxDate comparisons inside NoRecentDataWarning.svelte? That way we wouldn't have to pass warningType... Or do we need to do the comparisons inside of the beforeUpdate() event here?

Copy link
Contributor

Choose a reason for hiding this comment

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

i talked to Dmytro on slack, he is going to look at this but we will release the current state in the meantime as the functionality is doing what its supposed to.

</script>

<p>
On {formatDateDayOfWeek(date.value)}
<MaxDateHint sensor={CASES.value} suffix="," {fetcher} />
the {CASES.valueUnit}s were:
</p>
<NoRecentDataWarning {minMaxDate} {date} {warningType} />

<div class="mobile-three-col">
<div class="mobile-kpi">
<h3>Doctor Visits</h3>
<h3>
Doctor Visits
<MaxDateHint sensor={CASES.value} {fetcher} />
</h3>
<div>
{#await casesTrend}
<KPIValue value={null} loading />
Expand All @@ -66,20 +87,26 @@
</div>
</div>
<div class="mobile-kpi">
<h3>Hospital Admissions</h3>
<h3>
Hospital Admissions
<MaxDateHint sensor={HOSPITAL_ADMISSION.value} {fetcher} />
</h3>
<div>
{#await hospitalTrend}
<KPIValue value={null} loading />
{:then d}
<KPIValue value={d ? d.value : null} asterisk={d != null && (d.value == null || d.date < date.value)} />
<KPIValue value={d ? d.value : null} />
{/await}
</div>
<div class="sub">
<SensorUnit sensor={HOSPITAL_ADMISSION} long />
</div>
</div>
<div class="mobile-kpi">
<h3>Deaths</h3>
<h3>
Deaths
<MaxDateHint sensor={DEATHS.value} {fetcher} />
</h3>
<div>
{#await deathTrend}
<KPIValue value={null} loading />
Expand Down Expand Up @@ -111,10 +138,7 @@
{#await hospitalTrend}
<KPIChange value={null} loading />
{:then d}
<KPIChange
value={d && d.value != null && !Number.isNaN(d.value) ? d.change : null}
asterisk={d != null && (d.value == null || d.date < date.value)}
/>
<KPIChange value={d && d.value != null && !Number.isNaN(d.value) ? d.change : null} />
{/await}
</div>
<div class="sub">Relative change to 7 days ago</div>
Expand All @@ -130,5 +154,3 @@
<div class="sub">Relative change to 7 days ago</div>
</div>
</div>

<IndicatorFallbackWarning trend={hospitalTrend} date={date.value} level={region.level} sensor={HOSPITAL_ADMISSION} />
5 changes: 1 addition & 4 deletions src/modes/summary/Summary.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import IndicatorTable from './IndicatorTable.svelte';
// TEMPORARY DISABLING OF THIS OVERVIEW WIDGET UNTIL SIGNALS ARE FIXED:
// import Overview from './Overview.svelte';
import Overview from './Overview.svelte';
import { countyInfo, nationInfo, stateInfo } from '../../data/regions';
import RegionDatePicker from '../../components/RegionDatePicker.svelte';
import {
Expand Down Expand Up @@ -71,9 +70,7 @@
<div class="uk-container content-grid">
<div class="grid-3-11">
<FancyHeader invert>{region.displayName}</FancyHeader>
<!-- TEMPORARY DISABLING OF THIS OVERVIEW WIDGET UNTIL SIGNALS ARE FIXED
<Overview {date} {region} {fetcher} />
-->
<hr />
<FancyHeader invert sub="Map" anchor="map">{HOSPITAL_ADMISSION.name}</FancyHeader>
<p>{@html HOSPITAL_ADMISSION.signalTooltip}</p>
Expand Down
Loading