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

more robust missing meta data handling #653

Merged
merged 2 commits into from
Nov 25, 2020
Merged
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
17 changes: 15 additions & 2 deletions src/components/MapBox/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ const TICK_COUNT = 7;
* @typedef {import('../../stores/constants').SensorEntry} SensorEntry
*/

const DEFAULT_STATS = { min: 0, max: 100, mean: 50, std: 10 };

function resolveStats(statsLookup, key) {
if (!statsLookup || !statsLookup.has(key)) {
return DEFAULT_STATS;
}
const entry = statsLookup.get(key);
if ([entry.max, entry.std, entry.mean].some((d) => d == null || Number.isNaN(d))) {
console.warn('invalid stats detected for', key);
return DEFAULT_STATS;
}
return entry;
}
/**
* @param {*} statsLookup
* @param {SensorEntry} sensorEntry
Expand All @@ -27,7 +40,7 @@ export function determineMinMax(statsLookup, sensorEntry, level, signalOptions,
if (sensorEntry.isCasesOrDeath) {
key += `_${primaryValue(sensorEntry, signalOptions)}`;
}
const stats = statsLookup.get(key);
const stats = resolveStats(statsLookup, key);
if (useMax) {
return [0, stats.max];
}
Expand All @@ -37,7 +50,7 @@ export function determineMinMax(statsLookup, sensorEntry, level, signalOptions,
if (sensorEntry.isCasesOrDeath) {
key += `_${primaryValue(sensorEntry, signalOptions)}`;
}
const stats = statsLookup.get(key);
const stats = resolveStats(statsLookup, key);
if (useMax) {
return [0, stats.max];
}
Expand Down
4 changes: 2 additions & 2 deletions src/modes/exportdata/ExportData.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@
<Datepicker
bind:selected={startDate}
start={source ? source.minTime : new Date()}
end={minDate(endDate, source ? source.maxTime : new Date())}
end={source ? minDate(endDate, source.maxTime) : endDate}
formattedSelected={iso(startDate)}>
<button aria-label="selected start date" class="pg-button" on:>{iso(startDate)}</button>
</Datepicker>
-
<Datepicker
bind:selected={endDate}
start={maxDate(startDate, source ? source.minTime : new Date())}
start={source ? maxDate(startDate, source.minTime) : startDate}
end={source ? source.maxTime : new Date()}
formattedSelected={iso(endDate)}>
<button aria-label="selected end date" class="pg-button" on:>{iso(endDate)}</button>
Expand Down