From 5cb2dc5375d675503bf5b24a5fdf933bf17e7a88 Mon Sep 17 00:00:00 2001 From: lif <> Date: Sat, 11 Nov 2023 19:54:58 -0800 Subject: [PATCH] hack metric units back in --- server/scripts/modules/currentweather.mjs | 9 +++++---- server/scripts/modules/extendedforecast.mjs | 2 +- server/scripts/modules/latestobservations.mjs | 5 +++-- server/scripts/modules/localforecast.mjs | 2 +- server/scripts/modules/regionalforecast.mjs | 2 +- server/scripts/modules/utils/units.mjs | 7 ++++--- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/server/scripts/modules/currentweather.mjs b/server/scripts/modules/currentweather.mjs index 61bbf00..a86a233 100644 --- a/server/scripts/modules/currentweather.mjs +++ b/server/scripts/modules/currentweather.mjs @@ -186,14 +186,15 @@ const parseData = (data) => { // convert to us units data.Temperature = celsiusToFahrenheit(data.Temperature); - data.TemperatureUnit = 'F'; + // HACK + // data.TemperatureUnit = 'F'; data.DewPoint = celsiusToFahrenheit(data.DewPoint); data.Ceiling = Math.round(metersToFeet(data.Ceiling) / 100) * 100; - data.CeilingUnit = 'ft.'; + // data.CeilingUnit = 'ft.'; data.Visibility = kilometersToMiles(observations.visibility.value / 1000); - data.VisibilityUnit = ' mi.'; + // data.VisibilityUnit = ' mi.'; data.WindSpeed = kphToMph(data.WindSpeed); - data.WindUnit = 'MPH'; + // data.WindUnit = 'MPH'; data.Pressure = pascalToInHg(data.Pressure).toFixed(2); data.HeatIndex = celsiusToFahrenheit(data.HeatIndex); data.WindChill = celsiusToFahrenheit(data.WindChill); diff --git a/server/scripts/modules/extendedforecast.mjs b/server/scripts/modules/extendedforecast.mjs index aa5b859..50c3a87 100644 --- a/server/scripts/modules/extendedforecast.mjs +++ b/server/scripts/modules/extendedforecast.mjs @@ -26,7 +26,7 @@ class ExtendedForecast extends WeatherDisplay { try { forecast = await json(weatherParameters.forecast, { data: { - units: 'us', + units: 'si', }, retryCount: 3, stillWaiting: () => this.stillWaiting(), diff --git a/server/scripts/modules/latestobservations.mjs b/server/scripts/modules/latestobservations.mjs index 98cba31..3c2314d 100644 --- a/server/scripts/modules/latestobservations.mjs +++ b/server/scripts/modules/latestobservations.mjs @@ -64,8 +64,9 @@ class LatestObservations extends WeatherDisplay { // sort array by station name const sortedConditions = conditions.sort((a, b) => ((a.Name < b.Name) ? -1 : 1)); - this.elem.querySelector('.column-headers .temp.english').classList.add('show'); - this.elem.querySelector('.column-headers .temp.metric').classList.remove('show'); + //this.elem.querySelector('.column-headers .temp.english').classList.add('show'); + //this.elem.querySelector('.column-headers .temp.metric').classList.remove('show'); + this.elem.querySelector('.column-headers .temp.metric').classList.add('show'); const lines = sortedConditions.map((condition) => { const windDirection = directionToNSEW(condition.windDirection.value); diff --git a/server/scripts/modules/localforecast.mjs b/server/scripts/modules/localforecast.mjs index 3528b20..73135e3 100644 --- a/server/scripts/modules/localforecast.mjs +++ b/server/scripts/modules/localforecast.mjs @@ -61,7 +61,7 @@ class LocalForecast extends WeatherDisplay { try { return await json(weatherParameters.forecast, { data: { - units: 'us', + units: 'si', }, retryCount: 3, stillWaiting: () => this.stillWaiting(), diff --git a/server/scripts/modules/regionalforecast.mjs b/server/scripts/modules/regionalforecast.mjs index 15d89b1..df8d5c3 100644 --- a/server/scripts/modules/regionalforecast.mjs +++ b/server/scripts/modules/regionalforecast.mjs @@ -80,7 +80,7 @@ class RegionalForecast extends WeatherDisplay { // start off the observation task const observationPromise = utils.getRegionalObservation(point, city); - const forecast = await json(`https://api.weather.gov/gridpoints/${point.wfo}/${point.x},${point.y}/forecast`); + const forecast = await json(`https://api.weather.gov/gridpoints/${point.wfo}/${point.x},${point.y}/forecast?units=si`); // get XY on map for city const cityXY = utils.getXYForCity(city, minMaxLatLon.maxLat, minMaxLatLon.minLon, weatherParameters.state); diff --git a/server/scripts/modules/utils/units.mjs b/server/scripts/modules/utils/units.mjs index fea90b4..0b7c0d3 100644 --- a/server/scripts/modules/utils/units.mjs +++ b/server/scripts/modules/utils/units.mjs @@ -3,9 +3,10 @@ const round2 = (value, decimals) => Math.trunc(value * 10 ** decimals) / 10 ** decimals; const kphToMph = (Kph) => Math.round(Kph / 1.609_34); -const celsiusToFahrenheit = (Celsius) => Math.round((Celsius * 9) / 5 + 32); -const kilometersToMiles = (Kilometers) => Math.round(Kilometers / 1.609_34); -const metersToFeet = (Meters) => Math.round(Meters / 0.3048); +// HACK! +const celsiusToFahrenheit = (Celsius) => Celsius; // Math.round((Celsius * 9) / 5 + 32); +const kilometersToMiles = (Kilometers) => Kilometers; // Math.round(Kilometers / 1.609_34); +const metersToFeet = (Meters) => Meters; // Math.round(Meters / 0.3048); const pascalToInHg = (Pascal) => round2(Pascal * 0.000_295_3, 2); export {