From c70d9653474a5d53d7194718f871bfeeb06b9060 Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Tue, 23 Apr 2024 15:32:19 -0500 Subject: [PATCH] some marine forecast updates --- server/scripts/modules/marineforecast.mjs | 26 +++++++++++------------ views/index.ejs | 5 ++++- ws4kp.code-workspace | 4 ++++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/server/scripts/modules/marineforecast.mjs b/server/scripts/modules/marineforecast.mjs index c869552..d0fb47f 100644 --- a/server/scripts/modules/marineforecast.mjs +++ b/server/scripts/modules/marineforecast.mjs @@ -4,7 +4,6 @@ import STATUS from './status.mjs'; import WeatherDisplay from './weatherdisplay.mjs'; import { registerDisplay } from './navigation.mjs'; -import getExtendedForecast from './extendedforecast.mjs'; import getHourlyForecast from './hourly.mjs'; class MarineForecast extends WeatherDisplay { @@ -19,11 +18,8 @@ class MarineForecast extends WeatherDisplay { async getData() { if (!super.getData()) return; - const [extendedForecast, hourlyForecast] = await Promise.all([ - getExtendedForecast(() => this.stillWaiting()), - getHourlyForecast(() => this.stillWaiting()), - ]); - if (extendedForecast === undefined || hourlyForecast === undefined) { + const hourlyForecast = await getHourlyForecast(() => this.stillWaiting()); + if (hourlyForecast === undefined) { this.setStatus(STATUS.failed); return; } @@ -36,10 +32,7 @@ class MarineForecast extends WeatherDisplay { return; } - this.data = { - extendedForecast, - hourlyForecast, - }; + this.data = hourlyForecast; this.screenIndex = 0; this.setStatus(STATUS.loaded); } @@ -54,11 +47,12 @@ class MarineForecast extends WeatherDisplay { // create each day template const days = forecast.map((Day) => { const fill = {}; + const waveHeight = Math.round(Day.waveHeight * 3.281); fill.date = Day.dayName; - fill['wind-dir'] = 'NW'; + fill['wind-dir'] = Day.windDirection; fill['wind-speed'] = '10 - 15kts'; - fill['wave-height'] = '1\''; - fill['wave-desc'] = ''; + fill['wave-height'] = `${waveHeight}'`; + fill['wave-desc'] = waveDesc(waveHeight); const { low } = Day; if (low !== undefined) { @@ -135,5 +129,11 @@ const waveImage = (conditions) => { return canvas.toDataURL(); }; +const waveDesc = (waveHeight) => { + if (waveHeight > 7) return 'ROUGH'; + if (waveHeight > 4) return 'CHOPPY'; + return 'LIGHT'; +}; + // register display registerDisplay(new MarineForecast(11, 'marine-forecast')); diff --git a/views/index.ejs b/views/index.ejs index d65fc7b..d40505f 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -42,7 +42,7 @@ - + @@ -107,6 +107,9 @@
<%- include('partials/almanac.ejs') %> +
+
+ <%- include('partials/marine-forecast.ejs') %>
<%- include('partials/extended-forecast.ejs') %> diff --git a/ws4kp.code-workspace b/ws4kp.code-workspace index 96e5731..8b7ce1b 100644 --- a/ws4kp.code-workspace +++ b/ws4kp.code-workspace @@ -51,5 +51,9 @@ "editor.defaultFormatter": "j69.ejs-beautify" }, "files.exclude": {}, + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + } }, } \ No newline at end of file