Compare commits
6 Commits
snyk-fix-7
...
patch-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db34d0e3e7 | ||
|
|
fffbab7201 | ||
|
|
b9e7a2efc9 | ||
|
|
76a2a16fa6 | ||
|
|
cfbd1c901a | ||
|
|
617813bdbf |
@@ -38,6 +38,13 @@ class Pirep extends Resource
|
||||
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
||||
$res['distance'] = $distance->getResponseUnits();
|
||||
|
||||
if (!array_key_exists('block_fuel', $res)) {
|
||||
$res['block_fuel'] = 0;
|
||||
}
|
||||
|
||||
$block_fuel = new Fuel($res['block_fuel'], config('phpvms.internal_units.fuel'));
|
||||
$res['block_fuel'] = $block_fuel->getResponseUnits();
|
||||
|
||||
if (!array_key_exists('fuel_used', $res)) {
|
||||
$res['fuel_used'] = 0;
|
||||
}
|
||||
|
||||
@@ -326,6 +326,22 @@ class Pirep extends Model
|
||||
return $field_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the amount of block fuel
|
||||
*
|
||||
* @param $value
|
||||
*/
|
||||
public function setBlockFuelAttribute($value): void
|
||||
{
|
||||
if ($value instanceof Fuel) {
|
||||
$this->attributes['block_fuel'] = $value->toUnit(
|
||||
config('phpvms.internal_units.fuel')
|
||||
);
|
||||
} else {
|
||||
$this->attributes['block_fuel'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the amount of fuel used
|
||||
*
|
||||
|
||||
@@ -1772,7 +1772,7 @@ class Metar implements \ArrayAccess
|
||||
*/
|
||||
private function calculate_wind_chill($temperature_f): void
|
||||
{
|
||||
if ($temperature_f < 51 && $this->result['wind_speed'] !== 0) {
|
||||
if ($temperature_f < 51 && $this->result['wind_speed'] && $this->result['wind_speed'] !== 0) {
|
||||
$windspeed = $this->result['wind_speed']->toUnit('mph');
|
||||
if ($windspeed > 3) {
|
||||
$chill_f = 35.74 + 0.6215 * $temperature_f - 35.75 * ($windspeed ** 0.16);
|
||||
|
||||
@@ -151,6 +151,19 @@ class MetarTest extends TestCase
|
||||
$this->assertEquals('Few at 1500 feet; few at 25000 feet', $metar['clouds_report_ft']);
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/nabeelio/phpvms/issues/1071
|
||||
*/
|
||||
public function testMetarWindSpeedChill()
|
||||
{
|
||||
$metar = 'EKYT 091020Z /////KT CAVOK 02/M03 Q1019';
|
||||
$metar = Metar::parse($metar);
|
||||
|
||||
$this->assertEquals('VFR', $metar['category']);
|
||||
$this->assertNull($metar['wind_speed']);
|
||||
$this->assertEquals(6.21, $metar['visibility']['mi']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visibility in KM not parsed
|
||||
*
|
||||
|
||||
@@ -21,6 +21,7 @@ use App\Services\BidService;
|
||||
use App\Services\FlightService;
|
||||
use App\Services\PirepService;
|
||||
use App\Services\UserService;
|
||||
use App\Support\Units\Fuel;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
@@ -164,6 +165,8 @@ class PIREPTest extends TestCase
|
||||
$body = $response->json('data');
|
||||
|
||||
// Check that it has the fuel units
|
||||
$this->assertHasKeys($body['block_fuel'], ['lbs', 'kg']);
|
||||
$this->assertEquals($pirep->block_fuel, $body['block_fuel']['lbs']);
|
||||
$this->assertHasKeys($body['fuel_used'], ['lbs', 'kg']);
|
||||
$this->assertEquals($pirep->fuel_used, $body['fuel_used']['lbs']);
|
||||
|
||||
@@ -174,6 +177,24 @@ class PIREPTest extends TestCase
|
||||
// Check the planned_distance field
|
||||
$this->assertHasKeys($body['planned_distance'], ['km', 'nmi', 'mi']);
|
||||
$this->assertEquals($pirep->planned_distance, $body['planned_distance']['nmi']);
|
||||
|
||||
//Check conversion on save
|
||||
$val = random_int(1000, 9999999);
|
||||
$pirep->block_fuel = $val;
|
||||
$pirep->fuel_used = $val;
|
||||
// no conversion with plain numbers
|
||||
$this->assertEquals($pirep->block_fuel, $val);
|
||||
$this->assertEquals($pirep->fuel_used, $val);
|
||||
// no conversion with lbs
|
||||
$pirep->block_fuel = new Fuel($val, 'lbs');
|
||||
$this->assertEquals($pirep->block_fuel, $val);
|
||||
$pirep->fuel_used = new Fuel($val, 'lbs');
|
||||
$this->assertEquals($pirep->fuel_used, $val);
|
||||
// conversion of kg to lbs
|
||||
$pirep->block_fuel = new Fuel($val, 'kg');
|
||||
$this->assertEquals($pirep->block_fuel, (new Fuel($val, 'kg'))->toUnit('lbs'));
|
||||
$pirep->fuel_used = new Fuel($val, 'kg');
|
||||
$this->assertEquals($pirep->fuel_used, (new Fuel($val, 'kg'))->toUnit('lbs'));
|
||||
}
|
||||
|
||||
public function testGetUserPireps()
|
||||
|
||||
Reference in New Issue
Block a user