diff --git a/app/Http/Controllers/Admin/ServerIntelController.php b/app/Http/Controllers/Admin/ServerIntelController.php index de4a21741..e79eda5e5 100644 --- a/app/Http/Controllers/Admin/ServerIntelController.php +++ b/app/Http/Controllers/Admin/ServerIntelController.php @@ -46,31 +46,28 @@ public function overview(Request $request) * Start: LAST 7 DAYS STATS */ // Unique Players Count - $uniquePlayers = MinecraftPlayerSession::select(['player_uuid']) + $uniquePlayersCount = MinecraftPlayer::select(['player_uuid']) ->when($selectedServers, function ($query, $selectedServers) { $query->whereIn('server_id', $selectedServers); }) - ->where('created_at', '>=', now()->subWeek()) - ->distinct()->get(); - $uniquePlayersCount = $uniquePlayers->count(); + ->where('last_seen_at', '>=', now()->subWeek()) + ->distinct()->count('player_uuid'); // Old & New Players Count - $uniquePlayersSubquery = MinecraftPlayerSession::select(['player_uuid']) + $oldPlayersCount = MinecraftPlayer::select(['player_uuid']) ->when($selectedServers, function ($query, $selectedServers) { $query->whereIn('server_id', $selectedServers); }) - ->where('created_at', '>=', now()->subWeek()) - ->distinct() - ->getQuery(); - $oldPlayers = MinecraftPlayerSession::select(['player_uuid']) + ->where('first_seen_at', '<', now()->subWeek()) + ->where('last_seen_at', '>=', now()->subWeek()) + ->distinct()->count('player_uuid'); + + $newPlayersCount = MinecraftPlayer::select(['player_uuid']) ->when($selectedServers, function ($query, $selectedServers) { $query->whereIn('server_id', $selectedServers); }) - ->where('created_at', '<', now()->subWeek()) - ->whereIn('player_uuid', $uniquePlayersSubquery) - ->distinct()->get(); - $oldPlayersCount = $oldPlayers->count(); - $newPlayersCount = $uniquePlayers->whereNotIn('player_uuid', $oldPlayers->pluck('player_uuid'))->count(); + ->where('first_seen_at', '>=', now()->subWeek()) + ->distinct()->count('player_uuid'); // Peek Online Players $peekOnlinePlayersCount = MinecraftServerLiveInfo::query() diff --git a/app/Jobs/CalculatePlayersRatingJob.php b/app/Jobs/CalculatePlayersRatingJob.php index 6b48a6032..cfd4b9159 100644 --- a/app/Jobs/CalculatePlayersRatingJob.php +++ b/app/Jobs/CalculatePlayersRatingJob.php @@ -14,6 +14,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Log; class CalculatePlayersRatingJob implements ShouldQueue { @@ -33,6 +34,8 @@ public function __construct() */ public function handle(PlayerSettings $playerSettings, PluginSettings $pluginSettings) { + Log::info("[RatingJob] Starting calculating rating & ranks for all players"); + $server = null; if ($pluginSettings->enable_sync_player_ranks_from_server) { $server = Server::where('id', $pluginSettings->sync_player_ranks_from_server_id)->first(); @@ -69,7 +72,7 @@ public function handle(PlayerSettings $playerSettings, PluginSettings $pluginSet $pT->save(); } - \Log::info("[RatingJob] Finished calculating rating & ranks for all players"); + Log::info("[RatingJob] Finished calculating rating & ranks for all players"); } private function calculatePlayerRating($player, $minScore, $maxScore, PlayerSettings $playerSettings, array $serverIds): int|null @@ -87,7 +90,7 @@ private function calculatePlayerRating($player, $minScore, $maxScore, PlayerSett $playerRatingCalculator = new PlayerRatingCalculator(); $rating = $playerRatingCalculator->calculate($playerSettings->custom_rating_expression, $player, $serverIds); } catch (\Exception $e) { - \Log::critical($e); + Log::critical($e); $rating = null; } } else { @@ -128,7 +131,7 @@ private function calculatePlayerRankIdFromServerWebQuery($serverHost, $serverPor ->orderByDesc('weight')->first()?->id; } } catch(\Exception $e) { - \Log::critical($e); + Log::critical($e); } return $rankId; diff --git a/app/Jobs/CalculatePlayersScoreJob.php b/app/Jobs/CalculatePlayersScoreJob.php index f3dca3ad9..3be908ade 100644 --- a/app/Jobs/CalculatePlayersScoreJob.php +++ b/app/Jobs/CalculatePlayersScoreJob.php @@ -31,6 +31,7 @@ public function __construct() */ public function handle(PlayerSettings $playerSettings) { + Log::info('[ScoreJob] Starting calculating scores for all players'); $playerSettings->refresh(); // id list of all servers. @@ -48,8 +49,6 @@ public function handle(PlayerSettings $playerSettings) ->selectRaw('sum(vault_balance) as vault_balance') ->first(); if ($mcPlayerDataFromServer->updated_at < $player->updated_at && ! $shouldForceRunForAllPlayers) { - Log::info('[ScoreJob] Skipping player: '.$player->uuid.' as it is already up to date'); - continue; } @@ -59,8 +58,6 @@ public function handle(PlayerSettings $playerSettings) 'total_score' => $score, 'total_money' => $mcPlayerDataFromServer->vault_balance ?? 0, ]); - - Log::info('[ScoreJob] Calculated score for player: '.$player->uuid.' as '.$score); } Log::info('[ScoreJob] Finished calculating scores for all players');