Correctly show advancement screen.
This commit is contained in:
parent
c011d91615
commit
24e1c3d95e
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\Tabulation;
|
||||
|
||||
use App\Actions\Tabulation\CalculateAuditionScores;
|
||||
use App\Actions\Tabulation\RankAuditionEntries;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Audition;
|
||||
|
|
@ -11,41 +12,52 @@ use Illuminate\Support\Facades\Cache;
|
|||
|
||||
class AdvancementController extends Controller
|
||||
{
|
||||
protected RankAuditionEntries $ranker;
|
||||
|
||||
public function __construct(RankAuditionEntries $ranker)
|
||||
{
|
||||
$this->ranker = $ranker;
|
||||
}
|
||||
|
||||
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()
|
||||
->with('flags')
|
||||
->withCount([
|
||||
'entries' => function ($query) {
|
||||
$query->where('for_advancement', 1);
|
||||
$query->where('for_advancement', true);
|
||||
},
|
||||
])
|
||||
->withCount([
|
||||
'unscoredEntries' => function ($query) {
|
||||
$query->where('for_advancement', 1);
|
||||
$query->where('for_advancement', true);
|
||||
},
|
||||
])
|
||||
->orderBy('score_order')
|
||||
->get();
|
||||
|
||||
$auditionData = [];
|
||||
$auditions->each(function ($audition) use (&$auditionData) {
|
||||
$scoredPercent = ($audition->entries_count > 0) ?
|
||||
round((($audition->entries_count - $audition->unscored_entries_count) / $audition->entries_count) * 100)
|
||||
: 100;
|
||||
$auditions->each(function (Audition $audition) use (&$auditionData) {
|
||||
$auditionData[] = [
|
||||
'id' => $audition->id,
|
||||
'name' => $audition->name,
|
||||
'entries_count' => $audition->entries_count,
|
||||
'unscored_entries_count' => $audition->unscored_entries_count,
|
||||
'scored_entries_count' => $audition->entries_count - $audition->unscored_entries_count,
|
||||
'scored_percentage' => $scoredPercent,
|
||||
'scoring_complete' => $audition->unscored_entries_count == 0,
|
||||
'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,
|
||||
'published' => $audition->hasFlag('advancement_published'),
|
||||
];
|
||||
});
|
||||
|
|
@ -55,11 +67,12 @@ class AdvancementController extends Controller
|
|||
|
||||
public function ranking(Request $request, Audition $audition)
|
||||
{
|
||||
$entries = $this->ranker->rank('advancement', $audition);
|
||||
$entries->load('advancementVotes');
|
||||
$ranker = app(RankAuditionEntries::class);
|
||||
$entries = $ranker($audition, 'advancement');
|
||||
$entries->load(['advancementVotes', 'totalScore', 'student.school']);
|
||||
|
||||
$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'));
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class SeatingStatusController extends Controller
|
|||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
// Total auditions scores if we haven't done it lately
|
||||
if (! Cache::has('seating_status_audition_totaler_throttle')) {
|
||||
$lock = Cache::lock('seating_status_audition_totaler_lock');
|
||||
|
||||
|
|
|
|||
|
|
@ -16,22 +16,15 @@
|
|||
|
||||
<x-table.body>
|
||||
@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>
|
||||
<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->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>{{ $score }}</x-table.td>
|
||||
<x-table.td>{{ $entry->totalScore->advancement_total }}</x-table.td>
|
||||
|
||||
<x-table.td class="flex space-x-1">
|
||||
@foreach($entry->advancementVotes as $vote)
|
||||
|
|
|
|||
Loading…
Reference in New Issue