Skip to content

Commit

Permalink
feat: intro to season based top-ten
Browse files Browse the repository at this point in the history
  • Loading branch information
iBotPeaches committed Jun 11, 2023
1 parent e091dd5 commit 27ef5e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
20 changes: 20 additions & 0 deletions app/Console/Commands/RefreshAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');

Expand All @@ -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;
}
}
16 changes: 12 additions & 4 deletions app/Support/Analytics/Stats/BestAccuracyServiceRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 27ef5e7

Please sign in to comment.