Advancement tabulation #3
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Tabulation;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Audition;
|
||||
use App\Models\Entry;
|
||||
use App\Services\TabulationService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AdvancementController extends Controller
|
||||
{
|
||||
protected TabulationService $tabulationService;
|
||||
|
||||
public function __construct(TabulationService $tabulationService)
|
||||
{
|
||||
$this->tabulationService = $tabulationService;
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
$auditions = $this->tabulationService->getAuditionsWithStatus('advancement');
|
||||
|
||||
return view('tabulation.advancement.status', compact('auditions'));
|
||||
}
|
||||
|
||||
public function ranking(Request $request, Audition $audition)
|
||||
{
|
||||
$entries = $this->tabulationService->auditionEntries($audition->id, 'advancement');
|
||||
|
||||
$scoringComplete = $entries->every(function ($entry) {
|
||||
return $entry->scoring_complete;
|
||||
});
|
||||
|
||||
return view('tabulation.advancement.ranking', compact('audition', 'entries', 'scoringComplete'));
|
||||
}
|
||||
|
||||
public function setAuditionPassers(Request $request, Audition $audition)
|
||||
{
|
||||
$passingEntries = $request->input('pass');
|
||||
$passingEntries = array_keys($passingEntries);
|
||||
$audition->addFlag('advancement_published');
|
||||
$entries = Entry::whereIn('id', $passingEntries)->get();
|
||||
foreach ($entries as $entry) {
|
||||
$entry->addFlag('will_advance');
|
||||
}
|
||||
|
||||
return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success', 'Passers have been set successfully');
|
||||
}
|
||||
|
||||
public function clearAuditionPassers(Request $request, Audition $audition)
|
||||
{
|
||||
$audition->removeFlag('advancement_published');
|
||||
foreach ($audition->entries as $entry) {
|
||||
$entry->removeFlag('will_advance');
|
||||
}
|
||||
|
||||
return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success', 'Passers have been cleared successfully');
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ namespace App\Services;
|
|||
|
||||
use App\Models\Entry;
|
||||
use App\Models\Student;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class DoublerService
|
||||
|
|
@ -32,13 +33,19 @@ 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')
|
||||
// TODO needs to split by event so that a doubler may enter jazz and concert events for example
|
||||
$doublers = Cache::remember($this->doublersCacheKey, 60, function () {
|
||||
return Student::withCount(['entries' => function (Builder $query) {
|
||||
$query->where('for_seating', true);
|
||||
}])
|
||||
->with(['entries' => function (Builder $query) {
|
||||
$query->where('for_seating', true);
|
||||
}])
|
||||
->havingRaw('entries_count > ?', [1])
|
||||
->get();
|
||||
});
|
||||
|
||||
return $doublers;
|
||||
}
|
||||
|
||||
public function refreshDoublerCache()
|
||||
|
|
|
|||
|
|
@ -24,17 +24,30 @@ class EntryCacheService
|
|||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getEntriesForAudition($auditionId)
|
||||
public function getEntriesForAudition($auditionId, $mode = 'seating')
|
||||
{
|
||||
// TODO this invokes a lot of lazy loading. Perhaps cache the data for all entries then draw from that for each audition
|
||||
$cacheKey = 'audition'.$auditionId.'entries';
|
||||
|
||||
return Cache::remember($cacheKey, 3600, function () use ($auditionId) {
|
||||
$entries = Cache::remember($cacheKey, 3600, function () use ($auditionId) {
|
||||
return Entry::where('audition_id', $auditionId)
|
||||
->with('student.school')
|
||||
->get()
|
||||
->keyBy('id');
|
||||
});
|
||||
|
||||
switch ($mode) {
|
||||
case 'seating':
|
||||
return $entries->filter(function ($entry) {
|
||||
return $entry->for_seating;
|
||||
});
|
||||
case 'advancement':
|
||||
return $entries->filter(function ($entry) {
|
||||
return $entry->for_advancement;
|
||||
});
|
||||
default:
|
||||
return $entries;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class ScoreService
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function calculateScoresForAudition($auditionId)
|
||||
public function calculateScoresForAudition($auditionId, $mode= 'seating')
|
||||
{
|
||||
static $alreadyChecked = [];
|
||||
// if $auditionId is in the array $alreadyChecked return
|
||||
|
|
@ -111,7 +111,7 @@ class ScoreService
|
|||
$alreadyChecked[] = $auditionId;
|
||||
$audition = $this->auditionCache->getAudition($auditionId);
|
||||
$scoringGuideId = $audition->scoring_guide_id;
|
||||
$entries = $this->entryCache->getEntriesForAudition($auditionId);
|
||||
$entries = $this->entryCache->getEntriesForAudition($auditionId, $mode);
|
||||
$entries->load('scoreSheets'); // TODO Cache this somehow, it's expensive and repetitive on the seating page
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class TabulationService
|
|||
*
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function auditionEntries(int $auditionId)
|
||||
public function auditionEntries(int $auditionId, $mode = 'seating')
|
||||
{
|
||||
static $cache = [];
|
||||
if (isset($cache[$auditionId])) {
|
||||
|
|
@ -52,9 +52,9 @@ class TabulationService
|
|||
}
|
||||
|
||||
$audition = $this->auditionCacheService->getAudition($auditionId);
|
||||
$entries = $this->entryCacheService->getEntriesForAudition($auditionId);
|
||||
$entries = $this->entryCacheService->getEntriesForAudition($auditionId, $mode);
|
||||
$this->scoreService->calculateScoresForAudition($auditionId);
|
||||
|
||||
// TODO will need to pass a mode to the above function to only use subscores for hte appropriate mode
|
||||
foreach ($entries as $entry) {
|
||||
$entry->final_score_array = $this->scoreService->entryTotalScores($entry);
|
||||
$entry->scoring_complete = ($this->scoreService->entryScoreSheetCounts()[$entry->id] == $audition->judges_count);
|
||||
|
|
@ -69,18 +69,20 @@ class TabulationService
|
|||
|
||||
return 0;
|
||||
});
|
||||
|
||||
//TODO verify this actually sorts by subscores correctly
|
||||
|
||||
// Assign a rank to each entry. In the case of a declined seat by a doubler, indicate as so and do not increment rank
|
||||
$n = 1;
|
||||
/** @var Entry $entry */
|
||||
foreach ($entries as $entry) {
|
||||
if (! $entry->hasFlag('declined')) {
|
||||
if (! $entry->hasFlag('declined') or $mode != 'seating') {
|
||||
$entry->rank = $n;
|
||||
$n++;
|
||||
} else {
|
||||
$entry->rank = $n.' - declined';
|
||||
}
|
||||
}
|
||||
|
||||
$cache[$auditionId] = $entries->keyBy('id');
|
||||
|
||||
return $entries->keyBy('id');
|
||||
|
|
@ -117,6 +119,7 @@ class TabulationService
|
|||
case 'advancement':
|
||||
return $audition->advancement_entries_count - $audition->scored_entries_count;
|
||||
}
|
||||
|
||||
return $audition->entries_count - $audition->scored_entries_count;
|
||||
}
|
||||
|
||||
|
|
@ -132,9 +135,7 @@ class TabulationService
|
|||
return Cache::remember('auditionsWithStatus', 30, function () use ($mode) {
|
||||
|
||||
// Retrieve auditions from the cache and load entry IDs
|
||||
$auditions = $this->auditionCacheService->getAuditions();
|
||||
|
||||
|
||||
$auditions = $this->auditionCacheService->getAuditions($mode);
|
||||
// Iterate over the auditions and calculate the scored_entries_count
|
||||
foreach ($auditions as $audition) {
|
||||
$scored_entries_count = 0;
|
||||
|
|
@ -169,6 +170,7 @@ class TabulationService
|
|||
}
|
||||
|
||||
return $auditions;
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@props(['name','label','description' => '', 'checked' => false])
|
||||
@props(['name','label' => false,'description' => '', 'checked' => false])
|
||||
<div class="relative flex items-start">
|
||||
<div class="flex h-6 items-center">
|
||||
<input id="{{ $name }}"
|
||||
|
|
@ -6,11 +6,13 @@
|
|||
name="{{ $name }}"
|
||||
type="checkbox"
|
||||
@if($checked) checked @endif
|
||||
class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600">
|
||||
{{ $attributes->merge(['class' => "h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600"]) }}>
|
||||
</div>
|
||||
<div class="ml-3 text-sm leading-6">
|
||||
@if($label)
|
||||
<label for="{{ $name }}" class="font-medium text-gray-900">{{ $label }}</label>
|
||||
<p id="comments-description" class="text-gray-500">{{ $description }}</p>
|
||||
@endif
|
||||
@error($name)
|
||||
<p class="text-xs text-red-500 font-semibold mt-1 ml-3">{{ $message }}</p>
|
||||
@enderror
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@
|
|||
<div class="absolute left-1/2 z-10 mt-5 flex w-screen max-w-min -translate-x-1/2 px-4" x-show="open" x-cloak>
|
||||
<div class="w-56 shrink rounded-xl bg-white p-4 text-sm font-semibold leading-6 text-gray-900 shadow-lg ring-1 ring-gray-900/5">
|
||||
<a href="{{ route('scores.chooseEntry') }}" class="block p-2 hover:text-indigo-600">Enter Scores</a>
|
||||
<a href="/tabulation/status" class="block p-2 hover:text-indigo-600">Audition Status</a>
|
||||
<a href="{{ route('tabulation.status') }}" class="block p-2 hover:text-indigo-600">Audition Status</a>
|
||||
<a href="{{ route('advancement.status') }}" class="block p-2 hover:text-indigo-600">{{ auditionSetting('advanceTo') }} Status</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
<x-layout.app>
|
||||
<x-slot:page_title>{{ auditionSetting('advanceTo') }} Advancement - {{ $audition->name }}</x-slot:page_title>
|
||||
<x-form.form method="POST" action="{{ route('advancement.setAuditionPassers',['audition' => $audition->id]) }}">
|
||||
<div class="grid grid-cols-4" x-data="checkboxSelector()">
|
||||
<div class="col-span-3">
|
||||
@include('tabulation.advancement.results-table')
|
||||
</div>
|
||||
<div class="ml-4">
|
||||
@if( $audition->hasFlag('advancement_published') )
|
||||
@method('DELETE')
|
||||
<x-form.button type="submit" class="mt-3">Clear Advancement</x-form.button>
|
||||
@elseif($scoringComplete)
|
||||
|
||||
<x-card.card>
|
||||
<x-card.heading>Pass Entries</x-card.heading>
|
||||
<div class="mx-6 mt-3">
|
||||
<x-form.field name="markrows"
|
||||
type="number"
|
||||
label_text="Mark entries ranked 1 through"
|
||||
x-model="numberOfCheckboxes"/>
|
||||
|
||||
<div class="flex justify-between mb-3">
|
||||
<div></div>
|
||||
<x-form.button type="button" class="mt-2" @click="checkCheckboxes">Mark</x-form.button>
|
||||
</div>
|
||||
</div>
|
||||
</x-card.card>
|
||||
|
||||
<x-form.button type="submit" class="mt-3">Pass Checked Entries</x-form.button>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function checkboxSelector() {
|
||||
return {
|
||||
numberOfCheckboxes: 0,
|
||||
checkCheckboxes() {
|
||||
const checkboxes = document.querySelectorAll('.checkbox');
|
||||
checkboxes.forEach((checkbox, index) => {
|
||||
checkbox.checked = index < this.numberOfCheckboxes;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</x-form.form>
|
||||
</x-layout.app>
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<x-card.card class="px-3">
|
||||
<x-table.table>
|
||||
<thead>
|
||||
<tr>
|
||||
<x-table.th>Rank</x-table.th>
|
||||
<x-table.th>ID</x-table.th>
|
||||
<x-table.th>Draw #</x-table.th>
|
||||
<x-table.th>Student Name</x-table.th>
|
||||
<x-table.th>Total Score</x-table.th>
|
||||
<x-table.th>All Scores?</x-table.th>
|
||||
@if($scoringComplete)
|
||||
<x-table.th>Pass?</x-table.th>
|
||||
@endif
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<x-table.body>
|
||||
@foreach($entries as $entry)
|
||||
<tr>
|
||||
<x-table.td>{{ $entry->rank }}</x-table.td>
|
||||
<x-table.td>{{ $entry->id }}</x-table.td>
|
||||
<x-table.td>{{ $entry->draw_number }}</x-table.td>
|
||||
<x-table.td class="flex flex-col">
|
||||
<span>{{ $entry->student->full_name() }}</span>
|
||||
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
|
||||
</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>
|
||||
@if( $audition->hasFlag('advancement_published') )
|
||||
<x-table.td>
|
||||
@if($entry->hasFlag('will_advance'))
|
||||
<x-icons.checkmark color="green"/>
|
||||
@endif
|
||||
</x-table.td>
|
||||
@elseif($scoringComplete)
|
||||
<x-table.td>
|
||||
<x-form.checkbox name="pass[{{$entry->id}}]" x-ref="checkboxes" class="checkbox"></x-form.checkbox>
|
||||
</x-table.td>
|
||||
@endif
|
||||
|
||||
</tr>
|
||||
@endforeach
|
||||
</x-table.body>
|
||||
</x-table.table>
|
||||
</x-card.card>
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
<x-layout.app>
|
||||
<x-slot:page_title>{{ auditionSetting('advanceTo') }} Status</x-slot:page_title>
|
||||
<x-card.card class="mx-auto max-w-2xl">
|
||||
<x-card.heading>
|
||||
{{ auditionSetting('advanceTo') }} Advancement Status
|
||||
</x-card.heading>
|
||||
<x-table.table>
|
||||
<thead>
|
||||
<tr>
|
||||
<x-table.th>Audition</x-table.th>
|
||||
<x-table.th>Scoring Complete</x-table.th>
|
||||
<x-table.th>Advancement Published</x-table.th>
|
||||
</tr>
|
||||
</thead>
|
||||
<x-table.body>
|
||||
@foreach($auditions as $audition)
|
||||
@php
|
||||
$percent = 100;
|
||||
if($audition->advancement_entries_count > 0) {
|
||||
$percent = round(($audition->scored_entries_count / $audition->advancement_entries_count) * 100);
|
||||
}
|
||||
@endphp
|
||||
<tr class="hover:bg-gray-50">
|
||||
|
||||
<x-table.td class="">
|
||||
<a href="{{ route('advancement.ranking', ['audition' => $audition->id]) }}">
|
||||
<div class="flex justify-between mb-1">
|
||||
<span class="text-base font-medium text-indigo-700 dark:text-white">{{ $audition->name }}</span>
|
||||
<span class="text-sm font-medium text-indigo-700 dark:text-white">{{ $audition->scored_entries_count }} / {{ $audition->advancement_entries_count }} Scored</span>
|
||||
</div>
|
||||
<div class="w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700">
|
||||
<div class="bg-indigo-600 h-2.5 rounded-full" style="width: {{ $percent }}%"></div>
|
||||
</div>
|
||||
</a>
|
||||
</x-table.td>
|
||||
<td class="px-8">
|
||||
@if( $audition->scored_entries_count == $audition->advancement_entries_count)
|
||||
<x-icons.checkmark color="green"/>
|
||||
@endif
|
||||
</td>
|
||||
<td class="px-8">
|
||||
@if( $audition->hasFlag('advancement_published'))
|
||||
<x-icons.checkmark color="green"/>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</x-table.body>
|
||||
</x-table.table>
|
||||
</x-card.card>
|
||||
</x-layout.app>
|
||||
|
|
@ -16,12 +16,20 @@ Route::middleware(['auth', 'verified', CheckIfCanTab::class])->group(function ()
|
|||
|
||||
// Generic Tabulation Routes
|
||||
Route::prefix('tabulation/')->controller(\App\Http\Controllers\Tabulation\TabulationController::class)->group(function () {
|
||||
Route::get('/status', 'status');
|
||||
Route::get('/status', 'status')->name('tabulation.status');
|
||||
Route::match(['get', 'post'], '/auditions/{audition}', 'auditionSeating')->name('tabulation.audition.seat');
|
||||
Route::post('/auditions/{audition}/publish-seats', 'publishSeats')->name('tabulation.seat.publish');
|
||||
Route::post('/auditions/{audition}/unpublish-seats', 'unpublishSeats')->name('tabulation.seat.unpublish');
|
||||
});
|
||||
|
||||
// Advancement Routes
|
||||
Route::prefix('advancement/')->controller(\App\Http\Controllers\Tabulation\AdvancementController::class)->group(function () {
|
||||
Route::get('/status', 'status')->name('advancement.status');
|
||||
Route::get('/{audition}', 'ranking')->name('advancement.ranking');
|
||||
Route::post('/{audition}', 'setAuditionPassers')->name('advancement.setAuditionPassers');
|
||||
Route::delete('/{audition}', 'clearAuditionPassers')->name('advancement.clearAuditionPassers');
|
||||
});
|
||||
|
||||
// Doubler decision routes
|
||||
Route::prefix('doubler-decision')->controller(DoublerDecisionController::class)->group(function () {
|
||||
Route::post('{entry}/accept', 'accept')->name('doubler.accept');
|
||||
|
|
|
|||
Loading…
Reference in New Issue