From c638d2240c37d54b9ee8f05bfc57b67221851c94 Mon Sep 17 00:00:00 2001 From: iFannJR Date: Wed, 3 Jun 2026 21:37:39 +0700 Subject: [PATCH] perbaikan metode dan view --- app/Services/ToyRecommendationService.php | 24 +++++++++++++++++++ resources/views/user/recommendation.blade.php | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/Services/ToyRecommendationService.php b/app/Services/ToyRecommendationService.php index 68ceac4..a4e8499 100644 --- a/app/Services/ToyRecommendationService.php +++ b/app/Services/ToyRecommendationService.php @@ -326,6 +326,30 @@ protected function buildWeightsFromPriorities(array $priorities, Collection $cri return $weights; } + // 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; + // $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; + // } + + // return $weights; + // } + protected function buildMatrix(Collection $products, Collection $criterias): array { $matrix = []; diff --git a/resources/views/user/recommendation.blade.php b/resources/views/user/recommendation.blade.php index fdf1f0c..7036c95 100644 --- a/resources/views/user/recommendation.blade.php +++ b/resources/views/user/recommendation.blade.php @@ -20,10 +20,10 @@
- + value="{{ old('budget_min', 5000) }}" min="0" required />