diff --git a/app/Http/Controllers/Tabulation/TabulationController.php b/app/Http/Controllers/Tabulation/TabulationController.php
index 89ae6eb..0c6fbf7 100644
--- a/app/Http/Controllers/Tabulation/TabulationController.php
+++ b/app/Http/Controllers/Tabulation/TabulationController.php
@@ -36,9 +36,7 @@ class TabulationController extends Controller
public function auditionSeating(Audition $audition)
{
$entries = $this->tabulationService->auditionEntries($audition->id);
- foreach ($entries as $entry) {
- $entry->is_doubler = $this->doublerService->entryIsDoubler($entry);
- }
+
return view('tabulation.auditionSeating',compact('audition','entries'));
}
diff --git a/app/Services/ScoreService.php b/app/Services/ScoreService.php
index 2004fec..4cc71b7 100644
--- a/app/Services/ScoreService.php
+++ b/app/Services/ScoreService.php
@@ -30,7 +30,7 @@ class ScoreService
public function getScoringGuides(): \Illuminate\Database\Eloquent\Collection
{
$cacheKey = 'scoringGuides';
- return Cache::remember($cacheKey, 3600, fn() => ScoringGuide::with('subscores')->get());
+ return Cache::remember($cacheKey, 3600, fn() => ScoringGuide::with('subscores')->withCount('subscores')->get());
}
/**
@@ -40,7 +40,7 @@ class ScoreService
*/
public function getScoringGuide($id): ScoringGuide
{
- return $this->getScoringGuides()->firstWhere('id', $id);
+ return $this->getScoringGuides()->find($id);
}
/**
@@ -85,7 +85,9 @@ class ScoreService
public function entryTotalScores(Entry $entry)
{
$cacheKey = 'entry' . $entry->id . 'totalScores';
- return Cache::remember($cacheKey, 3600, fn() => $this->calculateFinalScoreArray($entry->audition->scoring_guide_id, $entry->scoreSheets));
+ return Cache::remember($cacheKey, 3600, function () use ($entry) {
+ return $this->calculateFinalScoreArray($entry->audition->scoring_guide_id, $entry->scoreSheets);
+ });
}
/**
diff --git a/app/Services/TabulationService.php b/app/Services/TabulationService.php
index 266e1fc..fed5744 100644
--- a/app/Services/TabulationService.php
+++ b/app/Services/TabulationService.php
@@ -2,7 +2,6 @@
namespace App\Services;
-
use App\Models\Entry;
use App\Models\ScoreSheet;
use App\Models\User;
@@ -35,33 +34,37 @@ class TabulationService
public function auditionEntries(Int $auditionId)
{
- $cache_key = 'audition'.$auditionId.'entries';
+ static $cache = [];
+ if(isset($cache[$auditionId])) {
+ return $cache[$auditionId];
+ }
+
$audition = $this->auditionCacheService->getAudition($auditionId);
+ $entries = $this->entryCacheService->getEntriesForAudition($auditionId);
+ $this->scoreService->calculateScoresForAudition($auditionId);
- return Cache::remember($cache_key, 5, function () use ($audition) {
- $entries = Entry::where('audition_id',$audition->id)->with(['student.school','scoreSheets'])->withCount('scoreSheets')->get();
-
-
- foreach ($entries as $entry) {
-// $entry->final_score_array = $this->entryFinalScores($entry);
- $entry->final_score_array = $this->scoreService->entryTotalScores($entry);
- $entry->scoring_complete = ($entry->score_sheets_count == $audition->judges_count) ? true:false;
+ foreach ($entries as $entry) {
+ $entry->final_score_array = $this->scoreService->entryTotalScores($entry);
+ $entry->scoring_complete = $this->scoreService->entryScoreSheetCounts()[$entry->id] ?? 0 == $audition->judges_count;
+ }
+ // Sort the array $entries by the first element in the final_score_array on each entry, then by the second element in that array continuing through each element in the final_score_array for each entry
+ $entries = $entries->sort(function ($a, $b) {
+ for ($i = 0; $i < count($a->final_score_array); $i++) {
+ if ($a->final_score_array[$i] != $b->final_score_array[$i]) {
+ return $b->final_score_array[$i] > $a->final_score_array[$i] ? 1 : -1;
+ }
}
-
- // Sort based on final_score_array
- for ($n=0; $n <= $audition->judges_count; $n++) {
- $entries = $entries->sortByDesc(function ($entry) use ($n) {
- return $entry['final_score_array'][$n];
- });
- }
- //TODO verify this actually sorts by subscores correctly
- $n = 1;
- foreach ($entries as $entry) {
- $entry->rank = $n;
- $n++;
- }
- return $entries->keyBy('id');
+ return 0;
});
+
+ //TODO verify this actually sorts by subscores correctly
+ $n = 1;
+ foreach ($entries as $entry) {
+ $entry->rank = $n;
+ $n++;
+ }
+ $cache[$auditionId] = $entries->keyBy('id');
+ return $entries->keyBy('id');
}
diff --git a/resources/views/tabulation/auditionSeating.blade.php b/resources/views/tabulation/auditionSeating.blade.php
index 065b1f9..80204bf 100644
--- a/resources/views/tabulation/auditionSeating.blade.php
+++ b/resources/views/tabulation/auditionSeating.blade.php
@@ -27,11 +27,11 @@
{{ $entry->student->school->name }}
- @if($entry->is_doubler)
-
- @endif
+{{-- @if($entry->is_doubler)--}}
+{{-- --}}
+{{-- @endif--}}
- {{ number_format($entry->final_score_array[0],4) }}
+ {{ number_format($entry->final_score_array[0] ?? 0,4) }}
@if($entry->scoring_complete) @endif
@endforeach
diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php
index a285732..ff1a39b 100644
--- a/resources/views/test.blade.php
+++ b/resources/views/test.blade.php
@@ -15,7 +15,7 @@
Test Page
@php
- $testedSheet = ScoreSheet::find(37);
+ dump($scoreservice->getScoringGuide(58)->subscores_count);
@endphp