memperbaiki cost/benefit
This commit is contained in:
parent
4b2a9130cd
commit
e68e59a169
|
|
@ -205,23 +205,33 @@ protected function ageRangeOverlaps(string $ageRange, int $childMin, int $childM
|
|||
|
||||
protected function buildWeightsFromPriorities(array $priorities, Collection $criterias): array
|
||||
{
|
||||
// priorities: [criteria_id => 1..5]
|
||||
// return weights by criteria name: ['Harga' => 0.2, 'Kualitas' => 0.2, ...]
|
||||
$raw = [];
|
||||
$sum = 0.0;
|
||||
|
||||
foreach ($criterias as $c) {
|
||||
$w = (float) ($priorities[(string) $c->id] ?? $priorities[$c->id] ?? 1);
|
||||
if ($w < 1) $w = 1;
|
||||
if ($w > 5) $w = 5;
|
||||
|
||||
$input = (int) ($priorities[(string) $c->id] ?? $priorities[$c->id] ?? 3);
|
||||
|
||||
if ($input < 1)
|
||||
$input = 1;
|
||||
if ($input > 5)
|
||||
$input = 5;
|
||||
|
||||
// Jika Cost, dibalik
|
||||
if ($c->type === 'cost') {
|
||||
$w = 6 - $input;
|
||||
} else {
|
||||
$w = $input;
|
||||
}
|
||||
|
||||
$raw[$c->name] = $w;
|
||||
$sum += $w;
|
||||
}
|
||||
|
||||
$count = max(1, $criterias->count());
|
||||
$weights = [];
|
||||
foreach ($raw as $name => $v) {
|
||||
$weights[$name] = $sum > 0 ? $v / $sum : 1 / $count;
|
||||
|
||||
foreach ($raw as $name => $value) {
|
||||
$weights[$name] = $value / $sum;
|
||||
}
|
||||
|
||||
return $weights;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->longBlob('image_blob')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->binary('image_blob')->nullable()->after('image');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->dropColumn('image_blob');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue