diff --git a/app/Console/Commands/RefreshAnalytics.php b/app/Console/Commands/RefreshAnalytics.php index beceedfa..fef62b47 100644 --- a/app/Console/Commands/RefreshAnalytics.php +++ b/app/Console/Commands/RefreshAnalytics.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use App\Jobs\ProcessAnalytic; +use App\Models\Season; use App\Support\Analytics\AnalyticInterface; use Illuminate\Console\Command; use Illuminate\Support\Facades\Storage; @@ -20,7 +21,9 @@ class RefreshAnalytics extends Command public function handle(): int { $availableAnalytics = Storage::disk('stats')->files(); + $seasons = Season::all(); + // ALL foreach ($availableAnalytics as $availableAnalytic) { $analytic = 'App\Support\Analytics\Stats\\'.Str::before($availableAnalytic, '.php'); @@ -35,6 +38,23 @@ public function handle(): int $this->output->writeln('Processed in '.(time() - $startTime).' seconds.'); } + // Seasons + $seasons->each(function (Season $season) use ($availableAnalytics) { + foreach ($availableAnalytics as $availableAnalytic) { + $analytic = 'App\Support\Analytics\Stats\\'.Str::before($availableAnalytic, '.php'); + + /** @var AnalyticInterface $analyticClass */ + $analyticClass = new $analytic($season); + + $startTime = time(); + $this->output->writeln('Processing: '.$analyticClass->title()); + + ProcessAnalytic::dispatchSync($analyticClass); + + $this->output->writeln('Processed in '.(time() - $startTime).' seconds.'); + } + }); + return CommandAlias::SUCCESS; } } diff --git a/app/Support/Analytics/Stats/BestAccuracyServiceRecord.php b/app/Support/Analytics/Stats/BestAccuracyServiceRecord.php index 39e6bf8e..1717d990 100644 --- a/app/Support/Analytics/Stats/BestAccuracyServiceRecord.php +++ b/app/Support/Analytics/Stats/BestAccuracyServiceRecord.php @@ -45,16 +45,24 @@ public function displayProperty(Analytic $analytic): string public function results(int $limit = 10): ?Collection { - return $this->builder() + $seasonKey = $this->season?->key; + + $query = $this->builder() ->select('service_records.*') ->with(['player']) ->leftJoin('players', 'players.id', '=', 'service_records.player_id') ->where('is_cheater', false) ->where('mode', Mode::MATCHMADE_PVP) - ->whereNull('season_number') ->where('total_matches', '>=', 1000) ->orderByDesc($this->property()) - ->limit($limit) - ->get(); + ->limit($limit); + + if ($seasonKey) { + $query->where('season_key', $seasonKey); + } else { + $query->whereNull('season_key'); + } + + return $query->get(); } }