-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from czqoocavatsim/development
1.3.0 - User interface refresh, conflict detector, track sorting
- Loading branch information
Showing
44 changed files
with
6,195 additions
and
8,220 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
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,19 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum ConflictLevelEnum: int | ||
{ | ||
case None = 0; | ||
case Potential = 1; | ||
case Warning = 2; | ||
|
||
public function colour(): string | ||
{ | ||
return match ($this) { | ||
ConflictLevelEnum::None => 'conflict-green', | ||
ConflictLevelEnum::Potential => 'conflict-potential', | ||
ConflictLevelEnum::Warning => 'conflict-warning' | ||
}; | ||
} | ||
} |
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
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,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
class ViewsController extends Controller | ||
{ | ||
public function welcome() | ||
{ | ||
$notams = Cache::remember('notams', now()->addMinutes(10), function () { | ||
return json_decode(Http::timeout(5)->get('https://ganderoceanicoca.ams3.digitaloceanspaces.com/resources/data/nattrak/notams.json')); | ||
}); | ||
return view('welcome', [ | ||
'notams' => $notams | ||
]); | ||
} | ||
} |
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,117 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Controllers; | ||
|
||
use App\Enums\ConflictLevelEnum; | ||
use App\Models\ClxMessage; | ||
use Carbon\Carbon; | ||
use Carbon\CarbonPeriod; | ||
use Illuminate\Support\Collection; | ||
use Livewire\Component; | ||
|
||
class ConflictChecker extends Component | ||
{ | ||
public $originalLevel; | ||
public $level; | ||
public $originalEntry; | ||
public $entry; | ||
public $originalTime; | ||
public $time; | ||
|
||
public $conflicts = []; | ||
public ConflictLevelEnum $conflictLevel = ConflictLevelEnum::None; | ||
|
||
protected $listeners = ['levelChanged', 'timeChanged']; | ||
|
||
public function render() | ||
{ | ||
return view('livewire.controllers.conflict-checker'); | ||
} | ||
|
||
public function mount() | ||
{ | ||
$this->originalLevel = $this->level; | ||
$this->originalEntry = $this->entry; | ||
$this->originalTime = $this->time; | ||
} | ||
|
||
public function levelChanged(string $newLevel) | ||
{ | ||
if (empty($newLevel)) { | ||
$this->level = $this->originalLevel; | ||
} else { | ||
$this->level = $newLevel; | ||
} | ||
$this->check(); | ||
} | ||
|
||
public function timeChanged(string $newTime) | ||
{ | ||
if (empty($newTime)) { | ||
$this->time = $this->originalTime; | ||
} else { | ||
$this->time = $newTime; | ||
} | ||
$this->check(); | ||
} | ||
|
||
private function getTimeRange(string $time, int $minutes): array | ||
{ | ||
$period = CarbonPeriod::since(Carbon::parse($time)->subMinutes($minutes))->minutes()->until(Carbon::parse($time)->addMinutes($minutes)); | ||
$times = []; | ||
foreach ($period as $time) { | ||
$times[] = $time->format('Hi'); | ||
} | ||
return $times; | ||
} | ||
|
||
private function formatDiff(Carbon $a, Carbon $b): string | ||
{ | ||
if ($a->diffInMinutes($b) < 2) { | ||
return "Same"; | ||
} else { | ||
return $a->longAbsoluteDiffForHumans($b); | ||
} | ||
} | ||
|
||
private function determineConflictLevel(Collection $aircraft): ConflictLevelEnum | ||
{ | ||
$level = ConflictLevelEnum::None; | ||
foreach ($aircraft as $a) { | ||
if ($a['diffMinutes'] < 5) { | ||
$level = ConflictLevelEnum::Warning; | ||
} | ||
if ($a['diffMinutes'] >= 5 && $a['diffMinutes'] <= 10) { | ||
$level = ConflictLevelEnum::Potential; | ||
} | ||
} | ||
|
||
return $level; | ||
} | ||
|
||
public function check() | ||
{ | ||
$timeArray = $this->getTimeRange($this->time, 10); | ||
$this->conflicts = []; | ||
$results = ClxMessage::whereEntryFix($this->entry) | ||
->whereIn( | ||
'raw_entry_time_restriction', | ||
$timeArray | ||
) | ||
->whereFlightLevel($this->level) | ||
->with('rclMessage') | ||
->get(); | ||
$mapped = $results->map(function (ClxMessage $message, $key) { | ||
return [ | ||
'id' => $key, | ||
'callsign' => $message->rclMessage->callsign, | ||
'level' => $message->flight_level, | ||
'time' => $message->formatEntryTimeRestriction(), | ||
'diffVisual' => $this->formatDiff(Carbon::parse($this->time), Carbon::parse($message->raw_entry_time_restriction)), | ||
'diffMinutes' => Carbon::parse($this->time)->diffInMinutes(Carbon::parse($message->raw_entry_time_restriction)) | ||
]; | ||
}); | ||
$this->conflictLevel = $this->determineConflictLevel($mapped); | ||
$this->conflicts = $mapped; | ||
} | ||
} |
Oops, something went wrong.