@extends('adminlte::page') @section('title', 'Class Results') @section('content_header')

Class Results

@stop @section('content')
{{-- ================= Filter Form ================= --}}
{{-- ================= Export Buttons ================= --}} @if(!empty($studentsData)) @endif {{-- ================= Summary Boxes ================= --}} @php $totalStudents = count($studentsData); $averageGPA = $totalStudents ? number_format(collect($studentsData)->avg('gpa'), 2) : 'N/A'; $highestPoints = $totalStudents ? max(collect($studentsData)->pluck('total_points')->toArray()) : 0; $lowestPoints = $totalStudents ? min(collect($studentsData)->pluck('total_points')->toArray()) : 0; $divisionCounts = collect($studentsData)->groupBy('division')->map->count(); // Subject averages $subjectAverages = []; if ($totalStudents) { $allSubjects = collect($studentsData)->flatMap(fn($s) => $s['subjectsData']); $subjectAverages = $allSubjects->groupBy('name')->map(fn($group) => [ 'average_mark' => number_format($group->avg('mark'), 2), 'average_gpa' => number_format($group->avg('point') / 4, 2), 'type' => $group->first()['type'] ?? '—' ])->sortKeys(); $bestSubject = $subjectAverages->sortByDesc('average_mark')->keys()->first(); $worstSubject = $subjectAverages->sortBy('average_mark')->keys()->first(); } @endphp

{{ $totalStudents }}

Total Students

{{ $averageGPA }}

Average GPA

{{ $highestPoints }}

Highest Total Points

{{ $lowestPoints }}

Lowest Total Points

Divisions

I: {{ $divisionCounts['I'] ?? 0 }} | II: {{ $divisionCounts['II'] ?? 0 }} | III: {{ $divisionCounts['III'] ?? 0 }} | IV: {{ $divisionCounts['IV'] ?? 0 }} | 0: {{ $divisionCounts['0'] ?? 0 }}

{{-- ================= Student Results Table ================= --}} @if(!empty($studentsData)) @php $allSubjects = collect($studentsData) ->flatMap(fn($s) => $s['subjectsData']) ->unique('name') ->values(); $sortedSubjects = $allSubjects->sortBy([ fn($s) => $s['type'] !== 'core', fn($s) => $s['name'] ])->values(); $gradeColors = [ 'A' => '#d4edda', 'B' => '#d1ecf1', 'C' => '#fff3cd', 'D' => '#ffe5b4', 'F' => '#f8d7da', ]; @endphp
@foreach($sortedSubjects as $subject) @endforeach @foreach(collect($studentsData)->sortBy(fn($d) => $d['student']->first_name . ' ' . $d['student']->last_name)->values() as $i => $data) @php $studentSubjects = collect($data['subjectsData'])->keyBy('name'); @endphp @foreach($sortedSubjects as $subject) @php $subjectData = $studentSubjects->get($subject['name']); $grade = $subjectData['grade'] ?? '—'; $mark = $subjectData['mark'] ?? '—'; $bg = $gradeColors[$grade] ?? '#f9f9f9'; @endphp @endforeach @php $coreSubjects = collect($data['subjectsData'])->where('type', 'core')->sortByDesc('mark'); $electives = collect($data['subjectsData'])->where('type', 'elective')->sortByDesc('mark'); $bestSubjects = $coreSubjects->take(7); if ($bestSubjects->count() < 7) { $bestSubjects = $bestSubjects->merge($electives->take(7 - $bestSubjects->count())); } $totalMarks = $bestSubjects->sum('mark'); $subjectCount = $bestSubjects->count(); $average = $subjectCount ? number_format($totalMarks / $subjectCount, 2) : 0; $totalPoints = $bestSubjects->sum('point'); @endphp @endforeach
# Student{{ $subject['name'] }}Total Marks (Best 7) Average (Best 7) Division Total Points GPA Position
{{ $i + 1 }} {{ $data['student']->first_name }} {{ $data['student']->last_name }}
{{ $mark }} ({{ $grade }})
{{ $totalMarks }} {{ $average }} {{ $data['division'] }} {{ $totalPoints }} {{ number_format($data['gpa'], 2) }} {{ $data['position'] }}/{{ $totalStudents }}
{{-- ================= Subject Performance Summary Table ================= --}}
Subject Performance Summary
@foreach($subjectAverages as $subject => $stats) @endforeach
Subject Type Average Mark Average GPA
{{ $subject }} {{ ucfirst($stats['type']) }} {{ $stats['average_mark'] }} {{ $stats['average_gpa'] }}
@else

No results found. Please select filters above.

@endif
@stop