Esempio n. 1
0
        public async Task <MostPopularItems> GetMostPopularItems(string userId)
        {
            MostPopularItems results = null;

            try
            {
                //USER_PERSONALIZATION -- userid required
                var request = new GetRecommendationsRequest
                {
                    CampaignArn = AwsParameterStoreClient.GetSimsMostPopularArn(), //sims-most-popular
                    UserId      = userId,
                    NumResults  = 10
                };

                var response = await AmazonPersonalizeRuntimeClient.GetRecommendationsAsync(request);

                var recommendedItems = response.ItemList;

                var json = JsonConvert.SerializeObject(recommendedItems);

                Logger.LogInformation("GetMostPopularItems for userid:" + userId + ": " + json);

                results = new MostPopularItems();

                List <string> itemIds = recommendedItems.Select(s => s.ItemId).ToList();

                results.Movies = await _storageService.GetMovieData(itemIds.ToArray());

                return(results);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list of recommended items. For campaigns, the campaign's Amazon Resource
        /// Name (ARN) is required and the required user and item input depends on the recipe
        /// type used to create the solution backing the campaign as follows:
        ///
        ///  <ul> <li>
        /// <para>
        /// USER_PERSONALIZATION - <code>userId</code> required, <code>itemId</code> not used
        /// </para>
        ///  </li> <li>
        /// <para>
        /// RELATED_ITEMS - <code>itemId</code> required, <code>userId</code> not used
        /// </para>
        ///  </li> </ul> <note>
        /// <para>
        /// Campaigns that are backed by a solution created using a recipe of type PERSONALIZED_RANKING
        /// use the API.
        /// </para>
        ///  </note>
        /// <para>
        ///  For recommenders, the recommender's ARN is required and the required item and user
        /// input depends on the use case (domain-based recipe) backing the recommender. For information
        /// on use case requirements see <a href="https://docs.aws.amazon.com/personalize/latest/dg/domain-use-cases.html">Choosing
        /// recommender use cases</a>.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetRecommendations service method.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        ///
        /// <returns>The response from the GetRecommendations service method, as returned by PersonalizeRuntime.</returns>
        /// <exception cref="Amazon.PersonalizeRuntime.Model.InvalidInputException">
        /// Provide a valid value for the field or parameter.
        /// </exception>
        /// <exception cref="Amazon.PersonalizeRuntime.Model.ResourceNotFoundException">
        /// The specified resource does not exist.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/personalize-runtime-2018-05-22/GetRecommendations">REST API Reference for GetRecommendations Operation</seealso>
        public virtual Task <GetRecommendationsResponse> GetRecommendationsAsync(GetRecommendationsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetRecommendationsRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetRecommendationsResponseUnmarshaller.Instance;

            return(InvokeAsync <GetRecommendationsResponse>(request, options, cancellationToken));
        }
Esempio n. 3
0
        internal virtual GetRecommendationsResponse GetRecommendations(GetRecommendationsRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetRecommendationsRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetRecommendationsResponseUnmarshaller.Instance;

            return(Invoke <GetRecommendationsResponse>(request, options));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the GetRecommendations operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetRecommendations operation on AmazonPersonalizeRuntimeClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetRecommendations
        ///         operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/personalize-runtime-2018-05-22/GetRecommendations">REST API Reference for GetRecommendations Operation</seealso>
        public virtual IAsyncResult BeginGetRecommendations(GetRecommendationsRequest request, AsyncCallback callback, object state)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetRecommendationsRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetRecommendationsResponseUnmarshaller.Instance;

            return(BeginInvoke(request, options, callback, state));
        }
Esempio n. 5
0
        public async Task <PersonalizeViewModel> GetRecommendations(string userId)
        {
            PersonalizeViewModel results = null;

            try
            {
                //USER_PERSONALIZATION -- userid required
                var request = new GetRecommendationsRequest
                {
                    CampaignArn = AwsParameterStoreClient.GetPersonalRecommendationsArn(), //personal-recommendations-metadata
                    UserId      = userId,
                    NumResults  = 10
                };

                var response = await AmazonPersonalizeRuntimeClient.GetRecommendationsAsync(request);

                var recommendedItems = response.ItemList;

                var json = JsonConvert.SerializeObject(recommendedItems);

                Logger.LogInformation("GetRecommendations:" + userId + ": " + json);

                results = new PersonalizeViewModel {
                    User = new User()
                    {
                        User_Id = userId
                    }
                };

                //get movie thumbnail from imdb
                IList <RecommendedItems> recItems = new List <RecommendedItems>();

                List <string> itemIds = recommendedItems.Select(s => s.ItemId).ToList();

                results.RecommendedItems.Movies = await _storageService.GetMovieData(itemIds.ToArray());

                return(results);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 6
0
        public async Task <SimilarItemViewModel> GetSimilarItems(string movieItemId)
        {
            SimilarItemViewModel results = null;

            try
            {
                //RELATED_ITEMS -- itemId required
                var relateditemsrequest = new GetRecommendationsRequest
                {
                    CampaignArn = AwsParameterStoreClient.GetSimsArn(), //sims-arn
                    ItemId      = movieItemId,
                    NumResults  = 10
                };

                var relateditemsrequestresponse = await AmazonPersonalizeRuntimeClient.GetRecommendationsAsync(relateditemsrequest);

                var relateditemsrequestrecommendedItems = relateditemsrequestresponse.ItemList;

                var json = JsonConvert.SerializeObject(relateditemsrequestrecommendedItems);

                Logger.LogInformation("GetSimilarItems for movie:" + movieItemId + ": " + json);

                results = new SimilarItemViewModel
                {
                    //selected movie
                    Movie = await _storageService.GetMovieData(movieItemId)
                };


                List <string> itemIds = relateditemsrequestrecommendedItems.Select(s => s.ItemId).ToList();

                results.SimilarItems.Movies = await _storageService.GetMovieData(itemIds.ToArray());

                return(results);
            }
            catch (Exception ex)
            {
                throw;
            }
        }