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);