Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/Filament/Training/Pages/Exam/ExamHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Training\Pages\Exam;

use App\Filament\Training\Pages\Exam\Widgets\ExamOverview;
use App\Repositories\Cts\ExamResultRepository;
use Filament\Forms;
use Filament\Pages\Page;
Expand All @@ -28,6 +29,13 @@ public static function canAccess(): bool
return auth()->user()->can('training.exams.access');
}

protected function getHeaderWidgets(): array
{
return [
ExamOverview::class,
];
}

public function table(Table $table): Table
{
$userPermissionsTruthTable = [
Expand Down
55 changes: 55 additions & 0 deletions app/Filament/Training/Pages/Exam/Widgets/ExamOverview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Filament\Training\Pages\Exam\Widgets;

use App\Models\Cts\PracticalResult;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Facades\DB;

class ExamOverview extends BaseWidget
{
protected ?string $heading = 'Exam Overview for Current Year';

protected function getCards(): array
{
$startofYear = now()->startOfYear();
$endofYear = now()->endOfYear();

$overall = PracticalResult::select(
DB::raw('count(*) as total'),
DB::raw("SUM(CASE WHEN result = '".PracticalResult::PASSED."' THEN 1 ELSE 0 END) as passed"),
DB::raw("SUM(CASE WHEN result = '".PracticalResult::FAILED."' THEN 1 ELSE 0 END) as failed"),
DB::raw("SUM(CASE WHEN result = '".PracticalResult::INCOMPLETE."' THEN 1 ELSE 0 END) as incomplete"),
)
->WhereBetween('date', [$startofYear, $endofYear])
->first();

$examStats = PracticalResult::whereBetween('date', [$startofYear, $endofYear])
->select('exam', 'result', DB::raw('count(*) as total'))
->groupBy('exam', 'result')
->get()
->groupBy('exam');

$cards = [
Stat::make('Total Taken', $overall->total),
Stat::make('Pass Rate', ($overall->total ? round($overall->passed / $overall->total * 100) : 100).'%')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

gotcha with an empty DB edge case 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was aware but decided it didn't really make a difference. Happy to correct to 0

->description("$overall->passed Passed, $overall->failed Failed, $overall->incomplete Incomplete"),
];

$examOrder = ['OBS', 'TWR', 'APP', 'CTR'];

foreach ($examOrder as $exam) {
$results = $examStats->get($exam, collect());
$examTotal = $results->sum('total');
$examPassed = $results->firstWhere('result', PracticalResult::PASSED)->total ?? 0;
$examFailed = $results->firstWhere('result', PracticalResult::FAILED)->total ?? 0;
$examIncomplete = $results->firstWhere('result', PracticalResult::INCOMPLETE)->total ?? 0;

$cards[] = Stat::make("{$exam} Pass Rate", ($examTotal ? round($examPassed / $examTotal * 100) : 100).'%')
->description("$examTotal Total, $examPassed Passed, $examFailed Failed, $examIncomplete Incomplete");
}

return $cards;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace App\Filament\Training\Pages;
namespace App\Filament\Training\Pages\TheoryExam;

use App\Filament\Training\Pages\TheoryExam\Widgets\TheoryExamOverview;
use App\Repositories\Cts\TheoryExamResultRepository;
use Carbon\Carbon;
use Filament\Forms;
Expand Down Expand Up @@ -32,6 +33,13 @@ public static function canAccess(): bool
return auth()->user()->can('training.theory.access');
}

protected function getHeaderWidgets(): array
{
return [
TheoryExamOverview::class,
];
}

protected function buildQuestionPlaceholders($record): array
{

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Filament\Training\Pages\TheoryExam\Widgets;

use App\Models\Cts\TheoryResult;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Facades\DB;

class TheoryExamOverview extends BaseWidget
{
protected ?string $heading = 'Theory Exam Overview for Current Year';

protected function getCards(): array
{
$startofYear = now()->startOfYear();
$endofYear = now()->endOfYear();
$overall = TheoryResult::select(
DB::raw('count(*) as total'),
DB::raw('SUM(CASE WHEN pass = 1 THEN 1 ELSE 0 END) as passed'),
DB::raw('SUM(CASE WHEN pass = 0 THEN 1 ELSE 0 END) as failed')
)
->whereBetween('started', [$startofYear, $endofYear])
->first();

$examStats = TheoryResult::whereBetween('started', [$startofYear, $endofYear])
->select('exam', 'pass', DB::raw('count(*) as total'))
->groupBy('exam', 'pass')
->get()
->groupBy('exam');

$cards = [
Stat::make('Total Taken', $overall->total),
Stat::make('Pass Rate', ($overall->total ? round($overall->passed / $overall->total * 100) : 100).'%')->description("$overall->passed Passed, $overall->failed Failed"),
];

$examOrder = ['S1', 'S2', 'S3', 'C1'];

foreach ($examOrder as $exam) {
$results = $examStats->get($exam, collect());
$examTotal = $results->sum('total');
$examPassed = $results->firstWhere('pass', true)->total ?? 0;
$examFailed = $results->firstWhere('pass', false)->total ?? 0;

$cards[] = Stat::make("{$exam} Pass Rate", ($examTotal ? round($examPassed / $examTotal * 100) : 100).'%')
->description("$examTotal Total, $examPassed Passed, $examFailed Failed");
}

return $cards;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Feature\TrainingPanel\Exams;

use App\Filament\Training\Pages\TheoryExamHistory;
use App\Filament\Training\Pages\TheoryExam\TheoryExamHistory;
use App\Models\Cts\Member;
use App\Models\Cts\TheoryAnswer;
use App\Models\Cts\TheoryQuestion;
Expand Down
Loading