Exemplo n.º 1
0
 def test_sanitize_report_list(self):
     """
     Tests a function which fixes common mistakes while the report is a list
     """
     for line, fixed in (
         ("KJFK AUTO 123456Z ////// KT 10SM 20/10",
          "KJFK 123456Z 10SM 20/10"),
         ("METAR EGLL CALM RETS 6SPM CLR Q 1000",
          "EGLL 00000KT TS P6SM Q1000"),
         ("TLPL 111200Z 111200Z11020KT Q1015",
          "TLPL 111200Z 11020KT Q1015"),
         ("SECU 151200Z 151200Z18002KT Q1027",
          "SECU 151200Z 18002KT Q1027"),
         ("OAKB 211230Z 360G17G32KT Q1011",
          "OAKB 211230Z 36017G32KT Q1011"),
         ("MHLC 090024Z 06012G22TK 5000", "MHLC 090024Z 06012G22KT 5000"),
         ("SKCL 211600Z 211600ZVRB04KT A3010",
          "SKCL 211600Z VRB04KT A3010"),
         (
             "SVMG 072200Z //////KT 9999 FEW010 XX/XX Q1012",
             "SVMG 072200Z 9999 FEW010 Q1012",
         ),
         ("KJFK 1 1 1 1 1 1 2 1", "KJFK 1 2 1"),
     ):
         line, fixed = line.split(), fixed.split()
         self.assertEqual(sanitization.sanitize_report_list(line), fixed)
Exemplo n.º 2
0
def parse_na_line(line: str, units: Units) -> {str: str}:
    """
    Parser for the North American TAF forcast variant
    """
    data = core.dedupe(line.split())
    data = sanitization.sanitize_report_list(data)
    ret = {"sanitized": " ".join(data)}
    (
        data,
        ret["type"],
        ret["start_time"],
        ret["end_time"],
        ret["transition_start"],
    ) = get_type_and_times(data)
    data, ret["wind_shear"] = get_wind_shear(data)
    (
        data,
        ret["wind_direction"],
        ret["wind_speed"],
        ret["wind_gust"],
        _,
    ) = core.get_wind(data, units)
    data, ret["visibility"] = core.get_visibility(data, units)
    data, ret["clouds"] = core.get_clouds(data)
    (
        ret["other"],
        ret["altimeter"],
        ret["icing"],
        ret["turbulence"],
    ) = get_alt_ice_turb(data)
    return ret
Exemplo n.º 3
0
def parse_in_line(line: str, units: Units) -> Dict[str, str]:
    """Parser for the International TAF forcast variant"""
    data = core.dedupe(line.split())
    data = sanitization.sanitize_report_list(data, remove_clr_and_skc=False)
    ret = {"sanitized": " ".join(data)}
    (
        data,
        ret["type"],
        ret["start_time"],
        ret["end_time"],
        ret["transition_start"],
    ) = get_type_and_times(data)
    data, ret["wind_shear"] = get_wind_shear(data)
    (
        data,
        ret["wind_direction"],
        ret["wind_speed"],
        ret["wind_gust"],
        _,
    ) = core.get_wind(data, units)
    if "CAVOK" in data:
        ret["visibility"] = core.make_number("CAVOK")
        ret["clouds"] = []
        data.pop(data.index("CAVOK"))
    else:
        data, ret["visibility"] = core.get_visibility(data, units)
        data, ret["clouds"] = core.get_clouds(data)
    (
        ret["other"],
        ret["altimeter"],
        ret["icing"],
        ret["turbulence"],
    ) = get_alt_ice_turb(data)
    return ret
Exemplo n.º 4
0
def parse(report: str, issued: date = None) -> AirepData:
    """"""
    if not report:
        return None
    clean = sanitization.sanitize_report_string(report)
    wxdata = sanitization.sanitize_report_list(clean.split())
    wxresp = {"raw": report, "sanitized": " ".join(wxdata)}
    print(wxdata)
    print(wxresp)
    return None
Exemplo n.º 5
0
def sanitize(report: str) -> Tuple[str, str, List[str]]:
    """Returns a sanitized report, remarks, and elements ready for parsing"""
    clean = sanitization.sanitize_report_string(report)
    data, remark_str = get_remarks(clean)
    data = core.dedupe(data)
    data = sanitization.sanitize_report_list(data)
    clean = " ".join(data)
    if remark_str:
        clean += " " + remark_str
    return clean, remark_str, data