Merge remote-tracking branch 'upstream/main' into modernization-and-refactor

This commit is contained in:
Eddy G
2025-06-27 18:21:32 -04:00
2 changed files with 40 additions and 10 deletions

View File

@@ -153,10 +153,12 @@ class CurrentWeather extends WeatherDisplay {
condition = shortConditions(condition); condition = shortConditions(condition);
} }
const wind = (typeof this.data.WindSpeed === 'number') ? this.data.WindDirection.padEnd(3, '') + this.data.WindSpeed.toString().padStart(3, ' ') : '-';
const fill = { const fill = {
temp: this.data.Temperature + String.fromCharCode(176), temp: this.data.Temperature + String.fromCharCode(176),
condition, condition,
wind: this.data.WindDirection.padEnd(3, '') + this.data.WindSpeed.toString().padStart(3, ' '), wind,
location: locationCleanup(this.data.station.properties.name).substr(0, 20), location: locationCleanup(this.data.station.properties.name).substr(0, 20),
humidity: `${this.data.Humidity}%`, humidity: `${this.data.Humidity}%`,
dewpoint: this.data.DewPoint + String.fromCharCode(176), dewpoint: this.data.DewPoint + String.fromCharCode(176),
@@ -243,7 +245,6 @@ const parseData = (data) => {
data.WindSpeed = windConverter(observations.windSpeed.value); data.WindSpeed = windConverter(observations.windSpeed.value);
data.WindDirection = directionToNSEW(observations.windDirection.value); data.WindDirection = directionToNSEW(observations.windDirection.value);
data.WindGust = windConverter(observations.windGust.value); data.WindGust = windConverter(observations.windGust.value);
data.WindSpeed = windConverter(data.WindSpeed);
data.WindUnit = windConverter.units; data.WindUnit = windConverter.units;
data.Humidity = Math.round(observations.relativeHumidity.value); data.Humidity = Math.round(observations.relativeHumidity.value);
data.Icon = getLargeIcon(observations.icon); data.Icon = getLargeIcon(observations.icon);

View File

@@ -8,8 +8,11 @@ import * as utils from './radar-utils.mjs';
import setTiles from './radar-tiles.mjs'; import setTiles from './radar-tiles.mjs';
import processRadar from './radar-processor.mjs'; import processRadar from './radar-processor.mjs';
// Use OVERRIDE_RADAR_HOST if provided, otherwise default to mesonet // store processed radar as dataURLs to avoid re-processing frames as they slide backwards in time
const RADAR_HOST = (typeof OVERRIDES !== 'undefined' ? OVERRIDES?.RADAR_HOST : undefined) || 'mesonet.agron.iastate.edu'; // this is cleared upon changing the location displayed
let processedRadars = [];
const RADAR_HOST = 'mesonet.agron.iastate.edu';
class Radar extends WeatherDisplay { class Radar extends WeatherDisplay {
constructor(navId, elemId) { constructor(navId, elemId) {
super(navId, elemId, 'Local Radar'); super(navId, elemId, 'Local Radar');
@@ -136,20 +139,43 @@ class Radar extends WeatherDisplay {
elemId: this.elemId, elemId: this.elemId,
}); });
// Load the most recent doppler radar images. const radarKey = `${radarSourceXY.x.toFixed(0)}-${radarSourceXY.y.toFixed(0)}`;
// reset the "used" flag on pre-processed radars
// items that were not used during this process are deleted (either expired via time or change of location)
processedRadars.forEach((radar) => { radar.used = false; });
try { try {
const radarInfo = await Promise.all(urls.map(async (url) => { const radarInfo = await Promise.all(urls.map(async (url) => {
const processedRadar = await processRadar({ // store the time
const timeMatch = url.match(/_(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)\./);
const [, year, month, day, hour, minute] = timeMatch;
const radarKeyedTimestamp = `${radarKey}:${year}${month}${day}${hour}${minute}`;
// check for a pre-processed radar
const preProcessed = processedRadars.find((radar) => radar.key === radarKeyedTimestamp);
// use the pre-processed radar, or get a new one
const processedRadar = preProcessed?.dataURL ?? await processRadar({
url, url,
RADAR_HOST, RADAR_HOST,
OVERRIDES, OVERRIDES,
radarSourceXY, radarSourceXY,
}); });
// store the time // store the radar
const timeMatch = url.match(/_(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)\./); if (!preProcessed) {
processedRadars.push({
key: radarKeyedTimestamp,
dataURL: processedRadar,
used: true,
});
} else {
// set used flag
preProcessed.used = true;
}
const [, year, month, day, hour, minute] = timeMatch;
const time = DateTime.fromObject({ const time = DateTime.fromObject({
year, year,
month, month,
@@ -177,6 +203,9 @@ class Radar extends WeatherDisplay {
this.times = radarInfo.map((radar) => radar.time); this.times = radarInfo.map((radar) => radar.time);
this.setStatus(STATUS.loaded); this.setStatus(STATUS.loaded);
// clean up any unused stored radars
processedRadars = processedRadars.filter((radar) => radar.used);
} catch (_error) { } catch (_error) {
// Radar fetch failed - skip this display in animation by setting totalScreens = 0 // Radar fetch failed - skip this display in animation by setting totalScreens = 0
this.timing.totalScreens = 0; this.timing.totalScreens = 0;