@extends('layouts.master') @section('content')
{{ $docente->nombres }} {{ $docente->apellidos }} - Periodo {!! App\Models\Periodo::where('id',Session::get('periodoActivo'))->value('descripcion') !!}
{{-- Botón de export a Excel --}} Exportar Excel
{{-- Tabla de resultados --}}
@foreach($materias as $mat) @endforeach @php $promediosPorMateria = []; @endphp @foreach($preguntas as $pregId => $texto) @php $hayPromedios = isset($promedios[$pregId]) && count($promedios[$pregId]); @endphp @if($hayPromedios) {{-- Color de la celda de la pregunta según alguna modalidad que aplique --}} @php $modalidadesPregunta = collect($materias)->mapWithKeys(function($mat, $matId) use($pregId, $modalidades){ return [$matId => $modalidades[$pregId][$matId] ?? null]; }); $colorPregunta = 'bg-light'; // gris por defecto foreach($modalidadesPregunta as $mod) { if($mod === 0 || $mod === 2) { $colorPregunta = 'bg-success text-white'; break; } elseif($mod === 3) { $colorPregunta = 'bg-primary text-white'; break; } } $totalPregunta = 0; $countMaterias = 0; @endphp @foreach($materias as $matId => $mat) @php $prom = $promedios[$pregId][$matId] ?? null; $modalidadCelda = $modalidades[$pregId][$matId] ?? null; $colorCelda = 'bg-light'; // gris por defecto $valorMostrar = ''; if(!is_null($prom)) { if($modalidadCelda === 0 || $modalidadCelda === 2) { $colorCelda = 'bg-success text-white'; $valorMostrar = number_format($prom, 2); } elseif($modalidadCelda === 3) { $colorCelda = 'bg-primary text-white'; $valorMostrar = number_format($prom, 2); } // Solo sumar al promedio si modalidad aplica (0,2,3) if(in_array($modalidadCelda, [0,2,3])) { $totalPregunta += $prom; $countMaterias++; $promediosPorMateria[$matId][] = ['valor' => $prom, 'modalidad' => $modalidadCelda]; } } @endphp @endforeach @endif @endforeach {{-- Fila de promedio por materia con color según modalidad --}} @php $totalGeneral = 0; $materiasConPromedio = 0; // contaremos solo materias que tienen promedio @endphp @foreach($materias as $matId => $mat) @php $promMat = 0; $colorProm = 'bg-light'; if(isset($promediosPorMateria[$matId]) && count($promediosPorMateria[$matId])) { $valores = $promediosPorMateria[$matId]; $promMat = array_sum(array_column($valores, 'valor')) / count($valores); // Determinar color según modalidad de los valores $colorProm = 'bg-light'; foreach($valores as $v) { if($v['modalidad'] === 0 || $v['modalidad'] === 2) { $colorProm = 'bg-success text-white'; break; } elseif($v['modalidad'] === 3) { $colorProm = 'bg-primary text-white'; break; } } $totalGeneral += $promMat; $materiasConPromedio++; } @endphp @endforeach @php // Promedio general: solo dividir entre materias que tienen promedio $promGeneral = $materiasConPromedio ? $totalGeneral / $materiasConPromedio : 0; @endphp
Pregunta{{ $mat }}Promedio por Pregunta
{{ $texto }}{{ $valorMostrar }}{{ $countMaterias ? number_format($totalPregunta / $countMaterias, 2) : '' }}
Promedio por Materia{{ $promMat ? number_format($promMat, 2) : '' }}{{ $promGeneral ? number_format($promGeneral, 2) : '' }}
@endsection