Bonus Score Use
#20 Implement bonus scores Bonus score is now included in total scores for seating.
This commit is contained in:
parent
579a0a2fc3
commit
c04dd02405
|
|
@ -5,20 +5,27 @@
|
|||
namespace App\Actions\Tabulation;
|
||||
|
||||
use App\Exceptions\TabulationException;
|
||||
use App\Models\BonusScore;
|
||||
use App\Models\Entry;
|
||||
use App\Services\AuditionService;
|
||||
use App\Services\EntryService;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
use function auditionSetting;
|
||||
|
||||
class AllowForOlympicScoring implements CalculateEntryScore
|
||||
{
|
||||
protected CalculateScoreSheetTotal $calculator;
|
||||
|
||||
protected AuditionService $auditionService;
|
||||
|
||||
protected EntryService $entryService;
|
||||
|
||||
public function __construct(CalculateScoreSheetTotal $calculator, AuditionService $auditionService, EntryService $entryService)
|
||||
{
|
||||
public function __construct(
|
||||
CalculateScoreSheetTotal $calculator,
|
||||
AuditionService $auditionService,
|
||||
EntryService $entryService
|
||||
) {
|
||||
$this->calculator = $calculator;
|
||||
$this->auditionService = $auditionService;
|
||||
$this->entryService = $entryService;
|
||||
|
|
@ -28,6 +35,7 @@ class AllowForOlympicScoring implements CalculateEntryScore
|
|||
{
|
||||
|
||||
$cacheKey = 'entryScore-'.$entry->id.'-'.$mode;
|
||||
|
||||
return Cache::remember($cacheKey, 10, function () use ($mode, $entry) {
|
||||
$this->basicValidation($mode, $entry);
|
||||
$this->areAllJudgesIn($entry);
|
||||
|
|
@ -38,7 +46,7 @@ class AllowForOlympicScoring implements CalculateEntryScore
|
|||
|
||||
}
|
||||
|
||||
protected function getJudgeTotals($mode, Entry $entry)
|
||||
protected function getJudgeTotals($mode, Entry $entry): array
|
||||
{
|
||||
|
||||
$scores = [];
|
||||
|
|
@ -55,7 +63,7 @@ class AllowForOlympicScoring implements CalculateEntryScore
|
|||
// remove the highest and lowest scores
|
||||
array_pop($scores);
|
||||
array_shift($scores);
|
||||
}
|
||||
}
|
||||
$sums = [];
|
||||
// Sum each subscore from the judges
|
||||
foreach ($scores as $score) {
|
||||
|
|
@ -66,9 +74,33 @@ class AllowForOlympicScoring implements CalculateEntryScore
|
|||
$index++;
|
||||
}
|
||||
}
|
||||
// add the bonus points for a seating mode
|
||||
if ($mode === 'seating') {
|
||||
$sums[0] += $this->getBonusPoints($entry);
|
||||
}
|
||||
|
||||
return $sums;
|
||||
}
|
||||
|
||||
protected function getBonusPoints(Entry $entry)
|
||||
{
|
||||
|
||||
$bonusScoreDefinition = $entry->audition->bonusScore()->first();
|
||||
if (! $bonusScoreDefinition) {
|
||||
return 0;
|
||||
}
|
||||
$bonusJudges = $bonusScoreDefinition->judges;
|
||||
$bonusScoreSheets = BonusScore::where('entry_id', $entry->id)->get();
|
||||
foreach ($bonusScoreSheets as $sheet) {
|
||||
if (! $bonusJudges->contains($sheet->user_id)) {
|
||||
throw new TabulationException('Entry has a bonus score from unassigned judge');
|
||||
}
|
||||
}
|
||||
|
||||
// sum the score property of the $bonusScoreSheets
|
||||
return $bonusScoreSheets->sum('score');
|
||||
}
|
||||
|
||||
protected function basicValidation($mode, $entry): void
|
||||
{
|
||||
if ($mode !== 'seating' && $mode !== 'advancement') {
|
||||
|
|
|
|||
Loading…
Reference in New Issue