mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-22 19:49:31 -07:00
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:
2
dist/index.html
vendored
2
dist/index.html
vendored
File diff suppressed because one or more lines are too long
2
dist/resources/ws.min.js
vendored
2
dist/resources/ws.min.js
vendored
File diff suppressed because one or more lines are too long
1544
package-lock.json
generated
1544
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -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": {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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':
|
||||||
|
|||||||
Reference in New Issue
Block a user