Пример #1
0
def visibility(vis: Number, unit: str = "m") -> str:
    """
    Format visibility details into a spoken word string
    """
    if not vis:
        return "Visibility unknown"
    if vis.value is None or "/" in vis.repr:
        ret_vis = vis.spoken
    else:
        ret_vis = translate.visibility(vis, unit=unit)
        if unit == "m":
            unit = "km"
        ret_vis = ret_vis[:ret_vis.find(" (")].lower().replace(unit,
                                                               "").strip()
        ret_vis = _core.spoken_number(_core.remove_leading_zeros(ret_vis))
    ret = "Visibility " + ret_vis
    if unit in SPOKEN_UNITS:
        if "/" in vis.repr and "half" not in ret:
            ret += " of a"
        ret += " " + SPOKEN_UNITS[unit]
        if not (("one half" in ret and " and " not in ret) or "of a" in ret):
            ret += "s"
    else:
        ret += unit
    return ret
Пример #2
0
def altimeter(alt: Number, unit: str = "inHg") -> str:
    """
    Format altimeter details into a spoken word string
    """
    ret = "Altimeter "
    if not alt:
        ret += "unknown"
    elif unit == "inHg":
        ret += f"{_core.spoken_number(alt.repr[:2])} point {_core.spoken_number(alt.repr[2:])}"
    elif unit == "hPa":
        ret += _core.spoken_number(alt.repr)
    return ret
Пример #3
0
def wind_shear(
    shear: str, unit_alt: str = "ft", unit_wind: str = "kt", spoken: bool = False
) -> str:
    """
    Translate wind shear into a readable string

    Ex: Wind shear 2000ft from 140 at 30kt
    """
    if not shear or "WS" not in shear or "/" not in shear:
        return ""
    shear = shear[2:].rstrip(unit_wind.upper()).split("/")
    wdir = _core.spoken_number(shear[1][:3]) if spoken else shear[1][:3]
    return f"Wind shear {int(shear[0])*100}{unit_alt} from {wdir} at {shear[1][3:]}{unit_wind}"
Пример #4
0
 def test_spoken_number(self):
     """
     Tests converting digits into spoken values
     """
     for num, spoken in (
         ("1", "one"),
         ("5", "five"),
         ("20", "two zero"),
         ("937", "nine three seven"),
         ("4.8", "four point eight"),
         ("29.92", "two nine point nine two"),
         ("1/2", "one half"),
         ("3 3/4", "three and three quarters"),
     ):
         self.assertEqual(_core.spoken_number(num), spoken)
Пример #5
0
 def test_spoken_number(self):
     """
     Tests converting digits into spoken values
     """
     for num, spoken in (
         ('1', 'one'),
         ('5', 'five'),
         ('20', 'two zero'),
         ('937', 'nine three seven'),
         ('4.8', 'four point eight'),
         ('29.92', 'two nine point nine two'),
         ('1/2', 'one half'),
         ('3 3/4', 'three and three quarters'),
     ):
         self.assertEqual(_core.spoken_number(num), spoken)