add kriteria

This commit is contained in:
yulianadewi18 2024-02-03 11:07:06 +08:00
parent 79287e1813
commit 08662080df
4 changed files with 216 additions and 191 deletions

View File

@ -9,8 +9,9 @@ use App\Models\Penilaian;
class PerhitunganController extends Controller
{
function index() {
$alternatif = Alternatif::with('penilaian.kriteria')->orderBy('kode_alternatif','ASC')->get();
function index()
{
$alternatif = Alternatif::with('penilaian.kriteria')->orderBy('kode_alternatif', 'ASC')->get();
$kriteria = Kriteria::get();
$penilaian = Penilaian::with('subKriteria')->get();
// return response()->json($alternatif);
@ -21,7 +22,7 @@ class PerhitunganController extends Controller
if ($vkriteria->id == $vpenilaian->id_kriteria) {
if ($vkriteria->sifat == "benefit") {
$minMax[$vkriteria->id][] = $vpenilaian->subKriteria['bobot'];
}elseif ($vkriteria->sifat == "cost") {
} elseif ($vkriteria->sifat == "cost") {
$minMax[$vkriteria->id][] = $vpenilaian->subKriteria['bobot'];
}
}
@ -34,7 +35,7 @@ class PerhitunganController extends Controller
if ($vkriteria->id == $vpenilaian->id_kriteria) {
if ($vkriteria->sifat == "benefit") { //nilai sub_kriteria : nilai maksimal
$normalisasi[$vpenilaian->alternatif->guru['nama_guru']][$vkriteria->id] = $vpenilaian->subKriteria['bobot'] / max($minMax[$vkriteria->id]);
}elseif ($vkriteria->sifat == "cost") { //nilai minimal : nilai sub_kriteria
} elseif ($vkriteria->sifat == "cost") { //nilai minimal : nilai sub_kriteria
$normalisasi[$vpenilaian->alternatif->guru['nama_guru']][$vkriteria->id] = min($minMax[$vkriteria->id]) / $vpenilaian->subKriteria['bobot'];
}
}
@ -43,16 +44,26 @@ class PerhitunganController extends Controller
// perangkingan
foreach ($normalisasi as $key => $vnormalisasi) {
foreach ($kriteria as $key_1 => $vkriteria) { //hasil normalisasi x bobot_kriteria
$rank[$key][] = $vnormalisasi[$vkriteria->id] * $vkriteria->bobot_kriteria;
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
foreach ($normalisasi as $key => $value) { //total hasil perangkingan
$rank[$key][] = array_sum($rank[$key]);
}
asort($rank); //sortir $rank
// asort($rank); //sortir $rank
// dd($minMax);
return view('pages.proses_penilaian.index', compact(['kriteria','alternatif','penilaian','minMax','normalisasi','rank']));
return view('pages.proses_penilaian.index', compact(['kriteria', 'alternatif', 'penilaian', 'minMax', 'normalisasi', 'rank']));
}
}

View File

@ -42,7 +42,10 @@
<div class="col-lg-12">
<div class="form-group">
<label for="">Sifat Kriteria</label>
<input type="text" class="form-control" name="sifat" @if(!empty($kriteria)) value="{{ $kriteria->sifat }}" @else value="{{ Session::get('sifat') }}" @endif>
<select class="form-control dataGuru" name="sifat">
<option value="benefit" @if (!empty($kriteria)) {{ ($kriteria->sifat == 'benefit') ? 'selected' : '' }} @endif>Benefit</option>
<option value="cost" @if (!empty($kriteria)) {{ ($kriteria->sifat == 'cost') ? 'selected' : '' }} @endif>Cost</option>
</select>
</div>
</div>
<div class="col-lg-12">

View File

@ -3,67 +3,67 @@
@section('title', 'Tambah Klasifikasi')
@section('content')
<div class="card border-top-primary shadow mb-4">
<form action="{{ url('penilaian-alternatif/store') }}" method="POST">
@csrf
<div class="card-body pt-3">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="">Periode</label>
<input type="text" class="form-control" name="periode">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="">Alternatif</label>
<select name="id_alternatif" class="form-control">
<option value="">Pilih</option>
@foreach ($alternatif as $alt)
<option value="{{ $alt->id }}">{{ $alt->guru['nama_guru'] }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-lg-8">
<label for=""><b>Penilaian Kriteria</b></label>
<hr style="border: 1px solid; margin-top:0px">
<table width="100%">
<tr>
<td><b>Kriteria</b></td>
<td width="30%"><b>Sub Kriteria</b></td>
</tr>
@foreach ($kriteria as $item)
<tr>
<td scope="row">
<input type="hidden" value="{{ $item->id }}" name="id_kriteria[]">
{{ $loop->iteration }}. {{ $item->nama_kriteria }}
</td>
<td>
<select name="id_sub[]" class="form-control mb-2">
<option value="">Pilih</option>
@foreach ($subKriteria as $sub)
<option value="{{ $sub->id }}">{{ $sub->sub_kriteria }}</option>
@endforeach
</select>
</td>
</tr>
@endforeach
</table>
</div>
<div class="col-lg-4">
<label for="" class="mt-3"><b>Keterangan Nilai</b></label>
<p class="mb-0">*Bobot pada setiap Sub Kriteria</p>
@foreach ($subKriteria as $subs)
<label for="" class="ml-4 mb-0">{{ $subs->bobot }} = {{ $subs->sub_kriteria }}</label><br>
@endforeach
<div class="card border-top-primary shadow mb-4">
<form action="{{ url('penilaian-alternatif/store') }}" method="POST">
@csrf
<div class="card-body pt-3">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="">Periode</label>
<input type="text" class="form-control" name="periode">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="">Alternatif</label>
<select name="id_alternatif" class="form-control">
<option value="">Pilih</option>
@foreach ($alternatif as $alt)
<option value="{{ $alt->id }}">{{ $alt->guru['nama_guru'] }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-lg-8">
<label for=""><b>Penilaian Kriteria</b></label>
<hr style="border: 1px solid; margin-top:0px">
<table width="100%">
<tr>
<td><b>Kriteria</b></td>
<td width="30%"><b>Sub Kriteria</b></td>
</tr>
@foreach ($kriteria as $item)
<tr>
<td scope="row">
<input type="hidden" value="{{ $item->id }}" name="id_kriteria[]">
{{ $loop->iteration }}. {{ $item->nama_kriteria }}
</td>
<td>
<select name="id_sub[]" class="form-control mb-2">
<option value="">Pilih</option>
@foreach ($subKriteria as $sub)
<option value="{{ $sub->id }}">{{ $sub->sub_kriteria }}</option>
@endforeach
</select>
</td>
</tr>
@endforeach
</table>
</div>
<div class="col-lg-4">
<label for="" class="mt-3"><b>Keterangan Nilai</b></label>
<p class="mb-0">*Bobot pada setiap Sub Kriteria</p>
@foreach ($subKriteria as $subs)
<label for="" class="ml-4 mb-0">{{ $subs->bobot }} = {{ $subs->sub_kriteria }}</label><br>
@endforeach
</div>
</div>
<div class="card-footer" style="display: flex; justify-content: space-between!important;">
<button class="btn btn-sm btn-warning">Kembali</button>
<button class="btn btn-sm btn-primary">Simpan</button>
</div>
</form>
</div>
</div>
<div class="card-footer" style="display: flex; justify-content: space-between!important;">
<button class="btn btn-sm btn-warning">Kembali</button>
<button class="btn btn-sm btn-primary">Simpan</button>
</div>
</form>
</div>
@endsection

View File

@ -6,133 +6,144 @@
@endpush
@section('content')
<div class="card border-top-primary shadow mb-4">
<div class="card-body pt-3">
<h4 class="text-gray-900">1. Data Masing Masing Guru Terhadap Kriteria</h4>
<div class="table-responsive">
<table class="table table-striped table-sm" width="100%">
<thead>
<tr>
<th class="text-center" rowspan="2" style="vertical-align: middle">Kode (Ai)</th>
<th class="text-center" rowspan="2" style="vertical-align: middle">Keterangan</th>
<th class="text-center" colspan="{{ count($kriteria) }}">Kode Kriteria</th>
</tr>
<tr>
@foreach ($kriteria as $item)
<th class="text-center">{{ $item->kode_kriteria }}</th>
@endforeach
</tr>
</thead>
{{-- <tbody>
<div class="card border-top-primary shadow mb-4">
<div class="card-body pt-3">
<h4 class="text-gray-900">1. Data Masing Masing Guru Terhadap Kriteria</h4>
<div class="table-responsive">
<table class="table table-striped table-sm" width="100%">
<thead>
<tr>
<th class="text-center" rowspan="2" style="vertical-align: middle">Kode (Ai)</th>
<th class="text-center" rowspan="2" style="vertical-align: middle">Keterangan</th>
<th class="text-center" colspan="{{ count($kriteria) }}">Kode Kriteria</th>
</tr>
<tr>
@foreach ($kriteria as $item)
<th class="text-center">{{ $item->kode_kriteria }}</th>
@endforeach
</tr>
</thead>
{{-- <tbody>
@foreach ($alternatif as $alt)
<tr>
<td class="text-center">{{ $alt->kode_alternatif }}</td>
<td>{{ $alt->guru['nama_guru'] }}</td>
@foreach ($alt->penilaian as $nilai)
<td class="text-center">{{ $nilai->id_sub }}</td>
<?php
$minMaxKriteria[$nilai->kriteria->kode_kriteria]['min'] > $nilai->id_sub && $minMaxKriteria[$nilai->kriteria->kode_kriteria]['min'] = $nilai->id_sub;
$minMaxKriteria[$nilai->kriteria->kode_kriteria]['max'] < $nilai->id_sub && $minMaxKriteria[$nilai->kriteria->kode_kriteria]['max'] = $nilai->id_sub
?>
@endforeach
</tr>
@endforeach
<td>{{ $alt->guru['nama_guru'] }}</td>
@foreach ($alt->penilaian as $nilai)
<td class="text-center">{{ $nilai->id_sub }}</td>
<?php
$minMaxKriteria[$nilai->kriteria->kode_kriteria]['min'] > $nilai->id_sub && $minMaxKriteria[$nilai->kriteria->kode_kriteria]['min'] = $nilai->id_sub;
$minMaxKriteria[$nilai->kriteria->kode_kriteria]['max'] < $nilai->id_sub && $minMaxKriteria[$nilai->kriteria->kode_kriteria]['max'] = $nilai->id_sub
?>
@endforeach
</tr>
@endforeach
</tbody> --}}
<tbody>
@forelse ($alternatif as $alt => $valt)
<tr>
<td class="text-center">{{ $valt->kode_alternatif }}</td>
<td>{{ $valt->guru['nama_guru'] }}</td>
@foreach ($valt->penilaian as $nilai)
<td class="text-center">{{ $nilai->subKriteria['bobot'] }}</td>
@endforeach
</tr>
@empty
<tr>
<td class="text-center" colspan="{{ count($kriteria) +2 }}">Data Kosong</td>
</tr>
@endforelse
</tbody>
<tfoot>
<tr class="text-center">
<th colspan="2">Nilai Maks</th>
@foreach ($kriteria as $key => $vkriteria)
<th class="bg-secondary text-white">{{ max($minMax[$vkriteria->id]) }}</th>
@endforeach
</tr>
<tr class="text-center">
<th colspan="2">Nilai Min</th>
@foreach ($kriteria as $key => $vkriteria)
<th class="bg-secondary text-white">{{ min($minMax[$vkriteria->id]) }}</th>
@endforeach
</tr>
</tfoot>
</table>
</div>
<h4 class="text-gray-900 mt-4">2. Menghitung Nilai Normalisasi</h4>
<div class="table-responsive">
<table class="table table-striped" width="100%">
<thead>
<tr>
<th class="text-center" rowspan="2" style="vertical-align: middle;">Alternatif</th>
<th class="text-center" colspan="{{ count($kriteria) }}">Kode Kriteria</th>
</tr>
<tr>
@foreach ($kriteria as $item)
<th class="text-center">{{ $item->kode_kriteria }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach ($normalisasi as $key => $value)
<tr>
<td width="20%">{{ $key }}</td>
@foreach ($value as $key_1 => $value_1)
<td class="text-center">{{ number_format($value_1 ,2) }}</td>
@endforeach
</tr>
</tbody> --}}
<tbody>
@forelse ($alternatif as $alt => $valt)
@if(count($valt->penilaian) > 0)
<tr>
<td class="text-center">{{ $valt->kode_alternatif }}</td>
<td>{{ $valt->guru['nama_guru'] }}</td>
@foreach ($valt->penilaian as $nilai)
<td class="text-center">{{ $nilai->subKriteria['bobot'] }}</td>
@endforeach
</tbody>
</table>
</div>
<h4 class="text-gray-900 mt-4">3. Perankingan</h4>
<div class="table-responsive">
<table class="table table-striped text-center" width="100%">
<thead>
<tr>
<th>Kode Kriteria</th>
@foreach ($kriteria as $item)
<th class="text-center">{{ $item->kode_kriteria }}</th>
@endforeach
<th rowspan="2" style="vertical-align: middle">Total</th>
<th rowspan="2" style="vertical-align: middle">Rank</th>
</tr>
<tr>
<th>Bobot</th>
@foreach ($kriteria as $item)
<th class="text-center">{{ $item->bobot_kriteria }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach ($rank as $key => $value)
<tr>
<td width="20%">{{ $key }}</td>
@foreach ($value as $key_1 => $value_1)
<td class="text-center">{{ number_format($value_1 ,2) }}</td>
@endforeach
<td>{{ $loop->iteration }}</td>
</tr>
</tr>
@endif
@empty
<tr>
<td class="text-center" colspan="{{ count($kriteria) + 2 }}">Data Kosong</td>
</tr>
@endforelse
</tbody>
<tfoot>
<tr class="text-center">
<th colspan="2">Nilai Maks</th>
@foreach ($kriteria as $key => $vkriteria)
@if (isset($minMax[$vkriteria->id]) && is_array($minMax[$vkriteria->id]))
<th class="bg-secondary text-white">{{ max($minMax[$vkriteria->id]) }}</th>
@else
<th class="bg-secondary text-white">0</th> {{-- Or any default value --}}
@endif
@endforeach
</tbody>
</table>
</div>
</tr>
<tr class="text-center">
<th colspan="2">Nilai Min</th>
@foreach ($kriteria as $key => $vkriteria)
@if (isset($minMax[$vkriteria->id]) && is_array($minMax[$vkriteria->id]))
<th class="bg-secondary text-white">{{ min($minMax[$vkriteria->id]) }}</th>
@else
<th class="bg-secondary text-white">0</th> {{-- Or any default value --}}
@endif
@endforeach
</tr>
</tfoot>
</table>
</div>
<h4 class="text-gray-900 mt-4">2. Menghitung Nilai Normalisasi</h4>
<div class="table-responsive">
<table class="table table-striped" width="100%">
<thead>
<tr>
<th class="text-center" rowspan="2" style="vertical-align: middle;">Alternatif</th>
<th class="text-center" colspan="{{ count($kriteria) }}">Kode Kriteria</th>
</tr>
<tr>
@foreach ($kriteria as $item)
<th class="text-center">{{ $item->kode_kriteria }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach ($normalisasi as $key => $value)
<tr>
<td width="20%">{{ $key }}</td>
@foreach ($value as $key_1 => $value_1)
<td class="text-center">{{ number_format($value_1 ,2) }}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div>
<h4 class="text-gray-900 mt-4">3. Perankingan</h4>
<div class="table-responsive">
<table class="table table-striped text-center" width="100%">
<thead>
<tr>
<th>Kode Kriteria</th>
@foreach ($kriteria as $item)
<th class="text-center">{{ $item->kode_kriteria }}</th>
@endforeach
<th rowspan="2" style="vertical-align: middle">Total</th>
<!-- <th rowspan="2" style="vertical-align: middle">Rank</th> -->
</tr>
<tr>
<th>Bobot</th>
@foreach ($kriteria as $item)
<th class="text-center">{{ $item->bobot_kriteria }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach ($rank as $key => $value)
<tr>
<td width="20%">{{ $key }}</td>
@foreach ($value as $key_1 => $value_1)
<td class="text-center">{{ number_format($value_1 ,2) }}</td>
@endforeach
<!-- <td>{{ $loop->iteration }}</td> -->
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@endsection
@push('js')