Example #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->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'));
 }
Example #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 = 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'));
 }