def get_altimeter(wxdata: [str], units: Units, version: str = "NA") -> ([str], Number): """ Returns the report list and the removed altimeter item Version is 'NA' (North American / default) or 'IN' (International) """ if not wxdata: return wxdata, None altimeter = "" target = wxdata[-1] # Handle QNH prefix: buf = 1 if target.startswith("QNH"): buf = 3 target = target.replace("QNH", "Q") if version == "NA": # Version target if target[0] == "A": altimeter = wxdata.pop()[buf:] # Other version but prefer normal if available elif target[0] == "Q": if len(wxdata) > 1 and wxdata[-2][0] == "A": wxdata.pop() altimeter = wxdata.pop()[buf:] else: units.altimeter = "hPa" altimeter = wxdata.pop()[buf:].lstrip(".") # Else grab the digits elif len(target) == 4 and target.isdigit(): altimeter = wxdata.pop() elif version == "IN": # Version target if target[0] == "Q": altimeter = wxdata.pop()[buf:].lstrip(".") if "/" in altimeter: altimeter = altimeter[:altimeter.find("/")] # Other version but prefer normal if available elif target[0] == "A": if len(wxdata) > 1 and wxdata[-2][0] == "Q": wxdata.pop() altimeter = wxdata.pop()[buf:] else: units.altimeter = "inHg" altimeter = wxdata.pop()[buf:] # Some stations report both, but we only need one if wxdata and (wxdata[-1][0] == "A" or wxdata[-1][0] == "Q"): wxdata.pop() # convert to Number altimeter = altimeter.replace("/", "") if not altimeter: return wxdata, None if units.altimeter == "inHg": value = altimeter[:2] + "." + altimeter[2:] else: value = altimeter return wxdata, make_number(value, altimeter)
def get_altimeter(wxdata: [str], units: Units, version: str = 'NA') -> ([str], Number): """ Returns the report list and the removed altimeter item Version is 'NA' (North American / default) or 'IN' (International) """ if not wxdata: return wxdata, None altimeter = '' target = wxdata[-1] if version == 'NA': # Version target if target[0] == 'A': altimeter = wxdata.pop()[1:] # Other version but prefer normal if available elif target[0] == 'Q': if len(wxdata) > 1 and wxdata[-2][0] == 'A': wxdata.pop() altimeter = wxdata.pop()[1:] else: units.altimeter = 'hPa' altimeter = wxdata.pop()[1:].lstrip('.') # Else grab the digits elif len(target) == 4 and target.isdigit(): altimeter = wxdata.pop() elif version == 'IN': # Version target if target[0] == 'Q': altimeter = wxdata.pop()[1:].lstrip('.') if '/' in altimeter: altimeter = altimeter[:altimeter.find('/')] # Other version but prefer normal if available elif target[0] == 'A': if len(wxdata) > 1 and wxdata[-2][0] == 'Q': wxdata.pop() altimeter = wxdata.pop()[1:] else: units.altimeter = 'inHg' altimeter = wxdata.pop()[1:] #Some stations report both, but we only need one if wxdata and (wxdata[-1][0] == 'A' or wxdata[-1][0] == 'Q'): wxdata.pop() # convert to Number if not altimeter: return wxdata, None altimeter = altimeter.replace('/', '') if units.altimeter == 'inHg': value = altimeter[:2] + '.' + altimeter[2:] else: value = altimeter return wxdata, make_number(value, altimeter)
def get_altimeter(wxdata: [str], units: Units, version: str = 'NA') -> ([str], Number): """ Returns the report list and the removed altimeter item Version is 'NA' (North American / default) or 'IN' (International) """ if not wxdata: return wxdata, None altimeter = '' target = wxdata[-1] if version == 'NA': # Version target if target[0] == 'A': altimeter = wxdata.pop()[1:] # Other version but prefer normal if available elif target[0] == 'Q': if len(wxdata) > 1 and wxdata[-2][0] == 'A': wxdata.pop() altimeter = wxdata.pop()[1:] else: units.altimeter = 'hPa' altimeter = wxdata.pop()[1:].lstrip('.') # Else grab the digits elif len(target) == 4 and target.isdigit(): altimeter = wxdata.pop() elif version == 'IN': # Version target if target[0] == 'Q': altimeter = wxdata.pop()[1:].lstrip('.') if '/' in altimeter: altimeter = altimeter[:altimeter.find('/')] # Other version but prefer normal if available elif target[0] == 'A': if len(wxdata) > 1 and wxdata[-2][0] == 'Q': wxdata.pop() altimeter = wxdata.pop()[1:] else: units.altimeter = 'inHg' altimeter = wxdata.pop()[1:] #Some stations report both, but we only need one if wxdata and (wxdata[-1][0] == 'A' or wxdata[-1][0] == 'Q'): wxdata.pop() # convert to Number if not altimeter: return wxdata, None altimeter = altimeter.replace('/', '') if units.altimeter == 'inHg': value = altimeter[:2] + '.' + altimeter[2:] else: value = altimeter return wxdata, make_number(value, altimeter)
def get_altimeter( data: List[str], units: Units, version: str = "NA" ) -> Tuple[List[str], Number]: """Returns the report list and the removed altimeter item Version is 'NA' (North American / default) or 'IN' (International) """ values = [] for _ in range(2): if not data: break value = parse_altimeter(data[-1]) if value is None: break values.append(value) data.pop(-1) if not values: return data, None values.sort(key=lambda x: x.value) altimeter = values[0 if version == "NA" else -1] units.altimeter = "inHg" if altimeter.value < 100 else "hPa" return data, altimeter