Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather wx #122

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions ogn/parser/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime

from ogn.parser.utils import createTimestamp, parseAngle, KNOTS_TO_MS, KPH_TO_MS, FEETS_TO_METER, INCH_TO_MM, fahrenheit_to_celsius, CheapRuler, normalized_quality
from ogn.parser.pattern import PATTERN_APRS, PATTERN_APRS_POSITION, PATTERN_APRS_POSITION_WEATHER, PATTERN_APRS_STATUS, PATTERN_SERVER
from ogn.parser.pattern import PATTERN_APRS, PATTERN_APRS_POSITION, PATTERN_APRS_POSITION_WEATHER, PATTERN_APRS_POSITION_WEATHER_WX, PATTERN_APRS_STATUS, PATTERN_SERVER
from ogn.parser.exceptions import AprsParseError

from ogn.parser.aprs_comment.ogn_parser import OgnParser
Expand Down Expand Up @@ -76,13 +76,14 @@ def parse_aprs(message, reference_timestamp=None):
else:
match = re.search(PATTERN_APRS, message)
if match:
aprs_type = 'position' if match.group('aprs_type') == '/' else 'status' if match.group('aprs_type') == '>' else 'unknown'
result.update({'aprs_type': aprs_type})
result.update({'aprs_type': 'unknown'})
aprs_type = 'position' if match.group('aprs_type') == '/' else 'status' if match.group('aprs_type') == '>' else 'weather_wx' if match.group('aprs_type') == ';' else 'unknown'
aprs_body = match.group('aprs_body')
if aprs_type == 'position':
match_position = re.search(PATTERN_APRS_POSITION, aprs_body)
if match_position:
result.update({
'aprs_type': 'position',
'name': match.group('callsign'),
'dstcall': match.group('dstcall'),
'relay': match.group('relay') if match.group('relay') else None,
Expand Down Expand Up @@ -132,19 +133,50 @@ def parse_aprs(message, reference_timestamp=None):
'comment': match_position_weather.group('comment') if match_position_weather.group('comment') else "",
})
return result

raise AprsParseError(message)
elif aprs_type == 'status':
match_status = re.search(PATTERN_APRS_STATUS, aprs_body)
if match_status:
result.update({
'aprs_type': 'status',
'name': match.group('callsign'),
'dstcall': match.group('dstcall'),
'receiver_name': match.group('receiver'),
'timestamp': createTimestamp(match_status.group('time'), reference_timestamp),
'comment': match_status.group('comment') if match_status.group('comment') else ""})
else:
raise NotImplementedError(message)
elif aprs_type == 'weather_wx':
match_position_weather = re.search(PATTERN_APRS_POSITION_WEATHER_WX, aprs_body)
if match_position_weather:
result.update({
'aprs_type': 'position_weather',

'name': match_position_weather.group('callsign').strip(),
'dstcall': match.group('dstcall'),
'relay': match.group('relay') if match.group('relay') else None,
'receiver_name': match.group('receiver'),
'timestamp': createTimestamp(match_position_weather.group('time'), reference_timestamp),
'latitude': parseAngle('0' + match_position_weather.group('latitude')) * # noqa: W504
(-1 if match_position_weather.group('latitude_sign') == 'S' else 1),
'symboltable': match_position_weather.group('symbol_table'),
'longitude': parseAngle(match_position_weather.group('longitude')) * # noqa: W504
(-1 if match_position_weather.group('longitude_sign') == 'W' else 1),
'symbolcode': match_position_weather.group('symbol'),

'wind_direction': int(match_position_weather.group('wind_direction')) if match_position_weather.group('wind_direction') != None else None,
'wind_speed': int(match_position_weather.group('wind_speed')) * KNOTS_TO_MS / KPH_TO_MS if match_position_weather.group('wind_speed') != None else None,
'wind_speed_peak': int(match_position_weather.group('wind_speed_peak')) * KNOTS_TO_MS / KPH_TO_MS if match_position_weather.group('wind_speed_peak') != None else None,
'temperature': fahrenheit_to_celsius(float(match_position_weather.group('temperature'))) if match_position_weather.group('temperature') != None else None,
'rainfall_1h': int(match_position_weather.group('rainfall_1h')) / 100.0 * INCH_TO_MM if match_position_weather.group('rainfall_1h') else None,
'rainfall_24h': int(match_position_weather.group('rainfall_24h')) / 100.0 * INCH_TO_MM if match_position_weather.group('rainfall_24h') else None,
'humidity': int(match_position_weather.group('humidity')) * 0.01 if match_position_weather.group('humidity') else None,
'barometric_pressure': int(match_position_weather.group('barometric_pressure'))/10 if match_position_weather.group('barometric_pressure') else None,

'comment': match_position_weather.group('comment') if match_position_weather.group('comment') else "",
})

return result
else:
raise AprsParseError(message)

Expand Down
24 changes: 24 additions & 0 deletions ogn/parser/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@
PATTERN_APRS_POSITION = re.compile(r"^(?P<time>(([0-1]\d|2[0-3])[0-5]\d[0-5]\dh|([0-2]\d|3[0-1])([0-1]\d|2[0-3])[0-5]\dz))(?P<latitude>9000\.00|[0-8]\d{3}\.\d{2})(?P<latitude_sign>N|S)(?P<symbol_table>.)(?P<longitude>18000\.00|1[0-7]\d{3}\.\d{2}|0\d{4}\.\d{2})(?P<longitude_sign>E|W)(?P<symbol>.)(?P<course_extension>(?P<course>\d{3})/(?P<ground_speed>\d{3}))?(/A=(?P<altitude>(-\d{5}|\d{6})))?(?P<pos_extension>\s!W((?P<latitude_enhancement>\d)(?P<longitude_enhancement>\d))!)?(?:\s(?P<comment>.*))?$")
PATTERN_APRS_POSITION_WEATHER = re.compile(r"^(?P<time>(([0-1]\d|2[0-3])[0-5]\d[0-5]\dh|([0-2]\d|3[0-1])([0-1]\d|2[0-3])[0-5]\dz))(?P<latitude>9000\.00|[0-8]\d{3}\.\d{2})(?P<latitude_sign>N|S)(?P<symbol_table>.)(?P<longitude>18000\.00|1[0-7]\d{3}\.\d{2}|0\d{4}\.\d{2})(?P<longitude_sign>E|W)(?P<symbol>.)(?P<wind_direction>(\d{3}|\.{3}))/(?P<wind_speed>(\d{3}|\.{3}))g(?P<wind_speed_peak>(\d{3}|\.{3}))t(?P<temperature>(\d{3}|\.{3}))(r(?P<rainfall_1h>\d{3}))?(p(?P<rainfall_24h>\d{3}))?(h(?P<humidity>\d{2}))?(b(?P<barometric_pressure>\d{5}))?(?:\s(?P<comment>.*))?$")
PATTERN_APRS_STATUS = re.compile(r"^(?P<time>(([0-1]\d|2[0-3])[0-5]\d[0-5]\dh|([0-2]\d|3[0-1])([0-1]\d|2[0-3])[0-5]\dz))\s(?P<comment>.*)$")
PATTERN_APRS_POSITION_WEATHER_WX = re.compile(r"""
^(?P<callsign>.+?)\*
(?P<time>(([0-1]\d|2[0-3])[0-5]\d[0-5]\dh|([0-2]\d|3[0-1])([0-1]\d|2[0-3])[0-5]\dz))
(?P<latitude>9000\.00|[0-8]\d{3}\.\d{2})
(?P<latitude_sign>N|S)
(?P<symbol_table>.)
(?P<longitude>18000\.00|1[0-7]\d{3}\.\d{2}|0\d{4}\.\d{2})
(?P<longitude_sign>E|W)
(?P<symbol>_)
(?P<wind_direction>(\d{3}))/
(?P<wind_speed>(\d{3}))
(?:c(?P<wind_direction1>[\d]+)?)?
(?:s(?P<wind_speed2>[\d]+)?)?
(?:g(?P<wind_speed_peak>[\d]+)?)?
(?:t(?P<temperature>[\d]+)?)?
(?:r(?P<rainfall_1h>[\d]+)?)?
(?:p(?P<rainfall_24h>[\d]+)?)?
(?:l(?P<luminosity>[\d]+)?)?
(?:L(?P<luminosity2>[\d]+)?)?
(?:P(?P<rain_since_midnight>[\d]+)?)?
(?:h(?P<humidity>[\d]+)?)?
(?:b(?P<barometric_pressure>[\d]+)?)?
(?P<comment>.*)
$""", re.VERBOSE | re.MULTILINE)

PATTERN_SERVER = re.compile(r"^# aprsc (?P<version>[a-z0-9\.\-]+) (?P<timestamp>\d+ [A-Za-z]+ \d+ \d{2}:\d{2}:\d{2} GMT) (?P<server>[A-Z0-9]+) (?P<ip_address>\d+\.\d+\.\d+\.\d+):(?P<port>\d+)$")

Expand Down