Skip to content

Commit

Permalink
Raise a custom exception when runway information contains incomplete …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
mivek committed May 18, 2024
1 parent d99973b commit c4b005e
Show file tree
Hide file tree
Showing 21 changed files with 634 additions and 174 deletions.
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.
230 changes: 223 additions & 7 deletions metar_taf_parser/locale/es/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ msgstr "cubierto"

#:
msgid "CloudQuantity.SKC"
msgstr "cielo claro"
msgstr "cielo despejado"

#:
msgid "CloudType.AC"
Expand Down Expand Up @@ -66,6 +66,10 @@ msgstr "Torrecumulus"
msgid "DepositBrakingCapacity.//"
msgstr "no reportado"

#:
msgid "DepositCoverage.NOT_REPORTED"
msgstr "no reportado"

#:
msgid "DepositCoverage.LESS_10"
msgstr "menos de 10%"
Expand All @@ -91,27 +95,27 @@ msgid "DepositThickness.00"
msgstr "menos de 1 mm"

#:
msgid "DepositThickness.THICKNESS_10"
msgid "DepositThickness.92"
msgstr "10 cm"

#:
msgid "DepositThickness.THICKNESS_15"
msgid "DepositThickness.93"
msgstr "15 cm"

#:
msgid "DepositThickness.THICKNESS_20"
msgid "DepositThickness.94"
msgstr "20 cm"

#:
msgid "DepositThickness.THICKNESS_25"
msgid "DepositThickness.95"
msgstr "25 cm"

#:
msgid "DepositThickness.THICKNESS_30"
msgid "DepositThickness.96"
msgstr "30 cm"

#:
msgid "DepositThickness.THICKNESS_35"
msgid "DepositThickness.97"
msgstr "35 cm"

#:
Expand All @@ -122,6 +126,10 @@ msgstr "40 cm o más"
msgid "DepositThickness.99"
msgstr "cerrado"

#:
msgid "DepositThickness.default"
msgstr "{0} mm"

#:
msgid "DepositType.NOT_REPORTED"
msgstr "no reportado"
Expand Down Expand Up @@ -166,6 +174,66 @@ msgstr "huellas o cumbres congeladas"
msgid "DepositType.SLUSH"
msgstr "nieve derretida"

#:
msgid "Descriptive.PR"
msgstr "parcial"

#:
msgid "Descriptive.TS"
msgstr "tormenta"

#:
msgid "ErrorCode.InvalidMessage"
msgstr "El mensaje ingresado es inválido."

#:
msgid "Flag.AMD"
msgstr "TAF modificado"

#:
msgid "Flag.AUTO"
msgstr "METAR automatizado"

#:
msgid "Flag.CNL"
msgstr "TAF cancelado"

#:
msgid "Indicator.M"
msgstr "menos que"

#:
msgid "Indicator.P"
msgstr "más que"

#:
msgid "Intensity.RE"
msgstr "reciente"

#:
msgid "Phenomenon.DS"
msgstr "tormenta de polvo"

#:
msgid "Phenomenon.FG"
msgstr "niebla"

#:
msgid "Phenomenon.FU"
msgstr "humo"

#:
msgid "Phenomenon.RA"
msgstr "lluvia"

#:
msgid "Phenomenon.SA"
msgstr "arena"

#:
msgid "Phenomenon.SN"
msgstr "nieve"

#:
msgid "Phenomenon.SS"
msgstr "tormenta de arena"
Expand Down Expand Up @@ -254,3 +322,151 @@ msgstr "pronóstico"
msgid "Remark.FUNNELCLOUD"
msgstr "nube embudo"

#:
msgid "Remark.NXT"
msgstr "siguiente"

#:
msgid "Remark.TORNADO"
msgstr "tornado"

#:
msgid "MetarFacade.InvalidIcao"
msgstr "El código Icao no es válido."

#:
msgid "Converter.E"
msgstr "Este"

#:
msgid "Converter.N"
msgstr "Norte"

#:
msgid "Converter.NE"
msgstr "Noreste"

#:
msgid "Converter.NW"
msgstr "Noroeste"

#:
msgid "Converter.S"
msgstr "Sur"

#:
msgid "Converter.SE"
msgstr "Sureste"

#:
msgid "Converter.VRB"
msgstr "Variable"

#:
msgid "Converter.W"
msgstr "Oeste"

#:
msgid "WeatherChangeType.INTER"
msgstr "Intermitente"

#:
msgid "WeatherChangeType.TEMPO"
msgstr "Temporal"

#:
msgid "WeatherChangeType.PROB"
msgstr "Probabilidad"

#:
msgid "TimeIndicator.FM"
msgstr "Desde"

#:
msgid "TimeIndicator.TL"
msgstr "hasta"

#:
msgid "ToString.airport"
msgstr "aeropuerto"

#:
msgid "ToString.clouds"
msgstr "nubes"

#:
msgid "ToString.day.month"
msgstr "día del mes"

#:
msgid "ToString.day.hour"
msgstr "hora del día"

#:
msgid "ToString.height.feet"
msgstr "altura (cm)"

#:
msgid "ToString.height.meter"
msgstr "altura (m)"

#:
msgid "ToString.intensity"
msgstr "intensidad"

#:
msgid "ToString.indicator"
msgstr "indicador"

#:
msgid "ToString.message"
msgstr "mensaje original"

#:
msgid "ToString.name"
msgstr "nombre"

#:
msgid "ToString.phenomenons"
msgstr "fenómenos"

#:
msgid "ToString.probability"
msgstr "probabilidad"

#:
msgid "ToString.quantity"
msgstr "cantidad"

#:
msgid "ToString.report.time"
msgstr "hora del informe"

#:
msgid "ToString.temperature"
msgstr "temperatura (°C)"

#:
msgid "ToString.temperature.max"
msgstr "temperatura máxima (°C)"

#:
msgid "ToString.temperature.min"
msgstr "temperatura mínima (°C)"

#:
msgid "ToString.type"
msgstr "tipo"

#:
msgid "ToString.wind.direction"
msgstr "dirección"

#:
msgid "ToString.wind.direction.degrees"
msgstr "dirección (grados)"

#:
msgid "TurbulenceIntensity.X"
msgstr "Turbulencia extrema"

Binary file modified metar_taf_parser/locale/fr/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit c4b005e

Please sign in to comment.