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

Feature/runway error parse #65

Merged
merged 2 commits into from
May 20, 2024
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [1.9.0] - 2024-05-19

### Added

- When information about a runway is incomplete in a METAR, a `ParseError` is raised instead of `ValueError`.

## [1.8.2] - 2024-01-14

### Fixed
Expand Down
65 changes: 40 additions & 25 deletions metar_taf_parser/command/metar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re

from metar_taf_parser.commons import converter
from metar_taf_parser.commons.exception import ParseError
from metar_taf_parser.model.enum import DepositType, DepositCoverage
from metar_taf_parser.model.model import RunwayInfo, Metar
from metar_taf_parser.commons.i18n import _
Expand Down Expand Up @@ -41,6 +42,22 @@ def execute(self, metar: Metar, input: str):
metar.altimeter = int(converter.convert_inches_mercury_to_pascal(mercury))


def _parse_runway(matches, metar, runway):
runway.name = matches[0][0]
runway.indicator = matches[0][1]
runway.min_range = int(matches[0][2])
runway.trend = matches[0][3]
metar.add_runway_info(runway)


def _parse_runway_max_range(matches, metar, runway):
runway.name = matches[0][0]
runway.min_range = int(matches[0][1])
runway.max_range = int(matches[0][2])
runway.trend = matches[0][3]
metar.add_runway_info(runway)


class RunwayCommand:
generic_regex = r'^(R\d{2}\w?/)'
runway_max_range_regex = r'^R(\d{2}\w?)/(\d{4})V(\d{3,4})([UDN])?(FT)?'
Expand Down Expand Up @@ -79,31 +96,29 @@ def can_parse(self, input: str):
def execute(self, metar: Metar, input: str):
matches = self._runway_deposit_pattern.findall(input)
runway = RunwayInfo()
if matches:
runway.name = matches[0][0]
runway.deposit_type = DepositType(matches[0][1])
runway.coverage = DepositCoverage(matches[0][2])
runway.thickness = self.__parse_deposit_thickness(matches[0][3])
runway.braking_capacity = self.__parse_deposit_braking_capacity(matches[0][4])
metar.add_runway_info(runway)
return

matches = self._runway_pattern.findall(input)
if matches:
runway.name = matches[0][0]
runway.indicator = matches[0][1]
runway.min_range = int(matches[0][2])
runway.trend = matches[0][3]
metar.add_runway_info(runway)
return

matches = self._max_range_pattern.findall(input)
if matches:
runway.name = matches[0][0]
runway.min_range = int(matches[0][1])
runway.max_range = int(matches[0][2])
runway.trend = matches[0][3]
metar.add_runway_info(runway)
try:
if matches:
self.__parse_runway_deposit(matches, metar, runway)
return

matches = self._runway_pattern.findall(input)
if matches:
_parse_runway(matches, metar, runway)
return

matches = self._max_range_pattern.findall(input)
if matches:
_parse_runway_max_range(matches, metar, runway)
except ValueError:
raise ParseError(_("ErrorCode.IncompleteRunwayInformation"))

def __parse_runway_deposit(self, matches, metar, runway):
runway.name = matches[0][0]
runway.deposit_type = DepositType(matches[0][1])
runway.coverage = DepositCoverage(matches[0][2])
runway.thickness = self.__parse_deposit_thickness(matches[0][3])
runway.braking_capacity = self.__parse_deposit_braking_capacity(matches[0][4])
metar.add_runway_info(runway)

def __parse_deposit_thickness(self, input):
thickness = self._deposit_thickness.get(input, 'DepositThickness.default')
Expand Down
8 changes: 8 additions & 0 deletions metar_taf_parser/commons/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ class TranslationError(Exception):
def __init__(self, translation: str, message: str):
self.message = message
self.translation = translation


class ParseError(Exception):
def __init__(self, message: str):
self.__message = message

def message(self):
return self.__message
Binary file modified metar_taf_parser/locale/de/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file modified metar_taf_parser/locale/en/LC_MESSAGES/messages.mo
Binary file not shown.
4 changes: 4 additions & 0 deletions metar_taf_parser/locale/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ msgstr "The airport was not found for this message."
msgid "ErrorCode.InvalidMessage"
msgstr "The entered message is invalid."

#:
msgid "ErrorCode.IncompleteRunwayInformation"
msgstr "The runway information is incomplete and cannot be parsed."

#:
msgid "Flag.AMD"
msgstr "amended TAF"
Expand Down
Binary file modified metar_taf_parser/locale/es/LC_MESSAGES/messages.mo
Binary file not shown.
Loading
Loading