Example #1
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 += core.spoken_number(str(alt.value).ljust(5, "0"), True)
    elif unit == "hPa":
        ret += core.spoken_number(str(alt.value).zfill(4), True)
    return ret
Example #2
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.base.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
Example #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], True) if spoken else shear[1][:3]
    return f"Wind shear {int(shear[0])*100}{unit_alt} from {wdir} at {shear[1][3:]}{unit_wind}"
Example #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)