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.
This commit is contained in:
parent
42a5cef684
commit
ce4e3e6984
|
|
@ -1,64 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/** @noinspection PhpUnhandledExceptionInspection */
|
|
||||||
|
|
||||||
namespace App\Actions\Tabulation;
|
namespace App\Actions\Tabulation;
|
||||||
|
|
||||||
use App\Exceptions\TabulationException;
|
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
use App\Models\ScoreSheet;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\AuditionService;
|
|
||||||
use App\Services\EntryService;
|
|
||||||
use App\Services\UserService;
|
|
||||||
|
|
||||||
class CalculateScoreSheetTotal
|
interface CalculateScoreSheetTotal
|
||||||
{
|
{
|
||||||
protected AuditionService $auditionService;
|
public function __invoke(string $mode, Entry $entry, User $judge): array;
|
||||||
protected EntryService $entryService;
|
|
||||||
protected UserService $userService;
|
|
||||||
|
|
||||||
public function __construct(AuditionService $auditionService, EntryService $entryService, UserService $userService)
|
|
||||||
{
|
|
||||||
$this->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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
|
||||||
|
namespace App\Actions\Tabulation;
|
||||||
|
|
||||||
|
use App\Exceptions\TabulationException;
|
||||||
|
use App\Models\Entry;
|
||||||
|
use App\Models\ScoreSheet;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Services\AuditionService;
|
||||||
|
use App\Services\EntryService;
|
||||||
|
use App\Services\UserService;
|
||||||
|
|
||||||
|
class CalculateScoreSheetTotalDivideByTotalWeights implements CalculateScoreSheetTotal
|
||||||
|
{
|
||||||
|
protected AuditionService $auditionService;
|
||||||
|
|
||||||
|
protected EntryService $entryService;
|
||||||
|
|
||||||
|
protected UserService $userService;
|
||||||
|
|
||||||
|
public function __construct(AuditionService $auditionService, EntryService $entryService, UserService $userService)
|
||||||
|
{
|
||||||
|
$this->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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
|
||||||
|
namespace App\Actions\Tabulation;
|
||||||
|
|
||||||
|
use App\Exceptions\TabulationException;
|
||||||
|
use App\Models\Entry;
|
||||||
|
use App\Models\ScoreSheet;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Services\AuditionService;
|
||||||
|
use App\Services\EntryService;
|
||||||
|
use App\Services\UserService;
|
||||||
|
|
||||||
|
class CalculateScoreSheetTotalDivideByWeightedPossible implements CalculateScoreSheetTotal
|
||||||
|
{
|
||||||
|
protected AuditionService $auditionService;
|
||||||
|
|
||||||
|
protected EntryService $entryService;
|
||||||
|
|
||||||
|
protected UserService $userService;
|
||||||
|
|
||||||
|
public function __construct(AuditionService $auditionService, EntryService $entryService, UserService $userService)
|
||||||
|
{
|
||||||
|
$this->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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,8 @@ use App\Actions\Schools\SetHeadDirector;
|
||||||
use App\Actions\Tabulation\AllowForOlympicScoring;
|
use App\Actions\Tabulation\AllowForOlympicScoring;
|
||||||
use App\Actions\Tabulation\CalculateEntryScore;
|
use App\Actions\Tabulation\CalculateEntryScore;
|
||||||
use App\Actions\Tabulation\CalculateScoreSheetTotal;
|
use App\Actions\Tabulation\CalculateScoreSheetTotal;
|
||||||
|
use App\Actions\Tabulation\CalculateScoreSheetTotalDivideByTotalWeights;
|
||||||
|
use App\Actions\Tabulation\CalculateScoreSheetTotalDivideByWeightedPossible;
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
|
|
@ -46,7 +48,9 @@ class AppServiceProvider extends ServiceProvider
|
||||||
*/
|
*/
|
||||||
public function register(): void
|
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(CalculateEntryScore::class, AllowForOlympicScoring::class);
|
||||||
$this->app->singleton(DrawService::class, DrawService::class);
|
$this->app->singleton(DrawService::class, DrawService::class);
|
||||||
$this->app->singleton(AuditionService::class, AuditionService::class);
|
$this->app->singleton(AuditionService::class, AuditionService::class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue