mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-14 07:39:29 -07:00
some marine forecast updates
This commit is contained in:
@@ -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'));
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
<script type="module" src="scripts/modules/regionalforecast.mjs"></script>
|
||||
<script type="module" src="scripts/modules/travelforecast.mjs"></script>
|
||||
<script type="module" src="scripts/modules/progress.mjs"></script>
|
||||
<script type="module" src="scripts/modules/radar.mjs"></script>
|
||||
<script type="module" src="scripts/modules/marineforecast.mjs"></script>
|
||||
<script type="module" src="scripts/index.mjs"></script>
|
||||
|
||||
<!-- data -->
|
||||
@@ -107,6 +107,9 @@
|
||||
</div>
|
||||
<div id="almanac-html" class="weather-display">
|
||||
<%- include('partials/almanac.ejs') %>
|
||||
</div>
|
||||
<div id="marine-forecast-html" class="weather-display">
|
||||
<%- include('partials/marine-forecast.ejs') %>
|
||||
</div>
|
||||
<div id="extended-forecast-html" class="weather-display">
|
||||
<%- include('partials/extended-forecast.ejs') %>
|
||||
|
||||
@@ -51,5 +51,9 @@
|
||||
"editor.defaultFormatter": "j69.ejs-beautify"
|
||||
},
|
||||
"files.exclude": {},
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit"
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user