43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\AIDecision;
|
|
use App\Models\Article;
|
|
use App\Models\Feedback;
|
|
use App\Models\Ticket;
|
|
|
|
class AdminDashboardService
|
|
{
|
|
public function stats(): array
|
|
{
|
|
return [
|
|
'articles_count' => Article::query()->count(),
|
|
'tickets_count' => Ticket::query()->count(),
|
|
'decisions_count' => AIDecision::query()->count(),
|
|
'feedback_accuracy' => $this->feedbackAccuracy(),
|
|
];
|
|
}
|
|
|
|
public function recentTickets(int $limit = 10)
|
|
{
|
|
return Ticket::query()->latest()->limit($limit)->get();
|
|
}
|
|
|
|
public function recentDecisions(int $limit = 10)
|
|
{
|
|
return AIDecision::query()->with(['ticket', 'article'])->latest()->limit($limit)->get();
|
|
}
|
|
|
|
private function feedbackAccuracy(): ?float
|
|
{
|
|
$total = Feedback::query()->count();
|
|
if ($total === 0) {
|
|
return null;
|
|
}
|
|
|
|
$correct = Feedback::query()->where('is_correct', true)->count();
|
|
return round(($correct / $total) * 100, 2);
|
|
}
|
|
}
|