示例#1
0
 public function addMdiff($movieA, $movieB)
 {
     foreach ($this->users as $user) {
         $noteA = Note::where("movie_id", $movieA->id)->where("user_id", $user->id)->first();
         $noteB = Note::where("movie_id", $movieB->id)->where("user_id", $user->id)->first();
         if ($noteA && $noteB) {
             $diff = $noteA->note - $noteB->note;
             $data = ["movieA_id" => $noteA->movie_id, "movieB_id" => $noteB->movie_id, "diff" => $diff];
             Mdiff::create($data);
             $this->qtdDiffs++;
         }
     }
 }
示例#2
0
 private function calcRates()
 {
     $candidates = [];
     $this->userNotRatedMovies->each(function ($movieA, $index) use(&$candidates) {
         $diffNote = [];
         $this->userRatedMovies->each(function ($note, $index) use($movieA, &$diffNote) {
             $diff = Mdiff::where('movieA_id', $movieA->_id)->first();
             if (empty($diff)) {
                 $diff = Mdiff::where('movieB_id', $movieA->_id)->where('movieA_id', $note->movie_id)->first();
             }
             if (!empty($diff)) {
                 array_push($diffNote, $diff->diff);
             }
         });
         if (empty($diffNote)) {
             $note = 0;
         } else {
             $note = array_sum($diffNote) / count($diffNote);
         }
         array_push($candidates, ['note' => $note, 'movie' => $movieA]);
     });
     return $this->orderCandidates($candidates);
 }