Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
44 changes: 44 additions & 0 deletions app/Filament/Training/Pages/Exam/Widgets/ExamOverview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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 function getCards(): array
{
$total = PracticalResult::count();
$passed = PracticalResult::where('result', PracticalResult::PASSED)->count();
$failed = PracticalResult::where('result', PracticalResult::FAILED)->count();
$incomplete = PracticalResult::where('result', PracticalResult::INCOMPLETE)->count();

$examStats = PracticalResult::select('exam', 'result', DB::raw('count(*) as total'))
Copy link
Contributor

@kristiankunc kristiankunc Dec 7, 2025

Choose a reason for hiding this comment

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

Not sure what @AxonC thinks, but I feel like this query will eat us in prod. Thinking about some pagination such as quarterly/yearly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It did cross my mind....
What if we tried to combine it?
Id be interested to know how the CTS shows these stats.

->groupBy('exam', 'result')
->get()
->groupBy('exam');

$cards = [
Stat::make('Total Taken', $total),
Stat::make('Pass Rate', ($total ? round($passed / $total * 100) : 100).'%')->description("$passed Passed, $failed Failed, $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,42 @@
<?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 function getCards(): array
{
$total = TheoryResult::count();
$passed = TheoryResult::where('pass', true)->count();
$failed = TheoryResult::where('pass', false)->count();

$examStats = TheoryResult::select('exam', 'pass', DB::raw('count(*) as total'))
->groupBy('exam', 'pass')
->get()
->groupBy('exam');

$cards = [
Stat::make('Total Taken', $total),
Stat::make('Pass Rate', ($total ? round($passed / $total * 100) : 100).'%')->description("$passed Passed, $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