add rank
This commit is contained in:
parent
d6390cbb59
commit
054e5ac501
|
@ -1,80 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Models\Alternatif;
|
|
||||||
use App\Models\Kriteria;
|
|
||||||
use App\Models\Penilaian;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class HasilPerhitunganController extends Controller
|
|
||||||
{
|
|
||||||
function index()
|
|
||||||
{
|
|
||||||
$alternatif = Alternatif::with('penilaian.kriteria')->orderBy('kode_alternatif', 'ASC')->get();
|
|
||||||
$kriteria = Kriteria::get();
|
|
||||||
$penilaian = Penilaian::with('subKriteria')->get();
|
|
||||||
// return response()->json($alternatif);
|
|
||||||
|
|
||||||
// mencari min max
|
|
||||||
foreach ($kriteria as $key => $vkriteria) {
|
|
||||||
foreach ($penilaian as $key_1 => $vpenilaian) {
|
|
||||||
if ($vkriteria->id == $vpenilaian->id_kriteria) {
|
|
||||||
if ($vkriteria->sifat == "benefit") {
|
|
||||||
$minMax[$vkriteria->id][] = $vpenilaian->subKriteria['bobot'];
|
|
||||||
} elseif ($vkriteria->sifat == "cost") {
|
|
||||||
$minMax[$vkriteria->id][] = $vpenilaian->subKriteria['bobot'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// normalisasi
|
|
||||||
foreach ($penilaian as $key_1 => $vpenilaian) {
|
|
||||||
foreach ($kriteria as $key => $vkriteria) {
|
|
||||||
if ($vkriteria->id == $vpenilaian->id_kriteria) {
|
|
||||||
if ($vkriteria->sifat == "benefit") { //nilai sub_kriteria : nilai maksimal
|
|
||||||
$normalisasi[$vpenilaian->alternatif->guru['id']][$vkriteria->id] = $vpenilaian->subKriteria['bobot'] / max($minMax[$vkriteria->id]);
|
|
||||||
} elseif ($vkriteria->sifat == "cost") { //nilai minimal : nilai sub_kriteria
|
|
||||||
$normalisasi[$vpenilaian->alternatif->guru['id']][$vkriteria->id] = min($minMax[$vkriteria->id]) / $vpenilaian->subKriteria['bobot'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// perangkingan
|
|
||||||
foreach ($normalisasi as $key => $vnormalisasi) {
|
|
||||||
foreach ($kriteria as $key_1 => $vkriteria) { // hasil normalisasi x bobot_kriteria
|
|
||||||
// Check if the key exists in the $vnormalisasi array
|
|
||||||
if (isset($vnormalisasi[$vkriteria->id])) {
|
|
||||||
$rank[$key][] = $vnormalisasi[$vkriteria->id] * $vkriteria->bobot_kriteria;
|
|
||||||
} else {
|
|
||||||
// Handle the case when the key is not found (you can skip it or handle it accordingly)
|
|
||||||
// For example, you might want to assign a default value or log a message.
|
|
||||||
$rank[$key][] = 0; // Assign a default value
|
|
||||||
// or
|
|
||||||
// log_message('error', 'Key not found: ' . $vkriteria->id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($normalisasi as $key => $value) { //total hasil perangkingan
|
|
||||||
$rank[$key][] = array_sum($rank[$key]);
|
|
||||||
// Tambahkan logika untuk menentukan status keterangan
|
|
||||||
if ($rank[$key] >= 100) {
|
|
||||||
$statusKeterangan[$key] = 'Sangat Baik';
|
|
||||||
} elseif ($rank[$key] >= 70 && $rank[$key] < 100) {
|
|
||||||
$statusKeterangan[$key] = 'Baik';
|
|
||||||
} elseif ($rank[$key] >= 20 && $rank[$key] < 70) {
|
|
||||||
$statusKeterangan[$key] = 'Cukup';
|
|
||||||
} else {
|
|
||||||
$statusKeterangan[$key] = 'Kurang';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arsort($rank); //sortir $rank
|
|
||||||
|
|
||||||
// dd($rank);
|
|
||||||
return view('pages.hasil_perhitungan.index', compact(['kriteria', 'alternatif', 'penilaian', 'minMax', 'normalisasi', 'rank']));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Alternatif;
|
use App\Models\Alternatif;
|
||||||
|
@ -85,11 +86,17 @@ class HasilPerhitunganController extends Controller
|
||||||
$statusKeterangan[$key] = 'Kurang';
|
$statusKeterangan[$key] = 'Kurang';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Membuat koleksi Laravel dari array
|
||||||
|
$collection = collect($rank);
|
||||||
|
|
||||||
// Sort the ranks
|
// Mengurutkan koleksi berdasarkan nilai di dalam array ke-14 (descending)
|
||||||
arsort($rank);
|
$sortedDescending = $collection->sortByDesc(function ($item) {
|
||||||
|
return $item[14];
|
||||||
|
});
|
||||||
|
|
||||||
// Pass data to the view
|
// Mengubah kembali ke bentuk array
|
||||||
|
$rank = $sortedDescending->toArray();
|
||||||
|
// dd($sortedArray);
|
||||||
return view('pages.hasil_perhitungan.index', compact('kriteria', 'alternatif', 'penilaian', 'minMax', 'normalisasi', 'rank'));
|
return view('pages.hasil_perhitungan.index', compact('kriteria', 'alternatif', 'penilaian', 'minMax', 'normalisasi', 'rank'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="2%">No</th>
|
<th width="2%">No</th>
|
||||||
<th width="18%">Nama Guru</th>
|
<th width="20%">Nama Guru</th>
|
||||||
<th width="8%">Jenis Kelamin</th>
|
<th width="8%">Jenis Kelamin</th>
|
||||||
<th width="10%">NIPA</th>
|
<th width="10%">NIPA</th>
|
||||||
<th width="10%">TTL</th>
|
<th width="10%">TTL</th>
|
||||||
|
|
|
@ -9,10 +9,14 @@
|
||||||
<table class="table table-striped text-center" id="tabel" width="100%">
|
<table class="table table-striped text-center" id="tabel" width="100%">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="text-left">Rank</th>
|
<th width="2%">Peringkat</th>
|
||||||
<th width="18%">Nama Guru</th>
|
<th width="20%">Nama Guru</th>
|
||||||
<th width="8%">Jenis Kelamin</th>
|
<th width="8%">Jenis Kelamin</th>
|
||||||
<th width="10%">NIPA</th>
|
<th width="10%">NIPA</th>
|
||||||
|
<th width="5%">Jenis Guru</th>
|
||||||
|
<th width="5%">Tugas Guru</th>
|
||||||
|
<th width="12%">Alamat</th>
|
||||||
|
<th width="10%">Telepon</th>
|
||||||
<th class="text-left">Nilai</th>
|
<th class="text-left">Nilai</th>
|
||||||
<th class="text-left">Status Keterangan</th>
|
<th class="text-left">Status Keterangan</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -28,6 +32,10 @@
|
||||||
<td class="text-left">{{$guru->nama_guru}}</td>
|
<td class="text-left">{{$guru->nama_guru}}</td>
|
||||||
<td class="text-left">{{$guru->gender}}</td>
|
<td class="text-left">{{$guru->gender}}</td>
|
||||||
<td class="text-left">{{$guru->nipa}}</td>
|
<td class="text-left">{{$guru->nipa}}</td>
|
||||||
|
<td class="text-left">{{$guru->jns_guru}}</td>
|
||||||
|
<td class="text-left">{{$guru->tugas}}</td>
|
||||||
|
<td class="text-left">{{$guru->jalan}}</td>
|
||||||
|
<td class="text-left">{{$guru->nohp}}</td>
|
||||||
@foreach ($value as $key_1 => $value_1)
|
@foreach ($value as $key_1 => $value_1)
|
||||||
@if ($loop->last)
|
@if ($loop->last)
|
||||||
<td class="text-left">{{ number_format($value_1, 2) }}</td>
|
<td class="text-left">{{ number_format($value_1, 2) }}</td>
|
||||||
|
|
|
@ -107,7 +107,6 @@
|
||||||
<th class="text-center">{{ $item->kode_kriteria }}</th>
|
<th class="text-center">{{ $item->kode_kriteria }}</th>
|
||||||
@endforeach
|
@endforeach
|
||||||
<th rowspan="2" style="vertical-align: middle">Total</th>
|
<th rowspan="2" style="vertical-align: middle">Total</th>
|
||||||
<th rowspan="2" style="vertical-align: middle">Ranking</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Bobot</th>
|
<th>Bobot</th>
|
||||||
|
|
Loading…
Reference in New Issue