Compare commits
3 Commits
UpdateMeta
...
1007-csv-i
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c97977de9a | ||
|
|
bda1a91117 | ||
|
|
3f92191126 |
@@ -101,7 +101,7 @@ class AirportService extends Service
|
||||
}
|
||||
|
||||
// Don't lookup the airport, so just add in something generic
|
||||
if (!setting('general.auto_airport_lookup')) {
|
||||
if (!setting('general.auto_airport_lookup', false)) {
|
||||
$airport = new Airport([
|
||||
'id' => $icao,
|
||||
'icao' => $icao,
|
||||
|
||||
@@ -51,8 +51,13 @@ class FlightImporter extends ImportExport
|
||||
'fields' => 'nullable',
|
||||
];
|
||||
|
||||
/** @var AirportService */
|
||||
private $airportSvc;
|
||||
|
||||
/** @var FareService */
|
||||
private $fareSvc;
|
||||
|
||||
/** @var FlightService */
|
||||
private $flightSvc;
|
||||
|
||||
/**
|
||||
|
||||
@@ -118,11 +118,7 @@ class ImportService extends Service
|
||||
// turn it into a collection and run some filtering
|
||||
$row = collect($row)->map(function ($val, $index) {
|
||||
$val = trim($val);
|
||||
if ($val === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
return $val;
|
||||
return empty($val) ? null : $val;
|
||||
})->toArray();
|
||||
|
||||
// Try to validate
|
||||
|
||||
@@ -131,10 +131,22 @@ return [
|
||||
'Yaml' => Symfony\Component\Yaml\Yaml::class,
|
||||
|
||||
// ENUMS
|
||||
'ActiveState' => App\Models\Enums\ActiveState::class,
|
||||
'UserState' => App\Models\Enums\UserState::class,
|
||||
'PirepSource' => App\Models\Enums\PirepSource::class,
|
||||
'PirepState' => App\Models\Enums\PirepState::class,
|
||||
'PirepStatus' => App\Models\Enums\PirepStatus::class,
|
||||
'AcarsType' => App\Models\Enums\AcarsType::class,
|
||||
'ActiveState' => App\Models\Enums\ActiveState::class,
|
||||
'AircraftState' => App\Models\Enums\AircraftState::class,
|
||||
'AircraftStatus' => App\Models\Enums\AircraftStatus::class,
|
||||
'Days' => App\Models\Enums\Days::class,
|
||||
'ExpenseType' => App\Models\Enums\ExpenseType::class,
|
||||
'FareType' => App\Models\Enums\FareType::class,
|
||||
'FlightType' => App\Models\Enums\FlightType::class,
|
||||
'FuelType' => App\Models\Enums\FuelType::class,
|
||||
'JournalType' => App\Models\Enums\JournalType::class,
|
||||
'NavaidType' => App\Models\Enums\NavaidType::class,
|
||||
'PageType' => App\Models\Enums\PageType::class,
|
||||
'PirepFieldSource' => App\Models\Enums\PirepFieldSource::class,
|
||||
'PirepSource' => App\Models\Enums\PirepSource::class,
|
||||
'PirepState' => App\Models\Enums\PirepState::class,
|
||||
'PirepStatus' => App\Models\Enums\PirepStatus::class,
|
||||
'UserState' => App\Models\Enums\UserState::class,
|
||||
],
|
||||
];
|
||||
|
||||
@@ -467,6 +467,11 @@ class ImporterTest extends TestCase
|
||||
*/
|
||||
public function testFlightImporter(): void
|
||||
{
|
||||
$this->updateSetting('general.auto_airport_lookup', false);
|
||||
|
||||
factory(Airport::class)->create(['icao' => 'KAUS']);
|
||||
factory(Airport::class)->create(['icao' => 'KJFK']);
|
||||
|
||||
[$airline, $subfleet] = $this->insertFlightsScaffoldData();
|
||||
|
||||
$file_path = base_path('tests/data/flights.csv');
|
||||
@@ -531,6 +536,19 @@ class ImporterTest extends TestCase
|
||||
// Check the subfleets
|
||||
$subfleets = $flight->subfleets;
|
||||
$this->assertCount(1, $subfleets);
|
||||
|
||||
// Reimport, see that data updates
|
||||
$file_path = base_path('tests/data/flights-update.csv');
|
||||
$status = $this->importSvc->importFlights($file_path);
|
||||
|
||||
$flight = Flight::where([
|
||||
'airline_id' => $airline->id,
|
||||
'flight_number' => '1972',
|
||||
])->first();
|
||||
|
||||
$this->assertCount(1, $status['success']);
|
||||
$this->assertEquals('12:00 CST', $flight->dpt_time);
|
||||
$this->assertEquals('18:35 EST', $flight->arr_time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -634,8 +652,8 @@ class ImporterTest extends TestCase
|
||||
$this->assertEquals(true, $airport->hub);
|
||||
$this->assertEquals('30.1945', $airport->lat);
|
||||
$this->assertEquals('-97.6699', $airport->lon);
|
||||
$this->assertEquals(0.0, $airport->ground_handling_cost);
|
||||
$this->assertEquals(setting('airports.default_jet_a_fuel_cost'), $airport->fuel_jeta_cost);
|
||||
$this->assertEquals(250, $airport->ground_handling_cost);
|
||||
$this->assertEquals(0.8, $airport->fuel_jeta_cost); // should be updated
|
||||
|
||||
// See if it imported
|
||||
$airport = Airport::where([
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
icao,iata,name,location,country,timezone,hub,lat,lon,ground_handling_cost,fuel_100ll_cost,fuel_jeta_cost,fuel_mogas_cost
|
||||
KAUS,AUS,Austin-Bergstrom,"Austin, Texas, USA", United States,America/Chicago,1,30.1945,-97.6699,0,,,
|
||||
KSFO,SFO,San Francisco,"San Francisco, California, USA", United States,America/California,1,30.1945,-97.6699,,,0.9,
|
||||
KJFK,JFK,Kennedy,"Queens, New York, USA", United States,America/New_York,0,30.1945,abcd,150,,0.8,
|
||||
icao,iata,name,location,country,timezone,hub,lat,lon,ground_handling_cost,fuel_100ll_cost,fuel_jeta_cost,fuel_mogas_cost
|
||||
KAUS,AUS,Austin-Bergstrom,"Austin, Texas, USA", United States,America/Chicago,1,30.1945,-97.6699,250,0.8,0.8,0.8
|
||||
KSFO,SFO,San Francisco,"San Francisco, California, USA", United States,America/California,1,30.1945,-97.6699,,,0.9,
|
||||
KJFK,JFK,Kennedy,"Queens, New York, USA", United States,America/New_York,0,30.1945,abcd,150,,0.8,
|
||||
|
||||
|
2
tests/data/flights-update.csv
Normal file
2
tests/data/flights-update.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
airline,flight_number,route_code,route_leg,dpt_airport,arr_airport,alt_airport,days,dpt_time,arr_time,level,distance,flight_time,flight_type,load_factor, load_factor_variance,pilot_pay,route,notes,active,subfleets,fares,fields
|
||||
VMS,1972, ,,KAUS,KJFK,KLGA,15,12:00 CST,18:35 EST,350,1477,207,J,85,0,100, ILEXY2 ZENZI LFK ELD J29 MEM Q29 JHW J70 STENT J70 MAGIO J70 LVZ LENDY6,"Just a flight",1,A32X,Y?price=300&cost=100&capacity=130;F?price=600&cost=400;B?,Departure Gate=4;Arrival Gate=C41
|
||||
|
Reference in New Issue
Block a user