diff --git a/app/Support/Metar.php b/app/Support/Metar.php index 1e9ffaac..6fdb9087 100644 --- a/app/Support/Metar.php +++ b/app/Support/Metar.php @@ -8,6 +8,7 @@ use App\Support\Units\Pressure; use App\Support\Units\Temperature; use App\Support\Units\Velocity; use function count; +use Illuminate\Support\Facades\Log; use PhpUnitsOfMeasure\Exception\NonNumericValue; use PhpUnitsOfMeasure\Exception\NonStringUnitName; @@ -341,6 +342,7 @@ class Metar implements \ArrayAccess public function __construct($raw, $taf = false, $debug = false, $icao = true) { $this->debug_enabled = $debug; + // Log::info('Parsing metar="'.$raw.'"'); $raw_lines = explode("\n", $raw, 2); if (isset($raw_lines[1])) { @@ -408,7 +410,7 @@ class Metar implements \ArrayAccess */ protected function createAltitude($value, $unit) { - return new Altitude($value, $unit); + return new Altitude((float) $value, $unit); } /** @@ -424,7 +426,7 @@ class Metar implements \ArrayAccess */ protected function createDistance($value, $unit) { - return new Distance($value, $unit); + return new Distance((float) $value, $unit); } /** @@ -440,7 +442,7 @@ class Metar implements \ArrayAccess */ protected function createPressure($value, $unit) { - return new Pressure($value, $unit); + return new Pressure((float) $value, $unit); } /** @@ -456,7 +458,7 @@ class Metar implements \ArrayAccess */ protected function createTemperature($value, $unit) { - return new Temperature($value, $unit); + return new Temperature((float) $value, $unit); } /** @@ -472,7 +474,7 @@ class Metar implements \ArrayAccess */ protected function createVelocity($value, $unit) { - return new Velocity($value, $unit); + return new Velocity((float) $value, $unit); } /** @@ -1118,6 +1120,7 @@ class Metar implements \ArrayAccess $report = implode(' ', $report); $report_ft = implode(' ', $report_ft); + $observed['report'] = $this->createAltitude($report_ft, 'ft'); $observed['report'] = ucfirst($report); $observed['report_ft'] = ucfirst($report_ft); diff --git a/resources/views/layouts/default/widgets/weather.blade.php b/resources/views/layouts/default/widgets/weather.blade.php index 3da30262..5ef12fa9 100644 --- a/resources/views/layouts/default/widgets/weather.blade.php +++ b/resources/views/layouts/default/widgets/weather.blade.php @@ -30,8 +30,8 @@ https://api.checkwx.com/#metar-decoded @lang('widgets.weather.barometer') - {{ number_format($metar['barometer'], 2) }} hPa - / {{ number_format($metar['barometer_in'], 2) }} inHg + {{ number_format($metar['barometer']['hPa'], 2) }} hPa + / {{ number_format($metar['barometer']['inHg'], 2) }} inHg @if($metar['clouds']) diff --git a/tests/MetarTest.php b/tests/MetarTest.php index ec2cf075..cee14eca 100644 --- a/tests/MetarTest.php +++ b/tests/MetarTest.php @@ -138,4 +138,13 @@ class MetarTest extends TestCase $this->assertEquals('VFR', $metar['category']); $this->assertNotNull($metar); } + + public function testMetar4Clouds() + { + $metar = 'KAUS 171153Z 18006KT 9SM FEW015 FEW250 26/24 A3003 RMK AO2 SLP156 T02560244 10267 20239 $'; + $metar = Metar::parse($metar); + + $this->assertNotNull($metar); + $this->assertEquals(2, count($metar->clouds)); + } }