enhance current weather, latest observations #188 #196 #193 #194

This commit is contained in:
Matt Walsh
2026-04-07 13:50:37 -05:00
parent e70639d7a6
commit 38cdb46c85
10 changed files with 85 additions and 10 deletions

View File

@@ -14,6 +14,7 @@ import {
import { debugFlag } from './utils/debug.mjs';
import { isDataStale, enhanceObservationWithMapClick } from './utils/mapclick.mjs';
import { DateTime } from '../vendor/auto/luxon.mjs';
import settings from './settings.mjs';
// some stations prefixed do not provide all the necessary data
const skipStations = ['U', 'C', 'H', 'W', 'Y', 'T', 'S', 'M', 'O', 'L', 'A', 'F', 'B', 'N', 'V', 'R', 'D', 'E', 'I', 'G', 'J'];
@@ -192,7 +193,9 @@ class CurrentWeather extends WeatherDisplay {
const wind = (typeof this.data.WindSpeed === 'number') ? this.data.WindDirection.padEnd(3, '') + this.data.WindSpeed.toString().padStart(3, ' ') : this.data.WindSpeed;
// get location (city name) from StationInfo if available (allows for overrides)
const location = (StationInfo[this.data.station.properties.stationIdentifier]?.city ?? locationCleanup(this.data.station.properties.name)).substr(0, 20);
// longer name allowed if in wide-enhanced
const locationLimit = (settings.wide?.value && settings.enhancedScreens?.value) ? 25 : 20;
const location = (StationInfo[this.data.station.properties.stationIdentifier]?.city ?? locationCleanup(this.data.station.properties.name)).substr(0, locationLimit);
const fill = {
temp: this.data.Temperature + String.fromCharCode(176),

View File

@@ -159,12 +159,17 @@ class LatestObservations extends WeatherDisplay {
const windDirection = directionToNSEW(condition.windDirection.value);
const Temperature = temperatureConverter(condition.temperature.value);
const Like = likeTemperature(condition.heatIndex?.value, condition.windChill?.value, Temperature, temperatureConverter);
const WindSpeed = windConverter(condition.windSpeed.value);
const locationLimit = (settings.wide?.value && settings.enhancedScreens?.value) ? 20 : 14;
const weatherLimit = (settings.wide?.value && settings.enhancedScreens?.value) ? 10 : 9;
const fill = {
location: locationCleanup(condition.city).substr(0, 14),
location: locationCleanup(condition.city).substr(0, locationLimit),
temp: Temperature,
weather: shortenCurrentConditions(condition.textDescription).substr(0, 9),
like: Like.value,
weather: shortenCurrentConditions(condition.textDescription).substr(0, weatherLimit),
};
if (WindSpeed > 0) {
@@ -175,7 +180,12 @@ class LatestObservations extends WeatherDisplay {
fill.wind = 'Calm';
}
return this.fillTemplate('observation-row', fill);
const filledRow = this.fillTemplate('observation-row', fill);
// add the feels like class
filledRow.querySelector('.like').classList.add(Like.cssClass);
return filledRow;
});
const linesContainer = this.elem.querySelector('.observation-lines');
@@ -186,6 +196,25 @@ class LatestObservations extends WeatherDisplay {
}
}
// generate a "feels like" temperature from heat index and wind chill.
const likeTemperature = (heat, wind, actual, converter) => {
// figure out the feels like value
let value = '';
if (heat) value = converter(heat);
if (wind) value = converter(wind);
// determine if there's a red/blue color class to add
let cssClass;
if (value !== '') {
if (value > actual) cssClass = 'heat-index';
if (value < actual) cssClass = 'wind-chill';
}
return {
value,
cssClass,
};
};
const shortenCurrentConditions = (_condition) => {
let condition = _condition;
condition = condition.replace(/Light/, 'L');