def test_taf_line(self):
     """
     Tests converting TAF line data into into a single spoken string
     """
     units = structs.Units(**static.NA_UNITS)
     line = {
         'altimeter': core.make_number('2992'),
         'clouds': [core.make_cloud('BKN015CB')],
         'end_time': core.make_timestamp('1206'),
         'icing': ['611005'],
         'other': ['+RA'],
         'start_time': core.make_timestamp('1202'),
         'turbulance': ['540553'],
         'type': 'FROM',
         'visibility': core.make_number('3'),
         'wind_direction': core.make_number('360'),
         'wind_gust': core.make_number('20'),
         'wind_shear': 'WS020/07040KT',
         'wind_speed': core.make_number('12'),
     }
     line.update({
         k: None
         for k in ('flight_rules', 'probability', 'raw', 'sanitized')
     })
     line = structs.TafLineData(**line)
     spoken = (
         'From 2 to 6 zulu, Winds three six zero at 12kt gusting to 20kt. '
         'Wind shear 2000inHg from zero seven zero at 40kt. Visibility three miles. '
         'Altimeter two nine point nine two. Heavy Rain. '
         'Broken layer at 1500ft (Cumulonimbus). '
         'Occasional moderate turbulence in clouds from 5500ft to 8500ft. '
         'Light icing from 10000ft to 15000ft')
     ret = speech.taf_line(line, units)
     self.assertIsInstance(ret, str)
     self.assertEqual(ret, spoken)
def test_type_and_times(type_, start_time, end_time, prob, spoken):
    times = core.make_timestamp(start_time), core.make_timestamp(end_time)
    if prob is not None:
        prob = core.make_number(prob)
    # noinspection PyTypeChecker
    ret = speech.type_and_times(type_, *times, prob)
    assert isinstance(ret, str)
    assert ret == spoken
Beispiel #3
0
 def test_find_missing_taf_times(self):
     """
     Tests that missing forecast times can be interpretted by
     """
     good_lines = [{
         'type': 'FROM',
         'start_time': '3021',
         'end_time': '3023'
     }, {
         'type': 'FROM',
         'start_time': '3023',
         'end_time': '0105'
     }, {
         'type': 'FROM',
         'start_time': '0105',
         'end_time': '0108'
     }, {
         'type': 'FROM',
         'start_time': '0108',
         'end_time': '0114'
     }]
     for line in good_lines:
         for key in ('start_time', 'end_time'):
             line[key] = core.make_timestamp(line[key])
     bad_lines = deepcopy(good_lines)
     bad_lines[0]['start_time'] = None
     bad_lines[1]['start_time'] = None
     bad_lines[2]['end_time'] = None
     bad_lines[3]['end_time'] = None
     start, end = good_lines[0]['start_time'], good_lines[-1]['end_time']
     self.assertEqual(core.find_missing_taf_times(bad_lines, start, end),
                      good_lines)
Beispiel #4
0
def parse_in(txt: str) -> typing.Tuple[MetarData, Units]:
    """
    Parser for the International METAR variant
    """
    units = Units(**IN_UNITS)
    clean = core.sanitize_report_string(txt)
    wxresp: typing.Dict[str, typing.Any] = {'raw': txt, 'sanitized': clean}
    wxdata, wxresp['remarks'] = core.get_remarks(clean)
    wxdata, wxresp['runway_visibility'], _ = core.sanitize_report_list(wxdata)
    wxdata, wxresp['station'], wxresp['time'] = core.get_station_and_time(
        wxdata)
    if 'CAVOK' not in wxdata:
        wxdata, wxresp['clouds'] = core.get_clouds(wxdata)
    wxdata, wind_dir, wind_speed, wind_gust, wind_var = core.get_wind(
        wxdata, units)
    wxresp['wind_direction'] = wind_dir
    wxresp['wind_speed'] = wind_speed
    wxresp['wind_gust'] = wind_gust
    wxresp['wind_variable_direction'] = wind_var
    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
Beispiel #5
0
 def test_make_timestamp(self):
     """
     Tests that a report timestamp is converted into a Timestamp dataclass
     """
     today = datetime.utcnow()
     rts = today.strftime(r'%d%HZ')
     date = core.make_timestamp(rts)
     self.assertIsInstance(date, structs.Timestamp)
     self.assertEqual(date.repr, rts)
     self.assertEqual(date.dt.day, today.day)
     self.assertEqual(date.dt.hour, today.hour)
 def test_taf(self):
     """
     Tests converting a TafData report into a single spoken string
     """
     units = structs.Units(**static.NA_UNITS)
     # noinspection PyUnresolvedReferences
     empty_line = {
         k: None
         for k in structs.TafLineData.__dataclass_fields__.keys()
     }
     forecast = [
         structs.TafLineData(**{
             **empty_line,
             **line
         }) for line in (
             {
                 'type': 'FROM',
                 'start_time': core.make_timestamp('0410Z'),
                 'end_time': core.make_timestamp('0414Z'),
                 'visibility': core.make_number('3'),
                 'wind_direction': core.make_number('360'),
                 'wind_gust': core.make_number('20'),
                 'wind_speed': core.make_number('12'),
             },
             {
                 'type': 'PROB',
                 'probability': core.make_number('45'),
                 'start_time': core.make_timestamp('0412Z'),
                 'end_time': core.make_timestamp('0414Z'),
                 'visibility': core.make_number('M1/4'),
             },
         )
     ]
     # noinspection PyArgumentList
     taf = structs.TafData(raw=None,
                           remarks=None,
                           station=None,
                           time=None,
                           forecast=forecast,
                           start_time=core.make_timestamp('0410Z'),
                           end_time=core.make_timestamp('0414Z'))
     ret = speech.taf(taf, units)
     spoken = (
         "Starting on .* 4th - From 10 to 14 zulu, "
         "Winds three six zero at 12kt gusting to 20kt. Visibility three miles. "
         r"From 12 to 14 zulu, there's a 45% chance for Visibility "
         "less than one quarter of a mile")
     self.assertIsInstance(ret, str)
     assert re.match(spoken, ret)