-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunwayvisualrange.py
45 lines (38 loc) · 1.37 KB
/
runwayvisualrange.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import re
from aviation_weather.components import Component
from aviation_weather.exceptions import RunwayVisualRangeDecodeError
class RunwayVisualRange(Component):
"""Represents the runway visual range"""
def __init__(self, raw):
"""Parse `raw` to create a new RunwayVisualRange object.
Args:
raw (str): The runway visual range to be parsed.
Raises:
RunwayVisualRangeDecodeError: If `raw` could not be parsed.
"""
m = re.search(
r"\bR(?P<runway>\d{2}[LRC]?)/(?P<d_min>[PM]?\d{4})"
r"(?:V(?P<d_max>[PM]?\d{4}))?(?P<unit>FT)?(?P<trend>[UND])?\b",
raw
)
if not m:
raise RunwayVisualRangeDecodeError("RunwayVisualRange(%r) could not be parsed" % raw)
self.runway = m.group("runway")
if m.group("d_max"):
self.distance = (m.group("d_min"), m.group("d_max"))
else:
self.distance = m.group("d_min")
self.unit = m.group("unit") or "m"
self.trend = m.group("trend")
@property
def raw(self):
raw = "R" + self.runway + "/"
if isinstance(self.distance, tuple):
raw += "V".join(self.distance)
else:
raw += self.distance
if self.unit != "m":
raw += self.unit
if self.trend:
raw += self.trend
return raw