Correctly show advancement screen.
This commit is contained in:
parent
c011d91615
commit
24e1c3d95e
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Tabulation;
|
namespace App\Http\Controllers\Tabulation;
|
||||||
|
|
||||||
|
use App\Actions\Tabulation\CalculateAuditionScores;
|
||||||
use App\Actions\Tabulation\RankAuditionEntries;
|
use App\Actions\Tabulation\RankAuditionEntries;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
|
|
@ -11,41 +12,52 @@ use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
class AdvancementController extends Controller
|
class AdvancementController extends Controller
|
||||||
{
|
{
|
||||||
protected RankAuditionEntries $ranker;
|
|
||||||
|
|
||||||
public function __construct(RankAuditionEntries $ranker)
|
|
||||||
{
|
|
||||||
$this->ranker = $ranker;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function status()
|
public function status()
|
||||||
{
|
{
|
||||||
|
// Total auditions scores if we haven't done it lately
|
||||||
|
if (! Cache::has('advancement_status_audition_totaler_throttle')) {
|
||||||
|
$lock = Cache::lock('advancement_status_audition_totaler_lock');
|
||||||
|
|
||||||
|
if ($lock->get()) {
|
||||||
|
try {
|
||||||
|
$totaler = app(CalculateAuditionScores::class);
|
||||||
|
foreach (Audition::forAdvancement()->with('judges')->get() as $audition) {
|
||||||
|
$totaler($audition);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set throttle
|
||||||
|
Cache::put('advancement_status_audition_totaler_throttle', true, 15);
|
||||||
|
} finally {
|
||||||
|
$lock->release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$auditions = Audition::forAdvancement()
|
$auditions = Audition::forAdvancement()
|
||||||
->with('flags')
|
->with('flags')
|
||||||
->withCount([
|
->withCount([
|
||||||
'entries' => function ($query) {
|
'entries' => function ($query) {
|
||||||
$query->where('for_advancement', 1);
|
$query->where('for_advancement', true);
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
->withCount([
|
->withCount([
|
||||||
'unscoredEntries' => function ($query) {
|
'unscoredEntries' => function ($query) {
|
||||||
$query->where('for_advancement', 1);
|
$query->where('for_advancement', true);
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
->orderBy('score_order')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$auditionData = [];
|
$auditionData = [];
|
||||||
$auditions->each(function ($audition) use (&$auditionData) {
|
$auditions->each(function (Audition $audition) use (&$auditionData) {
|
||||||
$scoredPercent = ($audition->entries_count > 0) ?
|
|
||||||
round((($audition->entries_count - $audition->unscored_entries_count) / $audition->entries_count) * 100)
|
|
||||||
: 100;
|
|
||||||
$auditionData[] = [
|
$auditionData[] = [
|
||||||
'id' => $audition->id,
|
'id' => $audition->id,
|
||||||
'name' => $audition->name,
|
'name' => $audition->name,
|
||||||
'entries_count' => $audition->entries_count,
|
'entries_count' => $audition->entries_count,
|
||||||
'unscored_entries_count' => $audition->unscored_entries_count,
|
'unscored_entries_count' => $audition->unscored_entries_count,
|
||||||
'scored_entries_count' => $audition->entries_count - $audition->unscored_entries_count,
|
'scored_entries_count' => $audition->entries_count - $audition->unscored_entries_count,
|
||||||
'scored_percentage' => $scoredPercent,
|
'scored_percentage' => $audition->entries_count > 0 ? ((($audition->entries_count - $audition->unscored_entries_count) / $audition->entries_count) * 100) : 0,
|
||||||
'scoring_complete' => $audition->unscored_entries_count == 0,
|
'scoring_complete' => $audition->unscored_entries_count === 0,
|
||||||
'published' => $audition->hasFlag('advancement_published'),
|
'published' => $audition->hasFlag('advancement_published'),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
@ -55,11 +67,12 @@ class AdvancementController extends Controller
|
||||||
|
|
||||||
public function ranking(Request $request, Audition $audition)
|
public function ranking(Request $request, Audition $audition)
|
||||||
{
|
{
|
||||||
$entries = $this->ranker->rank('advancement', $audition);
|
$ranker = app(RankAuditionEntries::class);
|
||||||
$entries->load('advancementVotes');
|
$entries = $ranker($audition, 'advancement');
|
||||||
|
$entries->load(['advancementVotes', 'totalScore', 'student.school']);
|
||||||
|
|
||||||
$scoringComplete = $entries->every(function ($entry) {
|
$scoringComplete = $entries->every(function ($entry) {
|
||||||
return $entry->score_totals[0] >= 0 || $entry->hasFlag('no_show');
|
return $entry->totalScore || $entry->hasFlag('no_show');
|
||||||
});
|
});
|
||||||
|
|
||||||
return view('tabulation.advancement.ranking', compact('audition', 'entries', 'scoringComplete'));
|
return view('tabulation.advancement.ranking', compact('audition', 'entries', 'scoringComplete'));
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class SeatingStatusController extends Controller
|
||||||
*/
|
*/
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
|
// Total auditions scores if we haven't done it lately
|
||||||
if (! Cache::has('seating_status_audition_totaler_throttle')) {
|
if (! Cache::has('seating_status_audition_totaler_throttle')) {
|
||||||
$lock = Cache::lock('seating_status_audition_totaler_lock');
|
$lock = Cache::lock('seating_status_audition_totaler_lock');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,22 +16,15 @@
|
||||||
|
|
||||||
<x-table.body>
|
<x-table.body>
|
||||||
@foreach($entries as $entry)
|
@foreach($entries as $entry)
|
||||||
@php
|
|
||||||
if ($entry->score_totals[0] < 0) {
|
|
||||||
$score = $entry->score_message;
|
|
||||||
} else {
|
|
||||||
$score = number_format($entry->score_totals[0] ?? 0,4);
|
|
||||||
}
|
|
||||||
@endphp
|
|
||||||
<tr>
|
<tr>
|
||||||
<x-table.td>{{ $entry->rank }}</x-table.td>
|
<x-table.td>{{ $entry->rank('advancement') }}</x-table.td>
|
||||||
<x-table.td>{{ $entry->id }}</x-table.td>
|
<x-table.td>{{ $entry->id }}</x-table.td>
|
||||||
<x-table.td>{{ $entry->draw_number }}</x-table.td>
|
<x-table.td>{{ $entry->draw_number }}</x-table.td>
|
||||||
<x-table.td class="flex flex-col">
|
<x-table.td class="flex flex-col">
|
||||||
<span>{{ $entry->student->full_name() }}</span>
|
<span>{{ $entry->student->full_name() }}</span>
|
||||||
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
|
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
|
||||||
</x-table.td>
|
</x-table.td>
|
||||||
<x-table.td>{{ $score }}</x-table.td>
|
<x-table.td>{{ $entry->totalScore->advancement_total }}</x-table.td>
|
||||||
|
|
||||||
<x-table.td class="flex space-x-1">
|
<x-table.td class="flex space-x-1">
|
||||||
@foreach($entry->advancementVotes as $vote)
|
@foreach($entry->advancementVotes as $vote)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue