Keywords - User Rating : {{ ucwords($key_words->name) }}
Categories
@php
// Group data by sector and calculate total categories per sector
$groupedData = $key_ranking_grouped
->groupBy('sector_name')
->map(function ($group) {
return [
'total_categories' => $group->sum('total_categories'),
'data' => $group,
];
})
->sortByDesc('total_categories')
->take(5);
@endphp
@if ($groupedData->count() > 0)
@foreach ($groupedData as $sectorName => $sectorData)
@php
$group = $sectorData['data']; // Get original data for this sector
$sectorLabels = $group->sortByDesc('total_categories')->pluck('cat_name')->take(5);
$sectorCounts = $group
->sortByDesc('total_categories')
->pluck('average_rating')
->take(5);
// Calculate total and average rating per keyword
$keywordRatings = $group->groupBy('keyword_name')->map(function ($keywords) {
$totalRating = $keywords->sum('rating'); // Sum of all ratings
$maxPossibleRating = $keywords->count() * 5; // Assuming rating is out of 5
$averageRating =
$maxPossibleRating > 0
? round(($totalRating / $maxPossibleRating) * 5, 2)
: 0;
return [
'total_rating' => $totalRating,
'average_rating' => $averageRating,
];
});
@endphp
@foreach ($keywordRatings as $keyword => $ratings)
@endforeach
11.2%
@endforeach
@endif
{{ ucwords($sectorName) }}
| S.No. | Username | Category | Sector | Rating | Date | Time | |||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{ $key + 1 + ($key_ranking_all->currentPage() - 1) * $key_ranking_all->perPage() }} |
{{ ucwords($data->user_name ?? $data->ip_address) }} |
{{ ucwords($data->cat_name) }} | {{ ucwords($data->sector_name) }} |
|
{{ $data->created_at->format('Y-m-d') }} | {{ $data->created_at->format('H:i:s A') }} | |||||||||||||||||||||||||||||||||||||||||||
@if (!empty(request()->search)) No result found @else No data found @endif | |||||||||||||||||||||||||||||||||||||||||||||||||
Total Keyword(s): {{ $total_all }}
{{ $key_ranking_all->appends(request()->input())->links() }}