Fix null visibility in METAR (#1079)

* Fix null visibility in METAR

* Report the text in units from the METAR
This commit is contained in:
Nabeel S
2021-03-17 17:40:45 -04:00
committed by GitHub
parent 0152ff6045
commit 63eef59060
2 changed files with 26 additions and 7 deletions

View File

@@ -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;
}
}

View File

@@ -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');