private static PersonalizerRankResult GenerateRankResultInner(List <PersonalizerRankableAction> originalActions, List <PersonalizerRankableAction> rankableActions, List <PersonalizerRankableAction> excludedActions, int[] rankedIndices, float[] rankingProbabilities, string eventId) { // excluded actions are not passed into VW // rankedIndices[0] is the index of the VW chosen action (1 based index) int chosenActionIndex = rankedIndices[0] - 1; // take care of actions that are excluded in their original positions if (excludedActions != null && excludedActions.Count > 0) { var newRanking = new int[originalActions.Count]; var probabilities = new float[originalActions.Count]; // at the original position // point the original position of ranked item for (int i = 0; i < rankableActions.Count; i++) { //RankableActions is Actions - ExcludedActions newRanking[rankableActions[i].Index] = rankableActions[rankedIndices[i] - 1].Index + 1; probabilities[rankableActions[i].Index] = rankingProbabilities[i]; } // update excluded positions foreach (var l in excludedActions) { newRanking[l.Index] = l.Index + 1; } rankedIndices = newRanking; rankingProbabilities = probabilities; } // finalize decision response ranking var rankings = rankedIndices?.Select((index, i) => { var action = originalActions[index - 1]; return(new PersonalizerRankedAction(action.Id, rankingProbabilities[i])); }).ToList(); // setting RewardActionId to be the VW chosen action. var personalizerRankResult = new PersonalizerRankResult(rankings, eventId, rankableActions.ElementAt(chosenActionIndex)?.Id); return(personalizerRankResult); }
public async Task <Response <PersonalizerRankResult> > RankAsync(PersonalizerRankOptions rankRequest, CancellationToken cancellationToken = default) { if (rankRequest == null) { throw new ArgumentNullException(nameof(rankRequest)); } using var message = CreateRankRequest(rankRequest); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 201: { PersonalizerRankResult value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = PersonalizerRankResult.DeserializePersonalizerRankResult(document.RootElement); return(Response.FromValue(value, message.Response)); }