From e64e152ae4826e227ec8abdbb3e259162495eb7d Mon Sep 17 00:00:00 2001 From: eireland Date: Wed, 31 Jan 2024 13:39:42 -0800 Subject: [PATCH] Adds visibility attr to hourly attr map. Adds a conversion from meters to yards for the visibility attr. --- src/types.ts | 1 + src/utils/noaaDataTypes.ts | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index d6b5b84..39fef97 100644 --- a/src/types.ts +++ b/src/types.ts @@ -147,6 +147,7 @@ export const dailyMonthlyAttrMap: AttrType[] = [ export const hourlyAttrMap: AttrType[] = [ {name: "Dew Point", abbr: "Dew", unit: unitMap.temperature}, + {name: "Visibility", abbr: "Vis", unit: unitMap.distance}, {name: "Barometric Pressure at sea level", abbr: "Pressure", unit: unitMap.pressure}, {name: "Air temperature", abbr: "Temp", unit: unitMap.temperature}, {name: "Wind direction", abbr: "WDir", unit: unitMap.angle}, diff --git a/src/utils/noaaDataTypes.ts b/src/utils/noaaDataTypes.ts index 990b113..d7c4cdc 100644 --- a/src/utils/noaaDataTypes.ts +++ b/src/utils/noaaDataTypes.ts @@ -15,13 +15,27 @@ interface ConverterMap { const converterMap: ConverterMap = { angle: null, - distance: null, + distance: convertVis, temperature: convertTemp, precipitation: convertPrecip, speed: convertWindspeed, pressure: null }; +function convertVis(fromUnit: Unit, toUnit: Unit, value: string) { + let k = 0.9144; + const numValue = Number(value); + if (!convertible(value)) { + return numValue; + } else if (fromUnit === "m" && toUnit === "yd") { + return numValue / k; + } else if (fromUnit === "yd" && toUnit === "m") { + return numValue * k; + } else { + return numValue; + } +} + function convertPrecip(fromUnit: Unit, toUnit: Unit, value: string) { let k = 25.4; const numValue = Number(value); @@ -151,7 +165,7 @@ const dataTypes = [ {"global-hourly": extractHourlyPressure}), new NoaaType("TMP", "temp", kUnitTypeTemp, "Air temperature", ["global-hourly"], {"global-hourly": extractHourlyTemp}), - new NoaaType("VIS", "vis", kUnitTypeDistance, "Visibility", + new NoaaType("VIS", "Vis", kUnitTypeDistance, "Visibility", ["global-hourly"], {"global-hourly": extractHourlyVisibility}), new NoaaType("WND", "WDir", kUnitTypeAngle, "Wind direction", ["global-hourly"], {"global-hourly": extractHourlyWindDirection}),