def parse_in(report: str) -> (MetarData, Units): """ Parser for the International METAR variant """ units = Units(**IN_UNITS) wxresp = {"raw": report} clean = _core.sanitize_report_string(report) wxdata, wxresp["remarks"] = _core.get_remarks(clean) wxdata = _core.dedupe(wxdata) wxdata = _core.sanitize_report_list(wxdata) wxresp["sanitized"] = " ".join(wxdata + [wxresp["remarks"]]) wxdata, wxresp["station"], wxresp["time"] = _core.get_station_and_time(wxdata) wxdata, wxresp["runway_visibility"] = _core.get_runway_visibility(wxdata) if "CAVOK" not in wxdata: wxdata, wxresp["clouds"] = _core.get_clouds(wxdata) wxdata, wxresp["wind_direction"], wxresp["wind_speed"], wxresp["wind_gust"], wxresp[ "wind_variable_direction" ] = _core.get_wind(wxdata, units) wxdata, wxresp["altimeter"] = _core.get_altimeter(wxdata, units, "IN") if "CAVOK" in wxdata: wxresp["visibility"] = _core.make_number("CAVOK") wxresp["clouds"] = [] wxdata.remove("CAVOK") else: wxdata, wxresp["visibility"] = _core.get_visibility(wxdata, units) wxresp["other"], wxresp["temperature"], wxresp["dewpoint"] = _core.get_temp_and_dew( wxdata ) condition = _core.get_flight_rules( wxresp["visibility"], _core.get_ceiling(wxresp["clouds"]) ) wxresp["flight_rules"] = FLIGHT_RULES[condition] wxresp["remarks_info"] = remarks.parse(wxresp["remarks"]) wxresp["time"] = _core.make_timestamp(wxresp["time"]) return MetarData(**wxresp), units
def test_get_flight_rules(self): """ Tests that the proper flight rule is calculated for a set visibility and ceiling Note: Only 'Broken', 'Overcast', and 'Vertical Visibility' are considdered ceilings """ for vis, ceiling, rule in ( (None, None, "IFR"), ("10", None, "VFR"), ("P6SM", ["OCV", 50], "VFR"), ("6", ["OVC", 20], "MVFR"), ("6", ["OVC", 7], "IFR"), ("2", ["OVC", 20], "IFR"), ("6", ["OVC", 4], "LIFR"), ("1/2", ["OVC", 30], "LIFR"), ("M1/4", ["OVC", 30], "LIFR"), ): vis = _core.make_number(vis) if ceiling: ceiling = structs.Cloud(None, *ceiling) self.assertEqual( static.FLIGHT_RULES[_core.get_flight_rules(vis, ceiling)], rule)
def test_get_flight_rules(self): """ Tests that the proper flight rule is calculated for a set visibility and ceiling Note: Only 'Broken', 'Overcast', and 'Vertical Visibility' are considdered ceilings """ for vis, ceiling, rule in ( (None, None, 'IFR'), ('10', None, 'VFR'), ('P6SM', ['OCV', 50], 'VFR'), ('6', ['OVC', 20], 'MVFR'), ('6', ['OVC', 7], 'IFR'), ('2', ['OVC', 20], 'IFR'), ('6', ['OVC', 4], 'LIFR'), ('1/2', ['OVC', 30], 'LIFR'), ('M1/4', ['OVC', 30], 'LIFR'), ): vis = _core.make_number(vis) if ceiling: ceiling = structs.Cloud(None, *ceiling) self.assertEqual( static.FLIGHT_RULES[_core.get_flight_rules(vis, ceiling)], rule)