Rewrite tabulation #14

Merged
okorpheus merged 43 commits from rewrite-tabulation into master 2024-07-14 05:36:29 +00:00
4 changed files with 52 additions and 6 deletions
Showing only changes of commit 719b4054d8 - Show all commits

View File

@ -7,17 +7,20 @@ namespace App\Actions\Tabulation;
use App\Exceptions\TabulationException; use App\Exceptions\TabulationException;
use App\Models\Entry; use App\Models\Entry;
use App\Services\AuditionService; use App\Services\AuditionService;
use App\Services\EntryService;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
class AllJudgesCount implements CalculateEntryScore class AllJudgesCount implements CalculateEntryScore
{ {
protected CalculateScoreSheetTotal $calculator; protected CalculateScoreSheetTotal $calculator;
protected AuditionService $auditionService; protected AuditionService $auditionService;
protected EntryService $entryService;
public function __construct(CalculateScoreSheetTotal $calculator, AuditionService $auditionService) public function __construct(CalculateScoreSheetTotal $calculator, AuditionService $auditionService, EntryService $entryService)
{ {
$this->calculator = $calculator; $this->calculator = $calculator;
$this->auditionService = $auditionService; $this->auditionService = $auditionService;
$this->entryService = $entryService;
} }
public function calculate(string $mode, Entry $entry): array public function calculate(string $mode, Entry $entry): array
@ -60,7 +63,7 @@ class AllJudgesCount implements CalculateEntryScore
throw new TabulationException('Mode must be seating or advancement'); throw new TabulationException('Mode must be seating or advancement');
} }
if (! $entry->exists()) { if (! $this->entryService->entryExists($entry)) {
throw new TabulationException('Invalid entry specified'); throw new TabulationException('Invalid entry specified');
} }
} }

View File

@ -71,6 +71,6 @@ class AppServiceProvider extends ServiceProvider
User::observe(UserObserver::class); User::observe(UserObserver::class);
SeatingLimit::observe(SeatingLimitObserver::class); SeatingLimit::observe(SeatingLimitObserver::class);
//Model::preventLazyLoading(! app()->isProduction()); Model::preventLazyLoading(! app()->isProduction());
} }
} }

View File

@ -42,21 +42,65 @@ class AuditionService
'seating' => 'for_seating', 'seating' => 'for_seating',
'advancement' => 'for_advance', 'advancement' => 'for_advance',
}; };
$audition->load('scoringGuide.subscores');
return $audition->scoringGuide->subscores->where($modeColumn, true)->sortBy($sortColumn); return $audition->scoringGuide->subscores->where($modeColumn, true)->sortBy($sortColumn);
}); });
} }
public function getJudges(Audition $audition) public function getSubscoresNEW(Audition $audition, $mode = 'seating', $sort = 'tiebreak')
{
$this->validateMode($mode);
$this->validateSort($sort);
$cacheKey = 'auditionSubscores-'.$mode.'-'.$sort;
$assignments = Cache::remember($cacheKey, 60, function () use ($audition, $mode, $sort) {
$this->validateAudition($audition);
$sortColumn = match ($sort) {
'tiebreak' => 'tiebreak_order',
'display' => 'display_order',
};
$modeColumn = match ($mode) {
'seating' => 'for_seating',
'advancement' => 'for_advance',
};
$allAuditions = Audition::with(['scoringGuide.subscores' => function ($query) use ($modeColumn, $sortColumn) {
$query->where($modeColumn, 1)->orderBy($sortColumn);
}])->get();
$return = [];
foreach ( $allAuditions as $audition) {
$return[$audition->id] = $audition->scoringGuide->subscores;
}
return $return;
});
return $assignments[$audition->id];
}
public function getJudgesOLD(Audition $audition)
{ {
$cacheKey = 'auditionJudges-'.$audition->id; $cacheKey = 'auditionJudges-'.$audition->id;
return Cache::remember($cacheKey, 10, function () use ($audition) { return Cache::remember($cacheKey, 10, function () use ($audition) {
$this->validateAudition($audition); $this->validateAudition($audition);
return $audition->judges; return $audition->judges;
}); });
} }
public function getJudges(Audition $audition)
{
$cacheKey = 'auditionJudgeAssignments';
$assignments = Cache::remember($cacheKey, 60, function () {
$allAuditions = Audition::with('judges')->get();
$return = [];
foreach ($allAuditions as $audition) {
$return[$audition->id] = $audition->judges;
}
return $return;
});
return $assignments[$audition->id];
}
protected function validateAudition($audition) protected function validateAudition($audition)
{ {
if (! $audition->exists()) { if (! $audition->exists()) {

View File

@ -130,7 +130,6 @@ it('correctly calculates scores for advancement', function () {
1004 => 85, 1004 => 85,
1005 => 95, 1005 => 95,
]; ];
#$calculator = new AllJudgesCount();
$calculator = App::make(AllJudgesCount::class); $calculator = App::make(AllJudgesCount::class);
enterScore($judge1, $entry, $scores); enterScore($judge1, $entry, $scores);
enterScore($judge2, $entry, $scores2); enterScore($judge2, $entry, $scores2);