From ce4e3e69843ed2f051a9f8448df1c272bd180976 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sun, 3 Nov 2024 18:24:07 -0600 Subject: [PATCH] Set ground for changing score sheet total procedure to show precentage of possible. CalculateScoreSheetTotal action converted to interface. DivideByTotalWeights is the old implementation DivideByWeightedPossible is the new implementation Old implementation is currently active in AppServiceProvider. Commented out lines allow for switching. --- .../Tabulation/CalculateScoreSheetTotal.php | 57 +-------------- ...ateScoreSheetTotalDivideByTotalWeights.php | 67 ++++++++++++++++++ ...coreSheetTotalDivideByWeightedPossible.php | 70 +++++++++++++++++++ app/Providers/AppServiceProvider.php | 6 +- 4 files changed, 144 insertions(+), 56 deletions(-) create mode 100644 app/Actions/Tabulation/CalculateScoreSheetTotalDivideByTotalWeights.php create mode 100644 app/Actions/Tabulation/CalculateScoreSheetTotalDivideByWeightedPossible.php diff --git a/app/Actions/Tabulation/CalculateScoreSheetTotal.php b/app/Actions/Tabulation/CalculateScoreSheetTotal.php index 322aec0..ea2ef39 100644 --- a/app/Actions/Tabulation/CalculateScoreSheetTotal.php +++ b/app/Actions/Tabulation/CalculateScoreSheetTotal.php @@ -1,64 +1,11 @@ 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'); - } - } + public function __invoke(string $mode, Entry $entry, User $judge): array; } diff --git a/app/Actions/Tabulation/CalculateScoreSheetTotalDivideByTotalWeights.php b/app/Actions/Tabulation/CalculateScoreSheetTotalDivideByTotalWeights.php new file mode 100644 index 0000000..95c4e16 --- /dev/null +++ b/app/Actions/Tabulation/CalculateScoreSheetTotalDivideByTotalWeights.php @@ -0,0 +1,67 @@ +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 new file mode 100644 index 0000000..c13c223 --- /dev/null +++ b/app/Actions/Tabulation/CalculateScoreSheetTotalDivideByWeightedPossible.php @@ -0,0 +1,70 @@ +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; + } + $finalScore = ($scoreTotal / $weightedMaxPossible) * 100; + // 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/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index f1e8467..73037c7 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -8,6 +8,8 @@ use App\Actions\Schools\SetHeadDirector; use App\Actions\Tabulation\AllowForOlympicScoring; use App\Actions\Tabulation\CalculateEntryScore; use App\Actions\Tabulation\CalculateScoreSheetTotal; +use App\Actions\Tabulation\CalculateScoreSheetTotalDivideByTotalWeights; +use App\Actions\Tabulation\CalculateScoreSheetTotalDivideByWeightedPossible; use App\Models\Audition; use App\Models\Entry; use App\Models\Room; @@ -46,7 +48,9 @@ class AppServiceProvider extends ServiceProvider */ public function register(): void { - $this->app->singleton(CalculateScoreSheetTotal::class, CalculateScoreSheetTotal::class); + //$this->app->singleton(CalculateScoreSheetTotal::class, CalculateScoreSheetTotal::class); + $this->app->singleton(CalculateScoreSheetTotal::class, CalculateScoreSheetTotalDivideByTotalWeights::class); + //$this->app->singleton(CalculateScoreSheetTotal::class, CalculateScoreSheetTotalDivideByWeightedPossible::class); $this->app->singleton(CalculateEntryScore::class, AllowForOlympicScoring::class); $this->app->singleton(DrawService::class, DrawService::class); $this->app->singleton(AuditionService::class, AuditionService::class);