Dashboard: add top 10 candidates and update global scores
This commit is contained in:
@@ -20,13 +20,32 @@ use App\Models\Attempt;
|
||||
Route::get('/dashboard', function () {
|
||||
$stats = [];
|
||||
$quizzes = [];
|
||||
$topCandidates = [];
|
||||
|
||||
if (auth()->user()->isAdmin()) {
|
||||
$allCandidates = Candidate::with(['attempts'])->get();
|
||||
$stats = [
|
||||
'total_candidates' => Candidate::count(),
|
||||
'finished_tests' => Attempt::whereNotNull('finished_at')->count(),
|
||||
'average_score' => round(Attempt::whereNotNull('finished_at')->avg('score') ?? 0, 1),
|
||||
'best_score' => Attempt::whereNotNull('finished_at')->max('score') ?? 0,
|
||||
'average_score' => round($allCandidates->avg('weighted_score') ?? 0, 1),
|
||||
'best_score' => round($allCandidates->max('weighted_score') ?? 0, 1),
|
||||
];
|
||||
|
||||
$topCandidates = Candidate::with(['user', 'attempts'])
|
||||
->get()
|
||||
->sortByDesc('weighted_score')
|
||||
->take(10)
|
||||
->map(function($candidate) {
|
||||
return [
|
||||
'id' => $candidate->id,
|
||||
'name' => $candidate->user->name,
|
||||
'email' => $candidate->user->email,
|
||||
'status' => $candidate->status,
|
||||
'weighted_score' => $candidate->weighted_score
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
} else {
|
||||
$candidate = auth()->user()->candidate;
|
||||
$quizzes = \App\Models\Quiz::all()->map(function($quiz) use ($candidate) {
|
||||
@@ -39,7 +58,8 @@ Route::get('/dashboard', function () {
|
||||
|
||||
return Inertia::render('Dashboard', [
|
||||
'stats' => $stats,
|
||||
'quizzes' => $quizzes
|
||||
'quizzes' => $quizzes,
|
||||
'top_candidates' => $topCandidates
|
||||
]);
|
||||
})->middleware(['auth', 'verified'])->name('dashboard');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user