/// <summary> Wrapper method of ChooseRank </summary>
        public override RankingResponseWrapper ChooseRank(string eventId, string contextJson, ActionFlags actionFlags)
        {
            RankingResponse        rankingResponse        = liveModel.ChooseRank(eventId, contextJson, actionFlags);
            RankingResponseWrapper rankingResponseWrapper = rankingResponse == null ? null : new RankingResponseWrapper(rankingResponse);

            return(rankingResponseWrapper);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create rank result based on Rl.Net response
        /// </summary>
        public static PersonalizerRankResult GenerateRankResult(List <PersonalizerRankableAction> originalActions,
                                                                List <PersonalizerRankableAction> rankableActions, List <PersonalizerRankableAction> excludedActions,
                                                                RankingResponseWrapper rankingResponse, string eventId)
        {
            var rankedIndices = rankingResponse?.Select(actionProbability => ((int)actionProbability.ActionIndex + 1)).ToArray();

            var rankingProbabilities = rankingResponse?.Select(actionProbability =>
                                                               actionProbability.Probability).ToArray();

            return(GenerateRankResultInner(originalActions, rankableActions, excludedActions, rankedIndices, rankingProbabilities, eventId));
        }
Exemplo n.º 3
0
        public Response <PersonalizerRankResult> Rank(PersonalizerRankOptions options)
        {
            string eventId = options.EventId;

            if (String.IsNullOrEmpty(eventId))
            {
                eventId = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
            }

            HashSet <string> excludedSet = new HashSet <string>(options.ExcludedActions);

            // Store the original action list
            List <PersonalizerRankableAction> originalActions = new List <PersonalizerRankableAction>();
            List <PersonalizerRankableAction> rankableActions = new List <PersonalizerRankableAction>();
            List <PersonalizerRankableAction> excludedActions = new List <PersonalizerRankableAction>();
            int idx = 0;

            foreach (var action in options.Actions)
            {
                PersonalizerRankableAction actionCopy = new PersonalizerRankableAction(action.Id, action.Features);
                actionCopy.Index = idx;
                originalActions.Add(actionCopy);
                if (excludedSet.Contains(actionCopy.Id))
                {
                    excludedActions.Add(actionCopy);
                }
                else
                {
                    rankableActions.Add(actionCopy);
                }
                ++idx;
            }

            // Convert options to the compatible parameter for ChooseRank
            var         contextJson = RlObjectConverter.ConvertToContextJson(options.ContextFeatures, rankableActions);
            ActionFlags flags       = options.DeferActivation == true ? ActionFlags.Deferred : ActionFlags.Default;

            // Call ChooseRank of local RL.Net
            RankingResponseWrapper rankingResponseWrapper = liveModel.ChooseRank(eventId, contextJson, flags);

            // Convert response to PersonalizerRankResult
            var value = RlObjectConverter.GenerateRankResult(originalActions, rankableActions, excludedActions, rankingResponseWrapper, options.EventId);

            return(Response.FromValue(value, default));
        }