def parse_record_bom(rec: Dict) -> Dict: """Parse CSV records in BOM format""" timezone = pytz.timezone(STATION_TIMEZONE_MAP[rec["station_id"]]) observation_time = parse_date(rec["observation_time"], is_utc=True, dayfirst=False).astimezone(timezone) return { "observation_time": observation_time, "station_id": rec["station_id"], "temp_apparent": float(rec["temp_apparent"].strip()) if is_number(rec["temp_apparent"]) else None, "temp_air": float(rec["temp_air"].strip()) if is_number(rec["temp_air"]) else None, "press_qnh": None, "wind_dir": None, "wind_spd": None, "cloud": None, "cloud_type": None, "humidity": float(rec["humidity"].strip()) if is_number(rec["humidity"]) else None, "wind_gust": None, }
def _validate_eoi_quantity(cls, value: Any, values: Dict[str, Any]) -> Optional[float]: """Calculates energy value""" generated = values["generated"] energy_quantity: Optional[float] = None if generated and is_number(generated): energy_quantity = float(generated) / 4 return energy_quantity
def get_state_for_prefix(prefix: str) -> str: """Returns a state for a prefix""" if not is_number(prefix): raise Exception( "get_state_for_prefix: {} is not a number".format(prefix)) if prefix[:1] not in POSTCODE_STATE_PREFIXES.keys(): raise Exception( "get_state_for_prefix: could not find state for prefix {}".format( prefix)) return POSTCODE_STATE_PREFIXES[prefix[:1]]
def get_network_region(network_region: str) -> Optional[str]: """ Trim the numbers off the end of nem regions """ if network_region and type(network_region) is str and len( network_region) > 1: if is_number(network_region[-1:]): return network_region[:-1] if network_region.strip().upper() == "WEM": return None return network_region return None
def _clean_expected_closure_year(closure_year: Union[str, int]) -> Optional[int]: """Clean up expected closure year because sometimes they just put comments in the field""" if is_number(closure_year): return int(closure_year) return None
def _parse_dirlisting_filesize(cls, value: str | int | float) -> Optional[int]: if is_number(value): return value return None