avwx.parsing.sanitization.cleaners.visibility

Cleaners for visibility elements.

 1"""Cleaners for visibility elements."""
 2
 3from itertools import permutations
 4
 5from avwx.parsing.core import is_runway_visibility
 6from avwx.parsing.sanitization.base import CleanItem
 7
 8VIS_PERMUTATIONS = ["".join(p) for p in permutations("P6SM")]
 9VIS_PERMUTATIONS.remove("6MPS")
10VIS_PERMUTATIONS += ["6+SM"]
11
12
13class VisibilityGreaterThan(CleanItem):
14    """Fix inconsistent 'P6SM'.
15    Ex: TP6SM or 6PSM -> P6SM
16    """
17
18    def can_handle(self, item: str) -> bool:
19        return len(item) > 3 and item[-4:] in VIS_PERMUTATIONS
20
21    def clean(self, _: str) -> str:
22        return "P6SM"
23
24
25class RunwayVisibilityUnit(CleanItem):
26    """Fix RVR where FT unit is cut short."""
27
28    def can_handle(self, item: str) -> bool:
29        return is_runway_visibility(item) and item.endswith("F")
30
31    def clean(self, item: str) -> str:
32        return f"{item}T"
VIS_PERMUTATIONS = ['P6SM', 'P6MS', 'PS6M', 'PSM6', 'PM6S', 'PMS6', '6PSM', '6PMS', '6SPM', '6SMP', '6MSP', 'SP6M', 'SPM6', 'S6PM', 'S6MP', 'SMP6', 'SM6P', 'MP6S', 'MPS6', 'M6PS', 'M6SP', 'MSP6', 'MS6P', '6+SM']
class VisibilityGreaterThan(avwx.parsing.sanitization.cleaners.base.CleanItem):
14class VisibilityGreaterThan(CleanItem):
15    """Fix inconsistent 'P6SM'.
16    Ex: TP6SM or 6PSM -> P6SM
17    """
18
19    def can_handle(self, item: str) -> bool:
20        return len(item) > 3 and item[-4:] in VIS_PERMUTATIONS
21
22    def clean(self, _: str) -> str:
23        return "P6SM"

Fix inconsistent 'P6SM'. Ex: TP6SM or 6PSM -> P6SM

def can_handle(self, item: str) -> bool:
19    def can_handle(self, item: str) -> bool:
20        return len(item) > 3 and item[-4:] in VIS_PERMUTATIONS

Return True if the element can and needs to be cleaned.

def clean(self, _: str) -> str:
22    def clean(self, _: str) -> str:
23        return "P6SM"

Clean the raw string.

class RunwayVisibilityUnit(avwx.parsing.sanitization.cleaners.base.CleanItem):
26class RunwayVisibilityUnit(CleanItem):
27    """Fix RVR where FT unit is cut short."""
28
29    def can_handle(self, item: str) -> bool:
30        return is_runway_visibility(item) and item.endswith("F")
31
32    def clean(self, item: str) -> str:
33        return f"{item}T"

Fix RVR where FT unit is cut short.

def can_handle(self, item: str) -> bool:
29    def can_handle(self, item: str) -> bool:
30        return is_runway_visibility(item) and item.endswith("F")

Return True if the element can and needs to be cleaned.

def clean(self, item: str) -> str:
32    def clean(self, item: str) -> str:
33        return f"{item}T"

Clean the raw string.