hazards only on first run through after load/refresh

sorting of hazards based on type tornado, hurricane, etc

5.13.0
This commit is contained in:
Matt Walsh
2024-10-08 09:52:04 -05:00
parent 019908684b
commit 80a68caa27
6 changed files with 1014 additions and 934 deletions

2
dist/index.html vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1544
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "ws4kp", "name": "ws4kp",
"version": "5.12.0", "version": "5.13.0",
"description": "Welcome to the WeatherStar 4000+ project page!", "description": "Welcome to the WeatherStar 4000+ project page!",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -3,13 +3,19 @@
import STATUS from './status.mjs'; import STATUS from './status.mjs';
import { json } from './utils/fetch.mjs'; import { json } from './utils/fetch.mjs';
import WeatherDisplay from './weatherdisplay.mjs'; import WeatherDisplay from './weatherdisplay.mjs';
import { registerDisplay } from './navigation.mjs'; import { registerDisplay, msg } from './navigation.mjs';
const hazardLevels = { const hazardLevels = {
Extreme: 10, Extreme: 10,
Severe: 5, Severe: 5,
}; };
const hazardModifiers = {
'Hurricane Warning': 2,
'Tornado Warning': 3,
'Severe Thunderstorm Warning': 1,
}
class Hazards extends WeatherDisplay { class Hazards extends WeatherDisplay {
constructor(navId, elemId, defaultActive) { constructor(navId, elemId, defaultActive) {
// special height and width for scrolling // special height and width for scrolling
@@ -34,8 +40,9 @@ class Hazards extends WeatherDisplay {
url.searchParams.append('limit', 5); url.searchParams.append('limit', 5);
const alerts = await json(url, { retryCount: 3, stillWaiting: () => this.stillWaiting() }); const alerts = await json(url, { retryCount: 3, stillWaiting: () => this.stillWaiting() });
const unsortedAlerts = alerts.features ?? []; const unsortedAlerts = alerts.features ?? [];
const sortedAlerts = unsortedAlerts.sort((a, b) => (hazardLevels[b.properties.severity] ?? 0) - (hazardLevels[a.properties.severity] ?? 0)); const hasImmediate = unsortedAlerts.reduce((acc, hazard) => acc || hazard.properties.urgency === 'Immediate', false);
const filteredAlerts = sortedAlerts.filter((hazard) => hazard.properties.severity !== 'Unknown'); const sortedAlerts = unsortedAlerts.sort((a, b) => (calcSeverity(b.properties.severity, b.properties.event)) - (calcSeverity(a.properties.severity, a.properties.event)));
const filteredAlerts = sortedAlerts.filter((hazard) => hazard.properties.severity !== 'Unknown' && (!hasImmediate || (hazard.properties.urgency === 'Immediate')));
this.data = filteredAlerts; this.data = filteredAlerts;
// show alert indicator // show alert indicator
@@ -134,6 +141,25 @@ class Hazards extends WeatherDisplay {
this.getDataCallbacks.push(() => resolve(this.data)); this.getDataCallbacks.push(() => resolve(this.data));
}); });
} }
// after we roll through the hazards once, don't display again until the next refresh (10 minutes)
screenIndexFromBaseCount() {
const superValue = super.screenIndexFromBaseCount();
// false is returned when we reach the end of the scroll
if (superValue === false) {
// set total screens to zero to take this out of the rotation
this.timing.totalScreens = 0;
}
// return the value as expected
return superValue;
}
}
const calcSeverity = (severity, event) => {
// base severity plus some modifiers for specific types of warnings
const baseSeverity = hazardLevels[severity] ?? 0;
const modifiedSeverity = hazardModifiers[event] ?? 0;
return baseSeverity + modifiedSeverity;
} }
// register display // register display

View File

@@ -268,6 +268,8 @@ const getWeatherIconFromIconLink = (link, _isNightTime) => {
case 'tsra_hi-n': case 'tsra_hi-n':
case 'hurricane': case 'hurricane':
case 'tropical_storm': case 'tropical_storm':
case 'hurricane-n':
case 'tropical_storm-n':
return addPath('CC_TStorm.gif'); return addPath('CC_TStorm.gif');
case 'wind_few': case 'wind_few':