Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metar: TEMPO and trend causing issue with values being overwritten #862

Merged
merged 3 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/Support/Metar.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public function parse_all(): array
// Delete null values from the TAF report
if ($this->result['taf'] === true) {
foreach ($this->result as $parameter => $value) {
if (!$value) {
if ($value === null) {
unset($this->result[$parameter]);
}
}
Expand All @@ -530,7 +530,8 @@ public function parse_all(): array
} else {
/* @noinspection NestedPositiveIfStatementsInspection */
if (array_key_exists('cloud_height', $this->result) && $this->result['cloud_height'] !== null) {
if ($this->result['cloud_height']['ft'] > 3000 && $this->result['visibility']['nmi'] > 5) {
if ($this->result['cloud_height']['ft'] > 3000
&& (empty($this->result['visibility']) || $this->result['visibility']['nmi'] > 5)) {
$this->result['category'] = 'VFR';
} else {
$this->result['category'] = 'IFR';
Expand Down Expand Up @@ -868,11 +869,11 @@ private function get_visibility($part)
$this->set_result_value('cavok', false, true);

// Cloud and visibilty OK or ICAO visibilty greater than 10 km
if ($found[1] === 'CAVOK' || $found[1] === '9999') {
if (strtoupper($found[1]) === 'CAVOK' || $found[1] === '9999') {
$this->set_result_value('visibility', $this->createDistance(10000, 'm'));
$this->set_result_value('visibility_report', 'Greater than 10 km');
/* @noinspection NotOptimalIfConditionsInspection */
if ($found[1] === 'CAVOK') {
if (strtoupper($found[1]) === 'CAVOK') {
$this->set_result_value('cavok', true);
$this->method += 4; // can skip the next 4 methods: visibility_min, runway_vr, present_weather, clouds
}
Expand Down Expand Up @@ -1484,6 +1485,8 @@ private function get_trends($part)
return false;
}

// Ignore trends
return true;
// Detects TAF on report
if ($this->part <= 4) {
$this->set_result_value('taf', true);
Expand Down
2 changes: 1 addition & 1 deletion modules/Awards/Awards/PilotFlightAwards.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Simple example of an awards class, where you can apply an award when a user
* has 100 flights. All award classes need to extend Award and implement the check() method
*
* See: http://docs.phpvms.net/customizing/awards
* See: https://docs.phpvms.net/developers/awards
*/
class PilotFlightAwards extends Award
{
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<server name="APP_DEBUG" value="true"/>
<server name="APP_LOG_LEVEL" value="error"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="CACHE_DRIVER" value="none"/>
<server name="DB_CONNECTION" value="memory"/>
<server name="DB_PREFIX" value="vmstest_"/>
<server name="MAIL_MAILER" value="array"/>
Expand Down
16 changes: 16 additions & 0 deletions tests/MetarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@ public function testHttpCallSuccess()
$this->assertInstanceOf(Metar::class, $airportSvc->getMetar('kjfk'));
}

/**
* TEMPO and trend causing issue with values being overwritten
* https://github.com/nabeelio/phpvms/issues/861
*/
public function testLFRSCall()
{
$this->mockXmlResponse('aviationweather/lfrs.xml');

/** @var AirportService $airportSvc */
$airportSvc = app(AirportService::class);

$metar = $airportSvc->getMetar('lfrs');
$this->assertInstanceOf(Metar::class, $metar);
$this->assertTrue($metar['cavok']);
}

public function testHttpCallSuccessFullResponse()
{
$this->mockXmlResponse('aviationweather/kphx.xml');
Expand Down
32 changes: 32 additions & 0 deletions tests/data/aviationweather/lfrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<response xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2"
xsi:noNamespaceSchemaLocation="http://www.aviationweather.gov/static/adds/schema/metar1_2.xsd">
<request_index>109074758</request_index>
<data_source name="metars"/>
<request type="retrieve"/>
<errors/>
<warnings/>
<time_taken_ms>7</time_taken_ms>
<data num_results="1">
<METAR>
<raw_text>LFRS 101630Z AUTO 32007KT 280V340 CAVOK 15/05 Q1027 TEMPO SCT035TCU</raw_text>
<station_id>LFRS</station_id>
<observation_time>2020-10-10T16:30:00Z</observation_time>
<latitude>47.17</latitude>
<longitude>-1.6</longitude>
<temp_c>15.0</temp_c>
<dewpoint_c>5.0</dewpoint_c>
<wind_dir_degrees>320</wind_dir_degrees>
<wind_speed_kt>7</wind_speed_kt>
<visibility_statute_mi>6.21</visibility_statute_mi>
<altim_in_hg>30.324802</altim_in_hg>
<quality_control_flags>
<auto>TRUE</auto>
</quality_control_flags>
<sky_condition sky_cover="CAVOK"/>
<flight_category>VFR</flight_category>
<metar_type>SPECI</metar_type>
<elevation_m>26.0</elevation_m>
</METAR>
</data>
</response>