Skip to content

Commit

Permalink
Merge branch 'main' of github.com:netbymatt/ws4kp
Browse files Browse the repository at this point in the history
  • Loading branch information
netbymatt committed Oct 19, 2024
2 parents 1d44b9e + 20d2516 commit 5918f08
Show file tree
Hide file tree
Showing 9 changed files with 1,087 additions and 1,001 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module.exports = {
indent: [
'error',
'tab',
{
SwitchCase: 1
},
],
'no-tabs': 0,
'no-console': 0,
Expand Down
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"format": "compressed",
"extensionName": ".css",
"savePath": "/server/styles",
"savePathSegmentKeys": null,
"savePathReplaceSegmentsWith": null
}
],
"search.exclude": {
Expand All @@ -21,5 +19,8 @@
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
},
"eslint.validate": [
"javascript"
]
}
2 changes: 1 addition & 1 deletion dist/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/resources/ws.min.js

Large diffs are not rendered by default.

1,544 changes: 798 additions & 746 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ws4kp",
"version": "5.12.0",
"version": "5.13.2",
"description": "Welcome to the WeatherStar 4000+ project page!",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -48,4 +48,4 @@
"express": "^4.17.1",
"ejs": "^3.1.5"
}
}
}
32 changes: 29 additions & 3 deletions server/scripts/modules/hazards.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
import STATUS from './status.mjs';
import { json } from './utils/fetch.mjs';
import WeatherDisplay from './weatherdisplay.mjs';
import { registerDisplay } from './navigation.mjs';
import { registerDisplay, msg } from './navigation.mjs';

const hazardLevels = {
Extreme: 10,
Severe: 5,
};

const hazardModifiers = {
'Hurricane Warning': 2,
'Tornado Warning': 3,
'Severe Thunderstorm Warning': 1,
}

class Hazards extends WeatherDisplay {
constructor(navId, elemId, defaultActive) {
// special height and width for scrolling
Expand All @@ -34,8 +40,9 @@ class Hazards extends WeatherDisplay {
url.searchParams.append('limit', 5);
const alerts = await json(url, { retryCount: 3, stillWaiting: () => this.stillWaiting() });
const unsortedAlerts = alerts.features ?? [];
const sortedAlerts = unsortedAlerts.sort((a, b) => (hazardLevels[b.properties.severity] ?? 0) - (hazardLevels[a.properties.severity] ?? 0));
const filteredAlerts = sortedAlerts.filter((hazard) => hazard.properties.severity !== 'Unknown');
const hasImmediate = unsortedAlerts.reduce((acc, hazard) => acc || hazard.properties.urgency === 'Immediate', false);
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;

// show alert indicator
Expand Down Expand Up @@ -134,6 +141,25 @@ class Hazards extends WeatherDisplay {
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
Expand Down
Loading

0 comments on commit 5918f08

Please sign in to comment.