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

Added parsing for Recent Significant Weather e.g. REUP #16

Merged
merged 1 commit into from
Apr 10, 2015
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
42 changes: 39 additions & 3 deletions metar.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,32 @@ var WEATHER = {
FC: "funnel cloud"
};

var RECENT_WEATHER = {
REBLSN: "Moderate/heavy blowing snow (visibility significantly reduced)reduced",
REDS: "Dust Storm",
REFC: "Funnel Cloud",
REFZDZ: "Freezing Drizzle",
REFZRA: "Freezing Rain",
REGP: "Moderate/heavy snow pellets",
REGR: "Moderate/heavy hail",
REGS: "Moderate/heavy small hail",
REIC: "Moderate/heavy ice crystals",
REPL: "Moderate/heavy ice pellets",
RERA: "Moderate/heavy rain",
RESG: "Moderate/heavy snow grains",
RESHGR: "Moderate/heavy hail showers",
RESHGS: "Moderate/heavy small hail showers",
RESHGS: "Moderate/heavy snow pellet showers",
RESHPL: "Moderate/heavy ice pellet showers",
RESHRA: "Moderate/heavy rain showers",
RESHSN: "Moderate/heavy snow showers",
RESN: "Moderate/heavy snow",
RESS: "Sandstorm",
RETS: "Thunderstorm",
REUP: "Unidentified precipitation (AUTO obs. only)",
REVA: "Volcanic Ash"
};

function parseAbbreviation(s, map) {
var abbreviation, meaning, length = 3;
if (!s) return;
Expand Down Expand Up @@ -180,7 +206,7 @@ METAR.prototype.parseWind = function() {
this.result.wind.speed = asInt(this.current.slice(3,5));

var unitMatch;
if (unitMatch = this.current.match(/KT|MPS|KPH$/)) {
if (unitMatch = this.current.match(/KT|MPS|KPH|SM$/)) {
this.result.wind.unit = unitMatch[0];
}
else {
Expand Down Expand Up @@ -292,6 +318,17 @@ METAR.prototype.parseAltimeter = function() {
}
};

METAR.prototype.parseRecentSignificantWeather = function() {
this.next();

if (this.current === undefined || this.current === null) return;

if (RECENT_WEATHER[this.current]) {
this.result.recentSignificantWeather = this.current;
this.result.recentSignificantWeatherDescription = RECENT_WEATHER[this.current];
}
};

METAR.prototype.parse = function() {
this.parseType();
this.parseStation();
Expand All @@ -306,10 +343,9 @@ METAR.prototype.parse = function() {
this.parseClouds();
this.parseTempDewpoint();
this.parseAltimeter();
this.parseRecentSignificantWeather();
};



function parseMETAR(metarString) {
var m = new METAR(metarString);
m.parse();
Expand Down
26 changes: 23 additions & 3 deletions test/parse_metar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ describe("METAR parser", function() {

m = parseMetar("PAOM 302353Z COR 32005KT 10SM CLR M03/M09 A2993");
assert.equal(true, m.correction);

m = parseMetar("KCNO 302353Z COR 25013KT 10SM FEW180 23/14 A2994 RMK AO2 SLP133 T02330139 10306 20217 55002");
assert.equal(true, m.correction);
});

it("can parse metar without auto", function() {
Expand Down Expand Up @@ -80,7 +83,7 @@ describe("METAR parser", function() {
assert.equal(42, m.wind.gust);
});

it("can MPH speed", function() {
it("can parse MPH speed", function() {
var m = parseMetar("ULLI 172030Z 23004MPS 9999 -SHRA SCT022CB BKN043 OVC066 13/10 Q1010 NOSIG");
assert.equal(4, m.wind.speed);
assert.equal("MPS", m.wind.unit);
Expand Down Expand Up @@ -231,7 +234,6 @@ describe("METAR parser", function() {
cumulonimbus: true
}], m.clouds);
});

});

describe("for temp/dewpoint", function() {
Expand All @@ -252,7 +254,6 @@ describe("METAR parser", function() {
assert.equal(-2, m.temperature);
assert.equal(-3, m.dewpoint);
});

});

describe("for altimeter", function() {
Expand All @@ -265,7 +266,26 @@ describe("METAR parser", function() {
var m = parseMetar("KLZZ 302355Z AUTO 00000KT 10SM CLR 04/M02 A3029 RMK AO2 T00391018 10070 20031");
assert.equal(30.29, m.altimeter_in_hg);
});
});

describe("for recent significant weather", function() {
it("can parse Moderate/heavy rain showers [RESHRA]", function() {
var m = parseMetar("EFKI 171950Z 00000KT 9999 MIFG FEW012 SCT200 10/11 Q1006 RESHRA");
assert.equal("RESHRA", m.recentSignificantWeather);
assert.equal("Moderate/heavy rain showers", m.recentSignificantWeatherDescription);
});

it("can parse Auto recent weather Unidentified precipitation", function() {
var m = parseMetar("EFKI 171950Z 00000KT 9999 MIFG FEW012 SCT200 10/11 Q1006 REUP");
assert.equal("REUP", m.recentSignificantWeather);
assert.equal("Unidentified precipitation (AUTO obs. only)", m.recentSignificantWeatherDescription);
});

it("can parse obs without recent weather", function() {
var m = parseMetar("EFKI 171950Z 00000KT 9999 MIFG FEW012 SCT200 10/11 Q1006=");
assert.equal(null, m.recentSignificantWeather);
assert.equal(null, m.recentSignificantWeatherDescription);
});
});

describe("for rvr", function() {
Expand Down