Skip to content

Commit

Permalink
Adds visibility attr to hourly attr map.
Browse files Browse the repository at this point in the history
Adds a conversion from meters to yards for the visibility attr.
  • Loading branch information
eireland committed Jan 31, 2024
1 parent ebf636a commit e64e152
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
18 changes: 16 additions & 2 deletions src/utils/noaaDataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}),
Expand Down

0 comments on commit e64e152

Please sign in to comment.