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;
|
namespace App\Actions\Tabulation;
|
||||||
|
|
||||||
use App\Exceptions\TabulationException;
|
use App\Exceptions\TabulationException;
|
||||||
|
use App\Models\BonusScore;
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
use App\Services\AuditionService;
|
use App\Services\AuditionService;
|
||||||
use App\Services\EntryService;
|
use App\Services\EntryService;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
use function auditionSetting;
|
use function auditionSetting;
|
||||||
|
|
||||||
class AllowForOlympicScoring implements CalculateEntryScore
|
class AllowForOlympicScoring implements CalculateEntryScore
|
||||||
{
|
{
|
||||||
protected CalculateScoreSheetTotal $calculator;
|
protected CalculateScoreSheetTotal $calculator;
|
||||||
|
|
||||||
protected AuditionService $auditionService;
|
protected AuditionService $auditionService;
|
||||||
|
|
||||||
protected EntryService $entryService;
|
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->calculator = $calculator;
|
||||||
$this->auditionService = $auditionService;
|
$this->auditionService = $auditionService;
|
||||||
$this->entryService = $entryService;
|
$this->entryService = $entryService;
|
||||||
|
|
@ -28,6 +35,7 @@ class AllowForOlympicScoring implements CalculateEntryScore
|
||||||
{
|
{
|
||||||
|
|
||||||
$cacheKey = 'entryScore-'.$entry->id.'-'.$mode;
|
$cacheKey = 'entryScore-'.$entry->id.'-'.$mode;
|
||||||
|
|
||||||
return Cache::remember($cacheKey, 10, function () use ($mode, $entry) {
|
return Cache::remember($cacheKey, 10, function () use ($mode, $entry) {
|
||||||
$this->basicValidation($mode, $entry);
|
$this->basicValidation($mode, $entry);
|
||||||
$this->areAllJudgesIn($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 = [];
|
$scores = [];
|
||||||
|
|
@ -55,7 +63,7 @@ class AllowForOlympicScoring implements CalculateEntryScore
|
||||||
// remove the highest and lowest scores
|
// remove the highest and lowest scores
|
||||||
array_pop($scores);
|
array_pop($scores);
|
||||||
array_shift($scores);
|
array_shift($scores);
|
||||||
}
|
}
|
||||||
$sums = [];
|
$sums = [];
|
||||||
// Sum each subscore from the judges
|
// Sum each subscore from the judges
|
||||||
foreach ($scores as $score) {
|
foreach ($scores as $score) {
|
||||||
|
|
@ -66,9 +74,33 @@ class AllowForOlympicScoring implements CalculateEntryScore
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// add the bonus points for a seating mode
|
||||||
|
if ($mode === 'seating') {
|
||||||
|
$sums[0] += $this->getBonusPoints($entry);
|
||||||
|
}
|
||||||
|
|
||||||
return $sums;
|
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
|
protected function basicValidation($mode, $entry): void
|
||||||
{
|
{
|
||||||
if ($mode !== 'seating' && $mode !== 'advancement') {
|
if ($mode !== 'seating' && $mode !== 'advancement') {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue