Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds visibility attr to hourly attr map. #48

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading