Ejemplo n.º 1
0
 public static function recommended()
 {
     $dbname = 'predictionio_appdata';
     $mdb = Flight::mdb();
     $db = $mdb->{$dbname};
     $items = $db->items;
     $client = Flight::prediction_client();
     $recommended_movies = array();
     try {
         $user_id = $_SESSION['user_id'];
         $client = new EngineClient('http://localhost:8000');
         $recommended_movies_raw = $client->sendQuery(array('user' => $user_id, 'num' => 9));
         $movie_iids = array_map(function ($item) {
             return $item['item'];
         }, $recommended_movies_raw['itemScores']);
         $cursor = $items->find(array('itypes' => '1', '_id' => array('$in' => $movie_iids)));
         $recommended_movies = array_values(iterator_to_array($cursor));
     } catch (Exception $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
     }
     $_SESSION['movies_viewed'] = 0;
     $_SESSION['user_id'] = '';
     Flight::render('recommended', array('recommended_movies' => $recommended_movies), 'content');
     Flight::render('layout', array('title' => 'Recommended', 'base_path' => '/movie_recommender'));
 }
Ejemplo n.º 2
0
 public static function recommended()
 {
     $dbname = 'predictionio_appdata';
     $mdb = Flight::mdb();
     $db = $mdb->{$dbname};
     $items = $db->items;
     $client = Flight::prediction_client();
     $recommended_movies = array();
     try {
         $user_id = $_SESSION['user_id'];
         $client->identify($user_id);
         $command = $client->getCommand('itemrec_get_top_n', array('pio_engine' => 'movie-recommender', 'pio_n' => 9));
         $recommended_movies_raw = $client->execute($command);
         $movie_iids = $recommended_movies_raw['pio_iids'];
         array_walk($movie_iids, function (&$movie_iid) {
             $movie_iid = '4_' . $movie_iid;
         });
         $cursor = $items->find(array('itypes' => '1', '_id' => array('$in' => $movie_iids)));
         $recommended_movies = array_values(iterator_to_array($cursor));
     } catch (Exception $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
     }
     $_SESSION['movies_viewed'] = 0;
     $_SESSION['user_id'] = '';
     Flight::render('recommended', array('recommended_movies' => $recommended_movies), 'content');
     Flight::render('layout', array('title' => 'Recommended', 'base_path' => '/movie_recommender'));
 }
Ejemplo n.º 3
0
 public static function import()
 {
     //$client = PredictionIOClient::factory(array("appkey" => "YOUR_PREDICTIONIO_APP_KEY"));
     //$accessKey = 'PZATchzAcnbZTzP12WgA1e4sZQGcQLtDJ1CKUlrOVHs7s7zocXbOb1XQAlZnlkSu';
     //$client = new EventClient($accessKey, 'http://localhost:7070');
     $client = Flight::prediction_client();
     $index = 0;
     for ($x = 1; $x <= 1; $x++) {
         $movies_url = 'https://api.themoviedb.org/3/movie/popular?api_key=b119b6067ef52d84c667d86bd6bab5c3&page=' . $x;
         $movies_response = Flight::guzzle()->get($movies_url);
         $movies_body = $movies_response->getBody();
         $movies_result = json_decode($movies_body, true);
         $movies = $movies_result['results'];
         if (!empty($movies)) {
             foreach ($movies as $row) {
                 $id = $row['id'];
                 $title = $row['title'];
                 $poster_path = '';
                 if (!empty($row['poster_path'])) {
                     $poster_path = $row['poster_path'];
                 }
                 $moviedetails_url = 'https://api.themoviedb.org/3/movie/' . $id . '?api_key=b119b6067ef52d84c667d86bd6bab5c3';
                 $moviedetails_response = Flight::guzzle()->get($moviedetails_url);
                 $movie_details_body = $moviedetails_response->getBody();
                 $movie = json_decode($movie_details_body, true);
                 $overview = $movie['overview'];
                 $release_date = $movie['release_date'];
                 $client_response = $client->setItem($index, array('itypes' => 1, 'tmdb_id' => $id, 'title' => $title, 'poster_path' => $poster_path, 'overview' => $overview, 'release_date' => $release_date));
                 echo "<pre>";
                 print_r($client_response);
                 echo "</pre>";
                 echo "<br><br>";
                 $index++;
             }
         }
     }
 }