Replace METAR data with custom class
This commit is contained in:
@@ -41,6 +41,7 @@ class Metar
|
||||
'observed_day' => null,
|
||||
'observed_time' => null,
|
||||
'observed_age' => null,
|
||||
'category' => null,
|
||||
'wind_speed' => null,
|
||||
'wind_gust_speed' => null,
|
||||
'wind_direction' => null,
|
||||
@@ -63,6 +64,7 @@ class Metar
|
||||
'clouds_report' => null,
|
||||
'clouds_report_ft' => null,
|
||||
'cloud_height' => null,
|
||||
'cloud_height_ft' => null,
|
||||
'cavok' => null,
|
||||
'temperature' => null,
|
||||
'temperature_f' => null,
|
||||
@@ -75,6 +77,7 @@ class Metar
|
||||
'wind_chill_f' => null,
|
||||
'barometer' => null,
|
||||
'barometer_in' => null,
|
||||
'barometer_mb' => null,
|
||||
'recent_weather' => null,
|
||||
'recent_weather_report' => null,
|
||||
'runways_report' => null,
|
||||
@@ -428,6 +431,16 @@ class Metar
|
||||
}
|
||||
}
|
||||
|
||||
// Finally determine if it's VFR or IFR conditions
|
||||
// https://www.aviationweather.gov/cva/help
|
||||
if($this->result['cavok']
|
||||
|| ($this->result['cloud_height_ft'] > 3000 && $this->result['visibility_nm'] > 5))
|
||||
{
|
||||
$this->result['category'] = 'VFR';
|
||||
} else {
|
||||
$this->result['category'] = 'IFR';
|
||||
}
|
||||
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
@@ -951,6 +964,7 @@ class Metar
|
||||
// Cloud height
|
||||
if (null === $this->result['cloud_height'] || $observed['height'] < $this->result['cloud_height']) {
|
||||
$this->set_result_value('cloud_height', $observed['height']);
|
||||
$this->set_result_value('cloud_height_ft', $observed['height_ft']);
|
||||
}
|
||||
|
||||
if (isset(static::$cloud_codes[$found[4]])) {
|
||||
@@ -1061,6 +1075,7 @@ class Metar
|
||||
}
|
||||
|
||||
$this->set_result_value('barometer', $pressure); // units are hPa
|
||||
$this->set_result_value('barometer_mb', $pressure); // units are hPa
|
||||
$this->set_result_value('barometer_in', round(0.02953 * $pressure, 2)); // convert to in Hg
|
||||
|
||||
$this->method++;
|
||||
|
||||
@@ -3,13 +3,7 @@
|
||||
namespace App\Widgets;
|
||||
|
||||
use App\Interfaces\Widget;
|
||||
use App\Support\Http;
|
||||
use App\Support\MetarWrapper;
|
||||
use App\Support\Units\Distance;
|
||||
use App\Support\Units\Temperature;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use MetarDecoder\MetarDecoder;
|
||||
use SimpleXMLElement;
|
||||
use App\Support\Metar;
|
||||
|
||||
/**
|
||||
* This is a widget for the 3rd party CheckWX service
|
||||
@@ -23,17 +17,6 @@ class Weather extends Widget
|
||||
|
||||
public const URL = 'https://avwx.rest/api/metar/';
|
||||
|
||||
/**
|
||||
* Determine the category depending on the rules for visibility/ceiling
|
||||
* https://www.aviationweather.gov/cva/help
|
||||
* @param $metar
|
||||
* @return string
|
||||
*/
|
||||
protected function determineCategory($metar): string
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to get the data from the CheckWX API
|
||||
*/
|
||||
@@ -50,14 +33,12 @@ class Weather extends Widget
|
||||
$raw_metar = $metar_class->get_metar($this->config['icao']);
|
||||
|
||||
if ($raw_metar && $raw_metar !== '') {
|
||||
$metar = new MetarWrapper($raw_metar);
|
||||
$wind = $metar->getWinds();
|
||||
$metar = Metar::parse($raw_metar);
|
||||
}
|
||||
|
||||
return view('widgets.weather', [
|
||||
'config' => $this->config,
|
||||
'metar' => $metar,
|
||||
'wind' => $wind,
|
||||
'unit_alt' => setting('units.altitude'),
|
||||
'unit_dist' => setting('units.distance'),
|
||||
'unit_temp' => setting('units.temperature'),
|
||||
|
||||
Reference in New Issue
Block a user