Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/sass-1.83.1
Browse files Browse the repository at this point in the history
  • Loading branch information
detheridge02 authored Jan 15, 2025
2 parents 301245c + dcb30e9 commit deaa1de
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 230 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ BUGSNAG_FILTERS=password,authid,authpassword,apikey_pub,access_token,x-newrelic-
BUGSNAG_BATCH_SENDING=true
BUGSNAG_NOTIFY_RELEASE_STAGES=production,staging
BUGSNAG_QUERY_BINDINGS=true

BETTERSTACK_SOURCE_TOKEN=
BETTERSTACK_LOG_LEVEL=debug
74 changes: 35 additions & 39 deletions app/Filament/Pages/Operations/GenerateQuarterlyStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Filament\Pages\Operations;

use App\Filament\Helpers\Pages\BasePage;
use App\Models\Atc\PositionGroup;
use App\Models\Mship\Account;
use App\Models\Mship\Account\Endorsement;
use Carbon\Carbon;
Expand Down Expand Up @@ -61,19 +60,18 @@ public function submit(): void
$endDate = $startDate->copy()->addMonths(3);

$this->statistics = collect([
['name' => 'Left Division', 'value' => $this->membersLeftDivision($startDate, $endDate)],
['name' => 'Pilots Visiting', 'value' => $this->pilotsVisiting($startDate, $endDate)],
['name' => 'New Joiners as First Division', 'value' => $this->newJoinersAsFirstDivision($startDate, $endDate)],
['name' => 'Members Becoming Inactive', 'value' => $this->membersBecomingInactive($startDate, $endDate)],
['name' => 'Visiting Controllers Above S1', 'value' => $this->visitingControllersAboveS1($startDate, $endDate)],
['name' => 'Completed Transfer (Ex OBS)', 'value' => $this->completedTransfersExObs($startDate, $endDate)],
])->merge(collect(['OBS', 'TWR', 'APP', 'CTR'])->map(function ($value) use ($startDate, $endDate) {
return ['name' => "Completed 121 Mentoring Sessions - {$value}", 'value' => $this->completedMentoringSessions($startDate, $endDate, $value)];
}))->merge(collect(['TWR', 'APP', 'CTR'])->map(function ($value) use ($startDate, $endDate) {
return ['name' => "Exam Pass - {$value}", 'value' => $this->examPasses($startDate, $endDate, $value)];
})->merge(collect(['GND', 'TWR', 'APP'])->map(function ($value) use ($startDate, $endDate) {
return ['name' => "Issued Heathrow Endorsement - {$value}", 'value' => $this->issuedHeathrowEndorsements($startDate, $endDate, $value)];
})));
'Division Membership' => [
['name' => 'Left Division', 'value' => $this->membersLeftDivision($startDate, $endDate)],
['name' => 'Pilots Visiting', 'value' => $this->pilotsVisiting($startDate, $endDate)],
['name' => 'New Joiners as First Division', 'value' => $this->newJoinersAsFirstDivision($startDate, $endDate)],
['name' => 'Members Becoming Inactive', 'value' => $this->membersBecomingInactive($startDate, $endDate)],
['name' => 'Visiting Controllers Above S1', 'value' => $this->visitingControllersAboveS1($startDate, $endDate)],
['name' => 'Completed Transfer (Ex OBS)', 'value' => $this->completedTransfersExObs($startDate, $endDate)],
],
'Completed Mentoring Sessions' => $this->completedMentoringSessions($startDate, $endDate),
'Exam Passes' => $this->examPasses($startDate, $endDate),
'Issued Position Group Endorsements' => $this->issuedPositionGroupEndorsements($startDate, $endDate),
]);
}

protected static function canUse(): bool
Expand Down Expand Up @@ -147,45 +145,43 @@ private function visitingControllersAboveS1($startDate, $endDate)
})->count();
}

private function completedMentoringSessions(Carbon $startDate, Carbon $endDate, string $type)
private function completedMentoringSessions(Carbon $startDate, Carbon $endDate)
{
$studentRating = match ($type) {
'OBS' => 1,
'TWR' => 2,
'APP' => 3,
'CTR' => 4
};

return DB::connection('cts')
->table('sessions')
->select('rts.name', DB::raw('count(*) as total'))
->join('rts', 'sessions.rts_id', '=', 'rts.id')
->whereBetween('taken_date', [$startDate, $endDate])
->whereNull('cancelled_datetime')
->where('position', 'LIKE', "%$type%")
->where('student_rating', '=', $studentRating)
->count();
->where('noShow', '=', 0)
->groupBy('rts_id')
->get()
->flatMap(fn ($value) => [['name' => $value->name, 'value' => $value->total]])
->toArray();
}

private function issuedHeathrowEndorsements(Carbon $startDate, Carbon $endDate, string $type)
private function issuedPositionGroupEndorsements(Carbon $startDate, Carbon $endDate)
{
$positionGroup = match ($type) {
'GND' => 18,
'TWR' => 10,
'APP' => 11
};

return Endorsement::whereBetween('created_at', [$startDate, $endDate])
->whereEndorsableType(PositionGroup::class)
->whereEndorsableId($positionGroup)
->count();
return Endorsement::with('endorsable')
->whereBetween('mship_account_endorsement.created_at', [$startDate, $endDate])
->join('position_groups', 'position_groups.id', 'mship_account_endorsement.endorsable_id')
->groupBy('position_groups.id', 'position_groups.name')
->select(['position_groups.name', 'position_groups.id', DB::raw('count(*) as total')])
->get()
->flatMap(fn ($value) => [['name' => $value->name, 'value' => $value->total]])
->toArray();
}

private function examPasses(Carbon $startDate, Carbon $endDate, string $type)
private function examPasses(Carbon $startDate, Carbon $endDate)
{
return DB::connection('cts')
->table('practical_results')
->select('exam', DB::raw('count(*) as total'))
->whereBetween('date', [$startDate, $endDate])
->where('result', '=', 'P')
->where('exam', '=', $type)
->count();
->groupBy('exam')
->get()
->flatMap(fn ($value) => [['name' => $value->exam, 'value' => $value->total]])
->toArray();
}
}
2 changes: 1 addition & 1 deletion app/Jobs/UpdateMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle()
try {
$member = Account::findOrFail(['id' => $this->accountID])->first();
} catch (ModelNotFoundException $e) {
Log::info("Member {$this->accountID} not found in database. Auth needed to fetch data.");
Log::debug("Member {$this->accountID} not found in database. Auth needed to fetch data.");

return;
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"league/csv": "^9.0",
"league/oauth2-client": "^2.4",
"livewire/livewire": "^3.5",
"logtail/monolog-logtail": "^3.2",
"maatwebsite/excel": "~3.1.17",
"malahierba-lab/public-id": "dev-main",
"ohdearapp/ohdear-php-sdk": "^3.0",
Expand Down Expand Up @@ -170,4 +171,4 @@
"php-http/discovery": true
}
}
}
}
Loading

0 comments on commit deaa1de

Please sign in to comment.