Skip to content

Commit

Permalink
Fixed divisionCallsignPrefixes filter
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Dec 31, 2022
1 parent d6c72b8 commit f5a9672
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
14 changes: 2 additions & 12 deletions app/Console/Commands/UpdateAtcHours.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private function updateMemberATCHours(Collection $members)
$this->info("Fetching seen ATC positions...");
$divisionCallsignPrefixes = collect(DB::select(
DB::raw('SELECT DISTINCT LEFT(callsign, 4) as prefix FROM positions;')
));
))->pluck('prefix');

$this->info("Updating member ATC hours...");

Expand All @@ -89,8 +89,6 @@ private function updateMemberATCHours(Collection $members)
}
$response = $this->makeHttpGetRequest($client, $url);

$this->info("Checking " . $member->id);

if ($response == null) {
Log::error('updateMemberATCHours: Failed to fetch GuzzleHttp Response, url: ' . $url);
continue;
Expand Down Expand Up @@ -122,16 +120,8 @@ private function updateHoursForMember(User $member, Collection $sessions, Collec
{
$this->info("Updating ATC hours for member: " . $member->id);

$isDivisionCallsign = function ($session) use ($divisionCallsignPrefixes) {
try {
isDivisionCallsign($session->callsign, $divisionCallsignPrefixes);
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return false;
}
return true;
};
$hoursActiveInDivision = $sessions
->filter($isDivisionCallsign)
->filter(fn($session) => isDivisionCallsign($session->callsign, $divisionCallsignPrefixes))
->map(function ($session) {
return floatval($session->minutes_on_callsign);
})
Expand Down
3 changes: 1 addition & 2 deletions app/Helpers/Vatsim.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ function isDivisionCallsign(string $callsign, Collection $divisionCallsignPrefix
}

// PREFIX

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

Expand Down

0 comments on commit f5a9672

Please sign in to comment.