Progress on seating page. Need to finish doublers

This commit is contained in:
Matt Young 2024-06-17 23:52:39 -05:00
parent 72566739b1
commit 74e2d47eae
5 changed files with 38 additions and 35 deletions

View File

@ -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'));
}

View File

@ -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);
});
}
/**

View File

@ -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');
}

View File

@ -27,11 +27,11 @@
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
</x-table.td>
<x-table.td>
@if($entry->is_doubler)
<x-doubler-block :studentID="$entry->student->id" />
@endif
{{-- @if($entry->is_doubler)--}}
{{-- <x-doubler-block :studentID="$entry->student->id" />--}}
{{-- @endif--}}
</x-table.td>
<x-table.td>{{ number_format($entry->final_score_array[0],4) }}</x-table.td>
<x-table.td>{{ number_format($entry->final_score_array[0] ?? 0,4) }}</x-table.td>
<x-table.td>@if($entry->scoring_complete) <x-icons.checkmark color="green" /> @endif</x-table.td>
</tr>
@endforeach

View File

@ -15,7 +15,7 @@
<x-layout.app>
<x-slot:page_title>Test Page</x-slot:page_title>
@php
$testedSheet = ScoreSheet::find(37);
dump($scoreservice->getScoringGuide(58)->subscores_count);
@endphp