Exemple #1
0
        public Response <PersonalizerMultiSlotRankResult> Rank(PersonalizerRankMultiSlotOptions options)
        {
            string eventId = options.EventId;

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

            Dictionary <string, int>             actionIdToActionIndex = RlObjectConverter.GetActionIdToIndexMapping(options.Actions);
            Dictionary <string, IList <object> > slotIdToFeatures      = new Dictionary <string, IList <object> >();

            foreach (var slot in options.Slots)
            {
                slotIdToFeatures.Add(slot.Id, RlObjectConverter.GetIncludedActionsForSlot(slot, actionIdToActionIndex));
            }

            // Convert options to the compatible parameter for ChooseRank
            DecisionContext decisionContext = new DecisionContext(options, slotIdToFeatures);
            var             contextJson     = JsonSerializer.Serialize(decisionContext);
            ActionFlags     flags           = options.DeferActivation == true ? ActionFlags.Deferred : ActionFlags.Default;

            int[] baselineActions = RlObjectConverter.ExtractBaselineActionsFromRankRequest(options);

            // Call ChooseRank of local RL.Net
            MultiSlotResponseDetailedWrapper multiSlotResponseDetailedWrapper = liveModel.RequestMultiSlotDecisionDetailed(eventId, contextJson, flags, baselineActions);

            // Convert response to PersonalizerRankResult
            var value = RlObjectConverter.GenerateMultiSlotRankResponse(options.Actions, multiSlotResponseDetailedWrapper, eventId);

            return(Response.FromValue(value, default));
        }
Exemple #2
0
        /// <summary>
        /// Convert PersonalizerRankOptions object to a json context string for Rl.Net
        /// </summary>
        public static string ConvertToContextJson(IEnumerable <object> contextFeatures, List <PersonalizerRankableAction> rankableActions)
        {
            DecisionContext decisionContext = new DecisionContext(contextFeatures, rankableActions);

            return(JsonSerializer.Serialize(decisionContext));
        }