From 58f29f326c13835bbc87c4d9bb1b92ed60641da2 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 11 Jun 2025 23:03:35 -0500 Subject: [PATCH] Remove depricated files --- app/Actions/Tabulation/AllJudgesCount.php | 99 ----------- .../Tabulation/AllowForOlympicScoring.php | 161 ------------------ .../Tabulation/CalculateEntryScore.php | 11 -- .../Tabulation/CalculateScoreSheetTotal.php | 11 -- ...ateScoreSheetTotalDivideByTotalWeights.php | 67 -------- ...coreSheetTotalDivideByWeightedPossible.php | 74 -------- app/Models/CalculatedScore.php | 15 -- 7 files changed, 438 deletions(-) delete mode 100644 app/Actions/Tabulation/AllJudgesCount.php delete mode 100644 app/Actions/Tabulation/AllowForOlympicScoring.php delete mode 100644 app/Actions/Tabulation/CalculateEntryScore.php delete mode 100644 app/Actions/Tabulation/CalculateScoreSheetTotal.php delete mode 100644 app/Actions/Tabulation/CalculateScoreSheetTotalDivideByTotalWeights.php delete mode 100644 app/Actions/Tabulation/CalculateScoreSheetTotalDivideByWeightedPossible.php delete mode 100644 app/Models/CalculatedScore.php diff --git a/app/Actions/Tabulation/AllJudgesCount.php b/app/Actions/Tabulation/AllJudgesCount.php deleted file mode 100644 index 0089211..0000000 --- a/app/Actions/Tabulation/AllJudgesCount.php +++ /dev/null @@ -1,99 +0,0 @@ -calculator = $calculator; - $this->auditionService = $auditionService; - $this->entryService = $entryService; - } - - public function calculate(string $mode, Entry $entry): array - { - - $cacheKey = 'entryScore-'.$entry->id.'-'.$mode; - - return Cache::remember($cacheKey, 300, function () use ($mode, $entry) { - $this->isEntryANoShow($entry); - $this->basicValidation($mode, $entry); - $this->areAllJudgesIn($entry); - $this->areAllJudgesValid($entry); - - return $this->getJudgeTotals($mode, $entry); - }); - - } - - protected function getJudgeTotals($mode, Entry $entry) - { - - $scores = []; - foreach ($this->auditionService->getJudges($entry->audition) as $judge) { - $scores[] = $this->calculator->__invoke($mode, $entry, $judge); - } - $sums = []; - // Sum each subscore from the judges - foreach ($scores as $score) { - $index = 0; - foreach ($score as $value) { - $sums[$index] = $sums[$index] ?? 0; - $sums[$index] += $value; - $index++; - } - } - - return $sums; - } - - protected function basicValidation($mode, $entry): void - { - if ($mode !== 'seating' && $mode !== 'advancement') { - throw new TabulationException('Mode must be seating or advancement'); - } - - if (! $this->entryService->entryExists($entry)) { - throw new TabulationException('Invalid entry specified'); - } - } - - protected function areAllJudgesIn(Entry $entry): void - { - $assignedJudgeCount = $this->auditionService->getJudges($entry->audition)->count(); - if ($entry->scoreSheets->count() !== $assignedJudgeCount) { - throw new TabulationException('Not all score sheets are in'); - } - } - - protected function areAllJudgesValid(Entry $entry): void - { - $validJudgeIds = $this->auditionService->getJudges($entry->audition)->pluck('id')->sort()->toArray(); - $existingJudgeIds = $entry->scoreSheets->pluck('user_id')->sort()->toArray(); - if ($validJudgeIds !== $existingJudgeIds) { - throw new TabulationException('Score exists from a judge not assigned to this audition'); - } - } - - protected function isEntryANoShow(Entry $entry): void - { - if ($entry->hasFlag('no_show')) { - throw new TabulationException('No Show'); - } - } -} diff --git a/app/Actions/Tabulation/AllowForOlympicScoring.php b/app/Actions/Tabulation/AllowForOlympicScoring.php deleted file mode 100644 index 44c237b..0000000 --- a/app/Actions/Tabulation/AllowForOlympicScoring.php +++ /dev/null @@ -1,161 +0,0 @@ -calculator = $calculator; - $this->auditionService = $auditionService; - $this->entryService = $entryService; - } - - public function calculate(string $mode, Entry $entry): array - { - $calculated = CalculatedScore::where('entry_id', $entry->id)->where('mode', $mode)->first(); - if ($calculated) { - return $calculated->calculatedScore; - } - - $cacheKey = 'entryScore-'.$entry->id.'-'.$mode; - - return Cache::remember($cacheKey, 300, function () use ($mode, $entry) { - $this->basicValidation($mode, $entry); - $this->isEntryANoShow($entry); - $this->areAllJudgesIn($entry); - $this->areAllJudgesValid($entry); - $calculatedScores = $this->getJudgeTotals($mode, $entry); - CalculatedScore::create([ - 'entry_id' => $entry->id, - 'mode' => $mode, - 'calculatedScore' => $calculatedScores, - ]); - - return $calculatedScores; - // return $this->getJudgeTotals($mode, $entry); - }); - - } - - protected function getJudgeTotals($mode, Entry $entry): array - { - - $scores = []; - foreach ($this->auditionService->getJudges($entry->audition) as $judge) { - $scores[] = $this->calculator->__invoke($mode, $entry, $judge); - } - // sort the scores array by the total score - usort($scores, function ($a, $b) { - return $a[0] <=> $b[0]; - }); - - // we can only really do olympic scoring if there are at least 3 scores - if (count($scores) >= 3 && auditionSetting('olympic_scoring')) { - // remove the highest and lowest scores - array_pop($scores); - array_shift($scores); - } - $sums = []; - // Sum each subscore from the judges - foreach ($scores as $score) { - $index = 0; - foreach ($score as $value) { - $sums[$index] = $sums[$index] ?? 0; - $sums[$index] += $value; - $index++; - } - } - // add the bonus points for a seating mode - if ($mode === 'seating' && $sums) { - - $sums[0] += $this->getBonusPoints($entry); - } - - return $sums; - } - - protected function getBonusPoints(Entry $entry) - { - - $bonusScoreDefinition = $entry->audition->bonusScore()->first(); - if (! $bonusScoreDefinition) { - return 0; - } - /** @noinspection PhpPossiblePolymorphicInvocationInspection */ - $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') { - throw new TabulationException('Mode must be seating or advancement'); - } - - if (! $this->entryService->entryExists($entry)) { - throw new TabulationException('Invalid entry specified'); - } - } - - protected function areAllJudgesIn(Entry $entry): void - { - $assignedJudgeCount = $this->auditionService->getJudges($entry->audition)->count(); - if ($entry->scoreSheets->count() !== $assignedJudgeCount) { - throw new TabulationException('Not all score sheets are in'); - } - } - - protected function areAllJudgesValid(Entry $entry): void - { - $validJudgeIds = $this->auditionService->getJudges($entry->audition)->pluck('id')->toArray(); - $existingJudgeIds = $entry->scoreSheets->pluck('user_id')->toArray(); - if (array_diff($existingJudgeIds, $validJudgeIds)) { - Log::debug('EntryID: '.$entry->id); - Log::debug('Valid judge ids: ('.gettype($validJudgeIds).') '.json_encode($validJudgeIds)); - Log::debug('Existing judge ids: ('.gettype($existingJudgeIds).') '.json_encode($existingJudgeIds)); - throw new TabulationException('Score exists from a judge not assigned to this audition'); - } - } - - protected function isEntryANoShow(Entry $entry): void - { - if ($entry->hasFlag('failed_prelim')) { - throw new TabulationException('Failed Prelim'); - } - - if ($entry->hasFlag('no_show')) { - throw new TabulationException('No Show'); - } - } -} diff --git a/app/Actions/Tabulation/CalculateEntryScore.php b/app/Actions/Tabulation/CalculateEntryScore.php deleted file mode 100644 index 8cb48a8..0000000 --- a/app/Actions/Tabulation/CalculateEntryScore.php +++ /dev/null @@ -1,11 +0,0 @@ -auditionService = $auditionService; - $this->entryService = $entryService; - $this->userService = $userService; - } - - public function __invoke(string $mode, Entry $entry, User $judge): array - { - $this->basicValidations($mode, $entry, $judge); - $scoreSheet = ScoreSheet::where('entry_id', $entry->id)->where('user_id', $judge->id)->first(); - if (! $scoreSheet) { - throw new TabulationException('No score sheet by that judge for that entry'); - } - $subscores = $this->auditionService->getSubscores($entry->audition, $mode); - $scoreTotal = 0; - $weightsTotal = 0; - $scoreArray = []; - foreach ($subscores as $subscore) { - $weight = $subscore['weight']; - $score = $scoreSheet->subscores[$subscore->id]['score']; - $scoreArray[] = $score; - $scoreTotal += ($score * $weight); - $weightsTotal += $weight; - } - $finalScore = $scoreTotal / $weightsTotal; - // put $final score at the beginning of the $ScoreArray - array_unshift($scoreArray, $finalScore); - - return $scoreArray; - } - - protected function basicValidations($mode, $entry, $judge): void - { - if ($mode !== 'seating' and $mode !== 'advancement') { - throw new TabulationException('Invalid mode requested. Mode must be seating or advancement'); - } - if (! $this->entryService->entryExists($entry)) { - throw new TabulationException('Invalid entry provided'); - } - if (! $this->userService->userExists($judge)) { - throw new TabulationException('Invalid judge provided'); - } - } -} diff --git a/app/Actions/Tabulation/CalculateScoreSheetTotalDivideByWeightedPossible.php b/app/Actions/Tabulation/CalculateScoreSheetTotalDivideByWeightedPossible.php deleted file mode 100644 index 55107bc..0000000 --- a/app/Actions/Tabulation/CalculateScoreSheetTotalDivideByWeightedPossible.php +++ /dev/null @@ -1,74 +0,0 @@ -auditionService = $auditionService; - $this->entryService = $entryService; - $this->userService = $userService; - } - - public function __invoke(string $mode, Entry $entry, User $judge): array - { - $this->basicValidations($mode, $entry, $judge); - $scoreSheet = ScoreSheet::where('entry_id', $entry->id)->where('user_id', $judge->id)->first(); - if (! $scoreSheet) { - throw new TabulationException('No score sheet by that judge for that entry'); - } - $subscores = $this->auditionService->getSubscores($entry->audition, $mode); - $scoreTotal = 0; - $weightsTotal = 0; - $weightedMaxPossible = 0; - $scoreArray = []; - foreach ($subscores as $subscore) { - $weight = $subscore['weight']; - $score = $scoreSheet->subscores[$subscore->id]['score']; - $maxPossible = $subscore['max_score']; - $scoreArray[] = $score; - $scoreTotal += ($score * $weight); - $weightsTotal += $weight; - $weightedMaxPossible += $maxPossible; - } - if ($weightedMaxPossible > 0) { - $finalScore = ($scoreTotal / $weightedMaxPossible) * 100; - } else { - $finalScore = 0; - } - // put $final score at the beginning of the $ScoreArray - array_unshift($scoreArray, $finalScore); - - return $scoreArray; - } - - protected function basicValidations($mode, $entry, $judge): void - { - if ($mode !== 'seating' and $mode !== 'advancement') { - throw new TabulationException('Invalid mode requested. Mode must be seating or advancement'); - } - if (! $this->entryService->entryExists($entry)) { - throw new TabulationException('Invalid entry provided'); - } - if (! $this->userService->userExists($judge)) { - throw new TabulationException('Invalid judge provided'); - } - } -} diff --git a/app/Models/CalculatedScore.php b/app/Models/CalculatedScore.php deleted file mode 100644 index f514d8d..0000000 --- a/app/Models/CalculatedScore.php +++ /dev/null @@ -1,15 +0,0 @@ - 'json']; -}