Exemplo n.º 1
0
 def test_is_unknown(self):
     """
     Tests unknown value when a string value contains only backspace characters or empty
     """
     # Unknown values
     for i in range(10):
         self.assertTrue(core.is_unknown('/' * i))
     # Full or partially known values
     for value in ('abc', '/bc', 'a/c', 'ab/', 'a//', '/b/', '//c'):
         self.assertFalse(core.is_unknown(value))
     # Bad type
     with self.assertRaises(TypeError):
         core.is_unknown(None)
Exemplo n.º 2
0
 def test_is_unknown(self):
     """
     Tests unknown value when a string value contains only backspace characters or empty
     """
     # Unknown values
     for i in range(10):
         self.assertTrue(core.is_unknown('/' * i))
     # Full or partially known values
     for value in ('abc', '/bc', 'a/c', 'ab/', 'a//', '/b/', '//c'):
         self.assertFalse(core.is_unknown(value))
     # Bad type
     with self.assertRaises(TypeError):
         core.is_unknown(None)
Exemplo n.º 3
0
def visibility(vis: str, unit: str = 'm') -> str:
    """
    Formats a visibility element into a string with both km and sm values

    Ex: 8km ( 5sm )
    """
    if vis == 'P6':
        return 'Greater than 6sm ( >9999m )'
    if vis == 'M1/4':
        return 'Less than .25sm ( <0400m )'
    if '/' in vis and not core.is_unknown(vis):
        vis = float(vis[:vis.find('/')]) / int(vis[vis.find('/') + 1:])
    try:
        float(vis)
    except ValueError:
        return ''
    if unit == 'm':
        converted = float(vis) * 0.000621371
        converted = str(round(converted, 1)).replace('.0', '') + 'sm'
        vis = str(round(int(vis) / 1000, 1)).replace('.0', '')
        unit = 'km'
    elif unit == 'sm':
        converted = float(vis) / 0.621371
        converted = str(round(converted, 1)).replace('.0', '') + 'km'
        vis = str(vis).replace('.0', '')
    else:
        return ''
    return vis + unit + ' (' + converted + ')'
Exemplo n.º 4
0
def visibility(vis: str, unit: str = 'm') -> str:
    """
    Format visibility details into a spoken word string
    """
    if core.is_unknown(vis):
        return 'Visibility Unknown'
    elif vis.startswith('M'):
        vis = 'less than ' + numbers(remove_leading_zeros(vis[1:]))
    elif vis.startswith('P'):
        vis = 'greater than ' + numbers(remove_leading_zeros(vis[1:]))
    elif '/' in vis:
        vis = unpack_fraction(vis)
        vis = ' and '.join(
            [numbers(remove_leading_zeros(n)) for n in vis.split(' ')])
    else:
        vis = translate.visibility(vis, unit=unit)
        if unit == 'm':
            unit = 'km'
        vis = vis[:vis.find(' (')].lower().replace(unit, '').strip()
        vis = numbers(remove_leading_zeros(vis))
    ret = 'Visibility ' + vis
    if unit in SPOKEN_UNITS:
        ret += ' ' + SPOKEN_UNITS[unit]
        if not (('one half' in vis and ' and ' not in vis) or 'of a' in vis):
            ret += 's'
    else:
        ret += unit
    return ret
Exemplo n.º 5
0
def temperature(header: str, temp: str, unit: str = 'C') -> str:
    """
    Format temperature details into a spoken word string
    """
    if core.is_unknown(temp):
        return header + ' Unknown'
    if unit in SPOKEN_UNITS:
        unit = SPOKEN_UNITS[unit]
    temp = numbers(remove_leading_zeros(temp))
    use_s = '' if temp in ('one', 'minus one') else 's'
    return ' '.join((header, temp, 'degree' + use_s, unit))
Exemplo n.º 6
0
def altimeter(alt: str, unit: str = 'inHg') -> str:
    """
    Format altimeter details into a spoken word string
    """
    ret = 'Altimeter '
    if core.is_unknown(alt):
        ret += 'Unknown'
    elif unit == 'inHg':
        ret += numbers(alt[:2]) + ' point ' + numbers(alt[2:])
    elif unit == 'hPa':
        ret += numbers(alt)
    return ret