-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SimBrief Airframes & Aircraft Weight Casting (#1892)
* SimBrief Airframes * Update AirframeController.php * Settings and Manual Update * Convert Aircraft Weights to Pounds If the 'kg' is selected as weight unit. * Fix Fuel Casting * Update simbrief_form.blade.php * Display weights with local units * StyleFix CI Fixes :) * StyleCI Fix 2 :) * Update aircraft.csv for tests Provide some weights * Update ApiTest with AC Weights * Update ApiTest.php * Don't check the weights during tests (to test) * Update ImporterTest.php Add weight to importer * Fix for wrong airframe_id generation. Ref PilotID should be used. * Use ENUMS instead of strings For separating Internal / External airframes * Forgot one :) * Update Aircraft Resource * Update Aircraft.php
- Loading branch information
Showing
36 changed files
with
1,182 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Cron\Weekly; | ||
|
||
use App\Contracts\Listener; | ||
use App\Events\CronWeekly; | ||
use App\Services\SimBriefService; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class UpdateSimbriefData extends Listener | ||
{ | ||
/** | ||
* Update SimBrief Support Data | ||
* | ||
* @param CronWeekly $event | ||
* | ||
* @throws \UnexpectedValueException | ||
* @throws \InvalidArgumentException | ||
* @throws \Prettus\Validator\Exceptions\ValidatorException | ||
*/ | ||
public function handle(CronWeekly $event): void | ||
{ | ||
Log::info('Weekly: Updating SimBrief Support Data'); | ||
$SimBriefSVC = app(SimBriefService::class); | ||
$SimBriefSVC->getAircraftAndAirframes(); | ||
$SimBriefSVC->GetBriefingLayouts(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
app/Database/migrations/2024_11_16_105923_create_simbrief_support_tables.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class() extends Migration { | ||
public function up(): void | ||
{ | ||
if (!Schema::hasTable('simbrief_aircraft')) { | ||
Schema::create('simbrief_aircraft', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('icao'); | ||
$table->string('name'); | ||
$table->mediumText('details')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
if (!Schema::hasTable('simbrief_airframes')) { | ||
Schema::create('simbrief_airframes', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('icao'); | ||
$table->string('name'); | ||
$table->string('airframe_id')->nullable(); | ||
$table->unsignedTinyInteger('source')->nullable(); | ||
$table->mediumText('details')->nullable(); | ||
$table->mediumText('options')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
if (!Schema::hasTable('simbrief_layouts')) { | ||
Schema::create('simbrief_layouts', function (Blueprint $table) { | ||
$table->string('id'); | ||
$table->string('name'); | ||
$table->string('name_long'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('simbrief_aircraft'); | ||
Schema::dropIfExists('simbrief_airframes'); | ||
Schema::dropIfExists('simbrief_layouts'); | ||
} | ||
}; |
16 changes: 16 additions & 0 deletions
16
app/Database/migrations_data/2024_11_16_122416_fetch_initial_simbrief_data.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
use App\Services\SimBriefService; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class() extends Migration { | ||
public function up(): void | ||
{ | ||
if (Schema::hasTable('simbrief_aircraft') && Schema::hasTable('simbrief_airframes')) { | ||
$SimBriefSVC = app(SimBriefService::class); | ||
$SimBriefSVC->getAircraftAndAirframes(); | ||
$SimBriefSVC->GetBriefingLayouts(); | ||
} | ||
} | ||
}; |
34 changes: 34 additions & 0 deletions
34
app/Database/migrations_data/2024_11_17_114057_convert_aircraft_weights.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
return new class() extends Migration { | ||
public function up(): void | ||
{ | ||
if (setting('units.weight') == 'kg') { | ||
// Get all aircraft data, directly from database which had weights defined | ||
$aircraft = DB::table('aircraft')->whereNotNull('dow')->orWhereNotNull('zfw')->orWhereNotNull('mtow')->orWhereNotNull('mlw')->orderBy('id')->get(); | ||
Log::debug('Begin weight conversion for '.$aircraft->count().' aircraft records'); | ||
foreach ($aircraft as $ac) { | ||
Log::debug('Converting and Updating Weights for '.$ac->registration); | ||
DB::table('aircraft')->where('id', $ac->id)->update([ | ||
'dow' => $this->PoundsConversion($ac->dow), | ||
'zfw' => $this->PoundsConversion($ac->zfw), | ||
'mtow' => $this->PoundsConversion($ac->mtow), | ||
'mlw' => $this->PoundsConversion($ac->mlw), | ||
]); | ||
} | ||
} | ||
} | ||
|
||
public function PoundsConversion($value) | ||
{ | ||
if ($value > 0) { | ||
return round($value / 0.45359237, 2); | ||
} | ||
|
||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Contracts\Controller; | ||
use App\Http\Requests\CreateAirframeRequest; | ||
use App\Http\Requests\UpdateAirframeRequest; | ||
use App\Models\Aircraft; | ||
use App\Models\Enums\AirframeSource; | ||
use App\Repositories\AirframeRepository; | ||
use App\Services\SimBriefService; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\View\View; | ||
use Laracasts\Flash\Flash; | ||
use Prettus\Repository\Criteria\RequestCriteria; | ||
use Prettus\Repository\Exceptions\RepositoryException; | ||
use Prettus\Validator\Exceptions\ValidatorException; | ||
|
||
class AirframeController extends Controller | ||
{ | ||
/** | ||
* @param AirframeRepository $airframeRepo | ||
*/ | ||
public function __construct( | ||
private readonly AirframeRepository $airframeRepo | ||
) { | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* | ||
* @throws RepositoryException | ||
* | ||
* @return View | ||
*/ | ||
public function index(Request $request): View | ||
{ | ||
$this->airframeRepo->pushCriteria(new RequestCriteria($request)); | ||
$airframes = $this->airframeRepo->where('source', AirframeSource::INTERNAL)->orderby('icao', 'asc')->orderby('name', 'asc')->get(); | ||
|
||
return view('admin.airframes.index', [ | ||
'airframes' => $airframes, | ||
]); | ||
} | ||
|
||
/** | ||
* @return View | ||
*/ | ||
public function create(): View | ||
{ | ||
return view('admin.airframes.create', [ | ||
'icao_codes' => Aircraft::whereNotNull('icao')->groupBy('icao')->pluck('icao')->toArray(), | ||
]); | ||
} | ||
|
||
/** | ||
* @param CreateAirframeRequest $request | ||
* | ||
* @throws ValidatorException | ||
* | ||
* @return RedirectResponse | ||
*/ | ||
public function store(CreateAirframeRequest $request): RedirectResponse | ||
{ | ||
$input = $request->all(); | ||
|
||
$model = $this->airframeRepo->create($input); | ||
Flash::success('Airframe saved successfully.'); | ||
|
||
return redirect(route('admin.airframes.index')); | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* | ||
* @return RedirectResponse|View | ||
*/ | ||
public function show(int $id): RedirectResponse|View | ||
{ | ||
$airframe = $this->airframeRepo->findWithoutFail($id); | ||
|
||
if (empty($airframe)) { | ||
Flash::error('SimBrief Airframe not found'); | ||
|
||
return redirect(route('admin.airframes.index')); | ||
} | ||
|
||
return view('admin.airframes.show', [ | ||
'airframe' => $airframe, | ||
]); | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* | ||
* @return RedirectResponse|View | ||
*/ | ||
public function edit(int $id): RedirectResponse|View | ||
{ | ||
$airframe = $this->airframeRepo->findWithoutFail($id); | ||
|
||
if (empty($airframe)) { | ||
Flash::error('SimBrief Airframe not found'); | ||
|
||
return redirect(route('admin.airframes.index')); | ||
} | ||
|
||
return view('admin.airframes.edit', [ | ||
'airframe' => $airframe, | ||
'icao_codes' => Aircraft::whereNotNull('icao')->groupBy('icao')->pluck('icao')->toArray(), | ||
]); | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* @param UpdateAirframeRequest $request | ||
* | ||
* @throws ValidatorException | ||
* | ||
* @return RedirectResponse | ||
*/ | ||
public function update(int $id, UpdateAirframeRequest $request): RedirectResponse | ||
{ | ||
$airframe = $this->airframeRepo->findWithoutFail($id); | ||
|
||
if (empty($airframe)) { | ||
Flash::error('SimBrief Airframe not found'); | ||
|
||
return redirect(route('admin.airframes.index')); | ||
} | ||
|
||
$airframe = $this->airframeRepo->update($request->all(), $id); | ||
Flash::success('SimBrief Airport updated successfully.'); | ||
|
||
return redirect(route('admin.airframes.index')); | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* | ||
* @return RedirectResponse | ||
*/ | ||
public function destroy(int $id): RedirectResponse | ||
{ | ||
$airframe = $this->airframeRepo->findWithoutFail($id); | ||
|
||
if (empty($airframe)) { | ||
Flash::error('SimBrief Airframe not found'); | ||
|
||
return redirect(route('admin.airframes.index')); | ||
} | ||
|
||
$this->airframeRepo->delete($id); | ||
|
||
Flash::success('SimBrief Airframe deleted successfully.'); | ||
|
||
return redirect(route('admin.airframes.index')); | ||
} | ||
|
||
// Manually trigger update of SimBrief Airframe and Layouts | ||
public function updateSimbriefData() | ||
{ | ||
Log::debug('Manually Updating SimBrief Support Data'); | ||
$SimBriefSVC = app(SimBriefService::class); | ||
$SimBriefSVC->getAircraftAndAirframes(); | ||
$SimBriefSVC->GetBriefingLayouts(); | ||
|
||
Flash::success('SimBrief Airframe and Layouts updated successfully.'); | ||
|
||
return redirect(route('admin.airframes.index')); | ||
} | ||
} |
Oops, something went wrong.