コード例 #1
0
 public function postPreference()
 {
     $preference = Input::get('preference');
     $user = Auth::user();
     foreach ($preference as $id => $score) {
         $userpreference = $user->visualizations()->where('id', $id)->first();
         if ($userpreference === null) {
             $visualization = \App\Visualization::find($id);
             $user->visualizations()->attach($visualization, ['knowledge' => $score]);
         } else {
             $userpreference->pivot->knowledge = $score;
             $userpreference->pivot->save();
             $userpreference->save();
         }
     }
     return redirect('home');
 }
コード例 #2
0
 public function generatePrediction($similaritems, $vectors)
 {
     $weight = 0;
     $sum = 0;
     $user = Auth::user();
     $users = \App\User::all();
     $index = 0;
     for ($i = 0; $i < count($users); $i++) {
         if ($users[$i]->id == $user->id) {
             $index = $i;
             break;
         }
     }
     foreach ($similaritems as $similaritem) {
         $visualization = Visualization::find($similaritem->visualization);
         $rating = $vectors[$similaritem->visualization - 1][$index];
         $weight += $similaritem->similarity * $rating;
         $sum += $similaritem->similarity;
     }
     return $weight / $sum;
 }