Skip to content

Commit

Permalink
Merge pull request #498 from Vatsim-Scandinavia/fix/vatsim-helper
Browse files Browse the repository at this point in the history
Fix/vatsim helper
  • Loading branch information
blt950 authored Mar 5, 2023
2 parents 1bf07c7 + 215bb9b commit ecb363a
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 204 deletions.
3 changes: 2 additions & 1 deletion app/Console/Commands/UpdateAtcHours.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Handover;
use App\Models\User;
use App\Models\AtcActivity;
use App\Helpers\Vatsim;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Console\Command;
Expand Down Expand Up @@ -120,7 +121,7 @@ private function updateHoursForMember(User $member, Collection $sessions, Collec
$this->info("Updating ATC hours for member: " . $member->id);

$hoursActiveInDivision = $sessions
->filter(fn($session) => isDivisionCallsign($session->callsign, $divisionCallsignPrefixes))
->filter(fn($session) => Vatsim::isDivisionCallsign($session->callsign, $divisionCallsignPrefixes))
->map(function ($session) {
return floatval($session->minutes_on_callsign);
})
Expand Down
42 changes: 23 additions & 19 deletions app/Helpers/Vatsim.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?php

namespace App\Helpers\Vatsim;

namespace App\Helpers;
use Illuminate\Support\Collection;

/**
* Checks if a position belongs to the division.
* @param string callsign
* @param Collection<string> divisionCallsignPrefixes
*/
function isDivisionCallsign(string $callsign, Collection $divisionCallsignPrefixes)
{
$validAtcSuffixes = ["DEL" => true, "GND" => true, "TWR" => true, "APP" => true, "DEP" => true, "CTR" => true, "FSS" => true];
// Filter away invalid ATC suffixes
$suffix = substr($callsign, -3);
if (!array_key_exists($suffix, $validAtcSuffixes)) {
return false;
}
class Vatsim{

/**
* Checks if a position belongs to the division.
* @param string callsign
* @param Collection<string> divisionCallsignPrefixes
*/
public static function isDivisionCallsign(string $callsign, Collection $divisionCallsignPrefixes)
{
$validAtcSuffixes = ["DEL" => true, "GND" => true, "TWR" => true, "APP" => true, "DEP" => true, "CTR" => true, "FSS" => true];
// Filter away invalid ATC suffixes
$suffix = substr($callsign, -3);
if (!array_key_exists($suffix, $validAtcSuffixes)) {
return false;
}

// PREFIX
if ($divisionCallsignPrefixes->contains(substr($callsign, 0, 4))) {
return true;
// PREFIX
if ($divisionCallsignPrefixes->contains(substr($callsign, 0, 4))) {
return true;
}

return false;
}

return false;
}


?>
Loading

0 comments on commit ecb363a

Please sign in to comment.