From deb6b8b68074cffe97456f2a7c722fe7c70beb6c Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 26 Jun 2024 09:44:49 -0500 Subject: [PATCH] Fix entry count issue to respect for_seating and for_advancement --- .../Tabulation/TabulationController.php | 12 +++++- app/Services/AuditionCacheService.php | 7 ++++ app/Services/DoublerService.php | 1 + app/Services/TabulationService.php | 40 ++++++++++++++++--- config/debugbar.php | 2 +- .../components/layout/navbar/navbar.blade.php | 3 ++ resources/views/tabulation/status.blade.php | 11 +++-- resources/views/test.blade.php | 23 +++++++++-- 8 files changed, 82 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/Tabulation/TabulationController.php b/app/Http/Controllers/Tabulation/TabulationController.php index 6a2f857..a107fb5 100644 --- a/app/Http/Controllers/Tabulation/TabulationController.php +++ b/app/Http/Controllers/Tabulation/TabulationController.php @@ -37,7 +37,7 @@ class TabulationController extends Controller public function status() { - $auditions = $this->tabulationService->getAuditionsWithStatus(); + $auditions = $this->tabulationService->getAuditionsWithStatus('seating'); return view('tabulation.status', compact('auditions')); } @@ -51,6 +51,10 @@ class TabulationController extends Controller } $entries = $this->tabulationService->auditionEntries($audition->id); + $entries = $entries->filter(function ($entry) { + return $entry->for_seating; + }); + $doublerComplete = true; foreach ($entries as $entry) { @@ -65,9 +69,13 @@ class TabulationController extends Controller return $entry->scoring_complete; }); $ensembleLimits = $this->seatingService->getLimitForAudition($audition->id); + // TODO die gracefully if no ensemble limits are set for this audition $auditionComplete = $scoringComplete && $doublerComplete; $seatableEntries = $this->seatingService->getSeatableEntries($audition->id); + $seatableEntries = $seatableEntries->filter(function ($entry) { + return $entry->for_seating; + }); return view('tabulation.auditionSeating', compact('audition', 'entries', @@ -97,6 +105,7 @@ class TabulationController extends Controller Cache::forget('resultsSeatList'); Cache::forget('publishedAuditions'); Cache::forget('audition'.$audition->id.'seats'); + // TODO move the previous Cache functions here and in unplublish to the services, need to add an event for publishing an audition as well return redirect()->route('tabulation.audition.seat', ['audition' => $audition->id]); } @@ -110,6 +119,7 @@ class TabulationController extends Controller Cache::forget('audition'.$audition->id.'seats'); $this->seatingService->forgetSeatsForAudition($audition->id); Seat::where('audition_id', $audition->id)->delete(); + return redirect()->route('tabulation.audition.seat', ['audition' => $audition->id]); } } diff --git a/app/Services/AuditionCacheService.php b/app/Services/AuditionCacheService.php index 8c96565..12968cc 100644 --- a/app/Services/AuditionCacheService.php +++ b/app/Services/AuditionCacheService.php @@ -4,6 +4,7 @@ namespace App\Services; use App\Models\Audition; use App\Models\ScoringGuide; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Session; @@ -34,6 +35,12 @@ class AuditionCacheService return Audition::with(['scoringGuide.subscores', 'judges']) ->withCount('judges') ->withCount('entries') + ->withCount(['entries as seating_entries_count' => function (Builder $query) { + $query->where('for_seating', true); + }]) + ->withCount(['entries as advancement_entries_count' => function (Builder $query) { + $query->where('for_advancement', true); + }]) ->orderBy('score_order') ->get() ->keyBy('id'); diff --git a/app/Services/DoublerService.php b/app/Services/DoublerService.php index 5fdfc05..daffd3a 100644 --- a/app/Services/DoublerService.php +++ b/app/Services/DoublerService.php @@ -32,6 +32,7 @@ class DoublerService public function getDoublers(): \Illuminate\Database\Eloquent\Collection { // TODO creating or destroying an entry should refresh the doubler cache + // TODO this currently counts total entries, only need to count seating_entries. Would be an edge case, but needs to be fixed. return Cache::remember($this->doublersCacheKey, 60, function () { return Student::withCount('entries') ->with('entries') diff --git a/app/Services/TabulationService.php b/app/Services/TabulationService.php index b856a48..7c8e3b6 100644 --- a/app/Services/TabulationService.php +++ b/app/Services/TabulationService.php @@ -78,7 +78,7 @@ class TabulationService $entry->rank = $n; $n++; } else { - $entry->rank = $n . ' - declined'; + $entry->rank = $n.' - declined'; } } $cache[$auditionId] = $entries->keyBy('id'); @@ -107,10 +107,16 @@ class TabulationService * * @return mixed */ - public function remainingEntriesForAudition($auditionId) + public function remainingEntriesForAudition($auditionId, $mode = 'seating') { - $audition = $this->getAuditionsWithStatus()[$auditionId]; + $audition = $this->getAuditionsWithStatus($mode)[$auditionId]; + switch ($mode) { + case 'seating': + return $audition->seating_entries_count - $audition->scored_entries_count; + case 'advancement': + return $audition->advancement_entries_count - $audition->scored_entries_count; + } return $audition->entries_count - $audition->scored_entries_count; } @@ -121,17 +127,39 @@ class TabulationService * * @return mixed */ - public function getAuditionsWithStatus() + public function getAuditionsWithStatus($mode = 'seating') { - return Cache::remember('auditionsWithStatus', 30, function () { + return Cache::remember('auditionsWithStatus', 30, function () use ($mode) { // Retrieve auditions from the cache and load entry IDs $auditions = $this->auditionCacheService->getAuditions(); + // Iterate over the auditions and calculate the scored_entries_count foreach ($auditions as $audition) { $scored_entries_count = 0; - foreach ($this->entryCacheService->getEntriesForAudition($audition->id) as $entry) { + $entries_to_check = $this->entryCacheService->getEntriesForAudition($audition->id); + + switch ($mode) { + case 'seating': + $entries_to_check = $entries_to_check->filter(function ($entry) { + return $entry->for_seating; + }); + $auditions = $auditions->filter(function ($audition) { + return $audition->for_seating; + }); + break; + case 'advancement': + $entries_to_check = $entries_to_check->filter(function ($entry) { + return $entry->for_advancement; + }); + $auditions = $auditions->filter(function ($audition) { + return $audition->for_advancement; + }); + break; + } + + foreach ($entries_to_check as $entry) { if ($this->scoreService->entryScoreSheetCounts()[$entry->id] - $audition->judges_count == 0) { $scored_entries_count++; } diff --git a/config/debugbar.php b/config/debugbar.php index c58b89f..5bfa169 100644 --- a/config/debugbar.php +++ b/config/debugbar.php @@ -224,7 +224,7 @@ return [ 'show_copy' => false, // Show copy button next to the query, 'slow_threshold' => false, // Only track queries that last longer than this time in ms 'memory_usage' => false, // Show queries memory usage - 'soft_limit' => 200, // After the soft limit, no parameters/backtrace are captured + 'soft_limit' => 400, // After the soft limit, no parameters/backtrace are captured 'hard_limit' => 500, // After the hard limit, queries are ignored ], 'mail' => [ diff --git a/resources/views/components/layout/navbar/navbar.blade.php b/resources/views/components/layout/navbar/navbar.blade.php index 7c6b78e..9770cb1 100644 --- a/resources/views/components/layout/navbar/navbar.blade.php +++ b/resources/views/components/layout/navbar/navbar.blade.php @@ -51,6 +51,9 @@ +
+ TEST PAGE +
- {{-- {{ $audition->scored_entries_count }} / {{ $audition->entries_count }} Scored--}}
{{ $audition->name }} - {{ $audition->scored_entries_count }} / {{ $audition->entries_count }} Scored + {{ $audition->scored_entries_count }} / {{ $audition->seating_entries_count }} Scored
@@ -35,7 +34,7 @@
- @if( $audition->scored_entries_count == $audition->entries_count) + @if( $audition->scored_entries_count == $audition->seating_entries_count) @endif diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php index 44d7e44..59a1db0 100644 --- a/resources/views/test.blade.php +++ b/resources/views/test.blade.php @@ -18,10 +18,27 @@ @php dump($auditionService->getAuditions()); @endphp + + + + Name + Total Entries + Seating Entries + Advancement Entries + + + + @foreach($auditionService->getAuditions() as $a) + + {{ $a->name }} + {{ $a->entries_count }} + {{ $a->seating_entries_count }} + {{ $a->advancement_entries_count }} + + @endforeach + + - @foreach($auditionService->getAuditions() as $a) - {{ $a->name }}
- @endforeach