From 63eef590605a03074282f65d0b411afa898f6be0 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Wed, 17 Mar 2021 17:40:45 -0400 Subject: [PATCH] Fix null visibility in METAR (#1079) * Fix null visibility in METAR * Report the text in units from the METAR --- app/Support/Metar.php | 16 +++++++++------- tests/MetarTest.php | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/Support/Metar.php b/app/Support/Metar.php index 25c573cf..27128504 100644 --- a/app/Support/Metar.php +++ b/app/Support/Metar.php @@ -879,8 +879,8 @@ class Metar implements \ArrayAccess $this->set_result_value('cavok', true); $this->method += 4; // can skip the next 4 methods: visibility_min, runway_vr, present_weather, clouds } - } /*elseif ($found[1] === '////') { - }*/ // information not available + } elseif ($found[1] === '////') { + } // information not available else { $prefix = ''; @@ -994,8 +994,10 @@ class Metar implements \ArrayAccess } $unit = 'meter'; + $report_unit = 'm'; if (isset($found[6]) && $found[6] === 'FT') { $unit = 'feet'; + $report_unit = 'nmi'; } $observed = [ @@ -1030,15 +1032,15 @@ class Metar implements \ArrayAccess if (!empty($observed['runway'])) { $report = []; if ($observed['variable'] !== null) { - $report[] = $observed['variable']['nmi'].' nmi'; + $report[] = $observed['variable'][$report_unit].$report_unit; } elseif ($observed['interval_min'] !== null && $observed['interval_max'] !== null) { if (isset(static::$rvr_prefix_codes[$observed['variable_prefix']])) { - $report[] = 'varying from a min. of '.$observed['interval_min']['nmi'].' nmi until a max. of '. + $report[] = 'varying from a min. of '.$observed['interval_min'][$report_unit].$report_unit.' until a max. of '. static::$rvr_prefix_codes[$observed['variable_prefix']].' that '. - $observed['interval_max']['nmi'].' nmi'; + $observed['interval_max'][$report_unit].' '.$report_unit; } else { - $report[] = 'varying from a min. of '.$observed['interval_min']['nmi'].' nmi until a max. of '. - $observed['interval_max']['nmi'].' nmi'; + $report[] = 'varying from a min. of '.$observed['interval_min'][$report_unit].$report_unit.' until a max. of '. + $observed['interval_max'][$report_unit].$report_unit; } } diff --git a/tests/MetarTest.php b/tests/MetarTest.php index 43703b9c..a4c22fc2 100644 --- a/tests/MetarTest.php +++ b/tests/MetarTest.php @@ -178,6 +178,23 @@ class MetarTest extends TestCase $this->assertEquals('38 km', $metar['visibility_report']); } + public function testLGKL() + { + $metar = 'LGKL 160320Z AUTO VRB02KT //// -RA ////// 07/04 Q1008 RE//'; + $metar = Metar::parse($metar); + + $this->assertEquals(2, $metar['wind_speed']['knots']); + $this->assertEquals('Light rain', $metar['present_weather_report']); + } + + public function testLBBG() + { + $metar = 'LBBG 041600Z 12003MPS 310V290 1400 R04/1000D R22/P1500U +SN BKN022 OVC050 M04/M07 Q1020 NOSIG 9949//91='; + $metar = Metar::parse($metar); + + $this->assertEquals('1000m and decreasing', $metar['runways_visual_range'][0]['report']); + } + public function testHttpCallSuccess() { $this->mockXmlResponse('aviationweather/kjfk.xml');