mirror of
https://github.com/the-programmers-hangout/Hermes.git
synced 2026-09-06 07:56:21 +02:00
add website to view stats
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class EmoteGuildStat extends Model
|
||||
{
|
||||
@@ -25,4 +26,110 @@ class EmoteGuildStat extends Model
|
||||
'emote_id'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build aggregate stats for all users.
|
||||
*/
|
||||
public static function dashboardAggregate(): array
|
||||
{
|
||||
$baseQuery = self::query()
|
||||
->join('emotes', 'emote_guild_stats.emote_id', '=', 'emotes.emote_id');
|
||||
|
||||
$summary = (clone $baseQuery)
|
||||
->selectRaw('COALESCE(SUM(emote_guild_stats.usage_count), 0) as total_usage')
|
||||
->selectRaw('COUNT(DISTINCT emote_guild_stats.emote_id) as unique_emotes')
|
||||
->first();
|
||||
|
||||
$usageByType = (clone $baseQuery)
|
||||
->select('emotes.type')
|
||||
->selectRaw('COALESCE(SUM(emote_guild_stats.usage_count), 0) as total_usage')
|
||||
->groupBy('emotes.type')
|
||||
->pluck('total_usage', 'type');
|
||||
|
||||
$unicodeUsage = (int) EmoteLog::query()
|
||||
->join('emotes', 'emote_logs.emote_id', '=', 'emotes.emote_id')
|
||||
->where('emotes.type', 'UNICODE')
|
||||
->count();
|
||||
|
||||
$unicodeUniqueEmotes = (int) EmoteLog::query()
|
||||
->join('emotes', 'emote_logs.emote_id', '=', 'emotes.emote_id')
|
||||
->where('emotes.type', 'UNICODE')
|
||||
->distinct('emote_logs.emote_id')
|
||||
->count('emote_logs.emote_id');
|
||||
|
||||
$topUnicode = EmoteLog::query()
|
||||
->join('emotes', 'emote_logs.emote_id', '=', 'emotes.emote_id')
|
||||
->where('emotes.type', 'UNICODE')
|
||||
->select(
|
||||
'emote_logs.emote_id',
|
||||
'emotes.emote_name',
|
||||
'emotes.type',
|
||||
'emotes.image'
|
||||
)
|
||||
->selectRaw('COUNT(*) as total_usage')
|
||||
->groupBy(
|
||||
'emote_logs.emote_id',
|
||||
'emotes.emote_name',
|
||||
'emotes.type',
|
||||
'emotes.image'
|
||||
)
|
||||
->orderByDesc('total_usage')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
$baseTotalUsage = (int) ($summary->total_usage ?? 0);
|
||||
$baseUniqueEmotes = (int) ($summary->unique_emotes ?? 0);
|
||||
|
||||
return [
|
||||
'total_usage' => $baseTotalUsage + $unicodeUsage,
|
||||
'unique_emotes' => $baseUniqueEmotes + $unicodeUniqueEmotes,
|
||||
'usage_by_type' => [
|
||||
'STATIC' => (int) ($usageByType->get('STATIC') ?? 0),
|
||||
'ANIMATED' => (int) ($usageByType->get('ANIMATED') ?? 0),
|
||||
'UNICODE' => $unicodeUsage,
|
||||
],
|
||||
'top_static' => self::topEmotesByType(
|
||||
$baseQuery,
|
||||
'STATIC',
|
||||
'emote_guild_stats.usage_count',
|
||||
'emote_guild_stats.emote_id'
|
||||
),
|
||||
'top_animated' => self::topEmotesByType(
|
||||
$baseQuery,
|
||||
'ANIMATED',
|
||||
'emote_guild_stats.usage_count',
|
||||
'emote_guild_stats.emote_id'
|
||||
),
|
||||
'top_unicode' => $topUnicode,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a top-10 emote list by type.
|
||||
*/
|
||||
protected static function topEmotesByType(
|
||||
$baseQuery,
|
||||
string $type,
|
||||
string $usageCountColumn,
|
||||
string $emoteIdColumn
|
||||
): Collection {
|
||||
return (clone $baseQuery)
|
||||
->where('emotes.type', $type)
|
||||
->select(
|
||||
$emoteIdColumn.' as emote_id',
|
||||
'emotes.emote_name',
|
||||
'emotes.type',
|
||||
'emotes.image'
|
||||
)
|
||||
->selectRaw("COALESCE(SUM({$usageCountColumn}), 0) as total_usage")
|
||||
->groupBy(
|
||||
$emoteIdColumn,
|
||||
'emotes.emote_name',
|
||||
'emotes.type',
|
||||
'emotes.image'
|
||||
)
|
||||
->orderByDesc('total_usage')
|
||||
->limit(10)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user