public RankRequest GenerateRank() { string eventId = Guid.NewGuid().ToString(); // Get the actions list to choose from personalizer with their features. IList <RankableAction> actions = GetActions(); // Get context information from the user. HttpRequestFeatures httpRequestFeatures = GetHttpRequestFeaturesFromRequest(Request); string timeOfDayFeature = GetUsersTimeOfDay(); string tasteFeature = GetUsersTastePreference(); // Create current context from user specified data. IList <object> currentContext = new List <object>() { new { time = timeOfDayFeature }, new { taste = tasteFeature }, new { httpRequestFeatures } }; // Exclude an action for personalizer ranking. This action will be held at its current position. IList <string> excludeActions = new List <string> { "juice" }; // Rank the actions return(new RankRequest(actions, currentContext, excludeActions, eventId)); }
private Tuple <string, string> callPersonalizationService(HttpRequestFeatures httpRequestFeatures) { // Generate an ID to associate with the request. string eventId = Guid.NewGuid().ToString(); // Get the actions list to choose from personalization with their features. IList <RankableAction> actions = GetActions(); // Get context information from the user. string timeOfDayFeature = GetUsersTimeOfDay(); string tasteFeature = GetUsersTastePreference(); // Create current context from user specified data. IList <object> currentContext = new List <object>() { new { time = timeOfDayFeature }, new { taste = tasteFeature }, new { httpRequestFeatures } }; // Exclude an action for personalization ranking. This action will be held at its current position. IList <string> excludeActions = new List <string> { "juice" }; // Rank the actions var request = new RankRequest(actions, currentContext, excludeActions, eventId); RankResponse response = client.Rank(request); string rankjson = JsonConvert.SerializeObject(request, Formatting.Indented); string rewardjson = JsonConvert.SerializeObject(response, Formatting.Indented); return(Tuple.Create(rankjson, rewardjson)); }
/// <summary> /// Retrieve features from the http request /// </summary> /// <param name="httpRequest">User's HTTP request info</param> /// <returns>User's HTTP Request features</returns> private HttpRequestFeatures GetHttpRequestFeaturesFromRequest(HttpRequest httpRequest) { HttpRequestFeatures httpRequestFeatures = new HttpRequestFeatures { IsSynthetic = Utils.GetIsSyntheticFromRequest(httpRequest), GeoLocation = Utils.GetGeoLocationFromRequest(httpRequest), Refer = Utils.GetRefererFromRequest(httpRequest), UserAgent = Utils.GetUserAgentFromRequest(httpRequest) }; return(httpRequestFeatures); }
public IActionResult Index() { HttpRequestFeatures httpRequestFeatures = GetHttpRequestFeaturesFromRequest(Request); ViewData["UserAgent"] = JsonConvert.SerializeObject(httpRequestFeatures, Formatting.Indented); Tuple <string, string> personalizationobj = callPersonalizationService(httpRequestFeatures); ViewData["Personalization Rank Request"] = personalizationobj.Item1; ViewData["Personalization Reward Request"] = personalizationobj.Item2; return(View()); }