avwx.parsing.sanitization.cleaners.replace
Cleaners for elements that should be replaced.
1"""Cleaners for elements that should be replaced.""" 2 3from avwx.parsing.sanitization.base import CleanItem 4 5# These replacement dicts are applied when the report is still a string 6 7_SHARED = { 8 "!": "1", 9 "@": "2", 10 "#": "3", 11 "%": "5", 12 "^": "6", 13 "&": "7", 14 "*": "8", 15 "?": " ", 16 '"': "", 17 "'": "", 18 "`": "", 19 ".": "", 20 "(": " ", 21 ")": " ", 22 ";": " ", 23} 24 25_WIND = { 26 "MISSINGKT": "", 27 " 0I0": " 090", 28 "NOSIGKT ": "KT NOSIG ", 29 "KNOSIGT ": "KT NOSIG ", 30 "/VRB": " VRB", 31 "CALMKT ": "CALM ", 32 "CLMKT ": "CALM ", 33 "CLRKT ": "CALM ", 34} 35 36_VISIBILITY = { 37 " <1/": " M1/", # <1/4SM <1/8SM 38 "/04SM": "/4SM", 39 "/4SSM": "/4SM", 40 "/08SM": "/8SM", 41 " /34SM": "3/4SM", 42 " 3/SM": " 3/4SM", 43 "PQ6SM ": "P6SM ", 44 "P6000F ": "P6000FT ", 45 "P6000FTQ ": "P6000FT ", 46} 47 48_CLOUD = { 49 " C A V O K ": " CAVOK ", 50 "N0SIG": "NOSIG", 51 "SCATTERED": "SCT", 52 "BROKEN": "BKN", 53 "OVERCAST": "OVC", 54} 55 56CURRENT = _SHARED | _WIND | _VISIBILITY | _CLOUD 57 58 59# These are item replacements after the report has been split 60 61ITEM_REPL = {"CALM": "00000KT", "A01": "AO1", "A02": "AO2", "PROB3O": "PROB30"} 62 63 64class ReplaceItem(CleanItem): 65 """Replace report elements after splitting.""" 66 67 def can_handle(self, item: str) -> bool: 68 return item in ITEM_REPL 69 70 def clean(self, item: str) -> str: 71 return ITEM_REPL[item]
CURRENT =
{'!': '1', '@': '2', '#': '3', '%': '5', '^': '6', '&': '7', '*': '8', '?': ' ', '"': '', "'": '', '`': '', '.': '', '(': ' ', ')': ' ', ';': ' ', 'MISSINGKT': '', ' 0I0': ' 090', 'NOSIGKT ': 'KT NOSIG ', 'KNOSIGT ': 'KT NOSIG ', '/VRB': ' VRB', 'CALMKT ': 'CALM ', 'CLMKT ': 'CALM ', 'CLRKT ': 'CALM ', ' <1/': ' M1/', '/04SM': '/4SM', '/4SSM': '/4SM', '/08SM': '/8SM', ' /34SM': '3/4SM', ' 3/SM': ' 3/4SM', 'PQ6SM ': 'P6SM ', 'P6000F ': 'P6000FT ', 'P6000FTQ ': 'P6000FT ', ' C A V O K ': ' CAVOK ', 'N0SIG': 'NOSIG', 'SCATTERED': 'SCT', 'BROKEN': 'BKN', 'OVERCAST': 'OVC'}
ITEM_REPL =
{'CALM': '00000KT', 'A01': 'AO1', 'A02': 'AO2', 'PROB3O': 'PROB30'}
65class ReplaceItem(CleanItem): 66 """Replace report elements after splitting.""" 67 68 def can_handle(self, item: str) -> bool: 69 return item in ITEM_REPL 70 71 def clean(self, item: str) -> str: 72 return ITEM_REPL[item]
Replace report elements after splitting.