public void CreateEvaluation() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "CreateEvaluation"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); var evaluation = new EvaluationContract { Name = "myFirstEvaluation", StartTime = new DateTime(2018, 12, 19), EndTime = new DateTime(2019, 1, 19), EnableOfflineExperimentation = true, Policies = new PolicyContract[] { new PolicyContract { Name = "Custom Policy 1", Arguments = "--cb_explore_adf --epsilon 0.2 --dsjson --cb_type ips -l 0.5 --l1 1E-07 --power_t 0.5" } } }; Evaluation createdEvaluation = client.Evaluations.Create(evaluation); Assert.Equal(evaluation.Name, createdEvaluation.Name); } }
public async Task UpdateServiceConfiguration() { using (MockContext.Start(this.GetType().FullName)) { HttpMockServer.Initialize(this.GetType().FullName, "UpdateServiceConfiguration"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); TimeSpan newExperimentalUnitDuration = TimeSpan.FromMinutes(1); TimeSpan modelExportFrequency = TimeSpan.FromHours(1); double newDefaultReward = 1.0; string newRewardFuntion = "average"; double newExplorationPercentage = 0.2f; var config = new ServiceConfiguration { RewardAggregation = newRewardFuntion, ModelExportFrequency = modelExportFrequency.ToString(), DefaultReward = newDefaultReward, RewardWaitTime = newExperimentalUnitDuration.ToString(), ExplorationPercentage = newExplorationPercentage }; ServiceConfiguration result = await client.ServiceConfiguration.UpdateAsync(config); Assert.Equal(config.DefaultReward, result.DefaultReward); Assert.True(Math.Abs(config.ExplorationPercentage - result.ExplorationPercentage) < 1e-3); Assert.Equal(config.ModelExportFrequency, result.ModelExportFrequency); Assert.Equal(config.RewardAggregation, result.RewardAggregation); Assert.Equal(config.RewardWaitTime, result.RewardWaitTime); } }
public async Task RankNullParameters() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "RankNullParameters"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); IList <RankableAction> actions = new List <RankableAction>(); actions.Add(new RankableAction { Id = "Person", Features = new List <object>() { new { videoType = "documentary", videoLength = 35, director = "CarlSagan" }, new { mostWatchedByAge = "30-35" } } }); var request = new RankRequest(actions); // Action RankResponse response = await client.RankAsync(request); // Assert Assert.Equal(actions.Count, response.Ranking.Count); for (int i = 0; i < response.Ranking.Count; i++) { Assert.Equal(actions[i].Id, response.Ranking[i].Id); } } }
/// <summary> /// A Personalizer rank request. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='rankRequest'> /// A Personalizer request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <RankResponse> RankAsync(this IPersonalizerClient operations, RankRequest rankRequest, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.RankWithHttpMessagesAsync(rankRequest, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public async Task ResetModel() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "ResetModel"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); await client.Model.ResetAsync(); } }
public async Task DeleteLogs() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "DeleteLogs"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); await client.Log.DeleteAsync(); } }
public async Task Reward() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "Reward"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); await client.RewardAsync("123456789", new RewardRequest(0.5)); } }
public void DeleteEvaluation() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "DeleteEvaluation"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); string evaluationId = "b58c6d92-b727-48c1-9487-4be2782c9e0a"; client.Evaluations.Delete(evaluationId); } }
public async Task GetModel() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "GetModel"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); Stream stream = await client.Model.GetAsync(); Assert.NotEqual(-1, stream.ReadByte()); } }
public async Task DeleteModel() { using (MockContext.Start(this.GetType().FullName)) { HttpMockServer.Initialize(this.GetType().FullName, "DeleteModel"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); await client.Model.DeleteAsync(); } }
public void GetEvaluation() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "GetEvaluation"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); string evaluationId = "014fd077-b5ab-495b-8ef9-f6d2dce9c624"; Evaluation evaluation = client.Evaluations.Get(evaluationId); Assert.Equal(evaluationId, evaluation.Id); } }
public void GetEvaluations() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "GetEvaluations"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); IList <Evaluation> evaluations = client.Evaluations.List(); Assert.True(evaluations.Count > 0); Assert.Equal("myFirstEvaluation", evaluations[0].Name); } }
public async Task GetLogsProperties() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "GetLogsProperties"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); LogsProperties properties = await client.Log.GetPropertiesAsync(); Assert.Equal(new DateTime(0001, 01, 01), new DateTime(properties.DateRange.FromProperty.Value.Year, properties.DateRange.FromProperty.Value.Month, properties.DateRange.FromProperty.Value.Day)); Assert.Equal(new DateTime(0001, 01, 01), new DateTime(properties.DateRange.To.Value.Year, properties.DateRange.To.Value.Month, properties.DateRange.To.Value.Day)); } }
public async Task RankServerFeatures() { using (MockContext.Start(this.GetType().FullName)) { HttpMockServer.Initialize(this.GetType().FullName, "RankServerFeatures"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); IList <object> contextFeatures = new List <object>() { new { Features = new { day = "tuesday", time = "night", weather = "rainy" } }, new { Features = new { userId = "1234", payingUser = true, favoriteGenre = "documentary", hoursOnSite = 0.12, lastwatchedType = "movie" } } }; IList <RankableAction> actions = new List <RankableAction>(); actions.Add(new RankableAction { Id = "Person1", Features = new List <object>() { new { videoType = "documentary", videoLength = 35, director = "CarlSagan" }, new { mostWatchedByAge = "30-35" } } }); actions.Add(new RankableAction { Id = "Person2", Features = new List <object>() { new { videoType = "documentary", videoLength = 35, director = "CarlSagan" }, new { mostWatchedByAge = "40-45" } } }); IList <string> excludeActions = new List <string> { "Person1" }; string eventId = "123456789"; var request = new RankRequest(actions, contextFeatures, excludeActions, eventId); // Action RankResponse response = await client.RankAsync(request); // Assert Assert.Equal(eventId, response.EventId); Assert.Equal(actions.Count, response.Ranking.Count); for (int i = 0; i < response.Ranking.Count; i++) { Assert.Equal(actions[i].Id, response.Ranking[i].Id); } } }
public async Task GetModelProperties() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "GetModelProperties"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); ModelProperties modelProperties = await client.Model.GetPropertiesAsync(); Assert.True(modelProperties.CreationTime != null); Assert.True(modelProperties.LastModifiedTime != null); } }
public async Task ResetPolicy() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "ResetPolicy"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); PolicyContract policy = await client.Policy.ResetAsync(); Assert.Equal("--cb_explore_adf --quadratic GT --quadratic MR --quadratic GR --quadratic ME --quadratic OT --quadratic OE --quadratic OR --quadratic MS --quadratic GX --ignore A --cb_type ips --epsilon 0.2", policy.Arguments); } }
public void GetEvaluation() { using (MockContext.Start(this.GetType().FullName)) { HttpMockServer.Initialize(this.GetType().FullName, "GetEvaluation"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); string evaluationId = "0f3cf6a9-f33f-4bb0-967e-3607cefef74e"; Evaluation evaluation = client.Evaluations.Get(evaluationId); Assert.Equal(evaluationId, evaluation.Id); } }
public async Task GetServiceConfiguration() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "GetServiceConfiguration"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); ServiceConfiguration defaultConfig = await client.ServiceConfiguration.GetAsync(); Assert.Equal(TimeSpan.FromMinutes(1), defaultConfig.RewardWaitTime); Assert.Equal(TimeSpan.FromHours(1), defaultConfig.ModelExportFrequency); Assert.Equal(1, defaultConfig.DefaultReward); Assert.Equal(0.2, defaultConfig.ExplorationPercentage); Assert.Equal(0, defaultConfig.LogRetentionDays); } }
/// <summary> /// A Personalizer rank request. /// </summary> /// <param name="client">The PersonalizerClient for this extension method.</param> /// <param name="features">Features of the context used for Personalizer as a dictionary of dictionaries.</param> /// <param name="actions">The set of actions the Personalizer service can pick from.</param> /// <param name="eventId">Optionally pass an eventId that uniquely identifies this Rank event.</param> /// <param name="excludedActions">The set of action ids to exclude from ranking.</param> /// <param name="deferActivation">Send false if the user will see the rank results.</param> /// <returns></returns> public static RankResponse Rank( this IPersonalizerClient client, List <object> features, List <RankableAction> actions, string eventId = null, List <string> excludedActions = null, bool deferActivation = false) { return(client.Events.Rank(new RankRequest { ContextFeatures = features, Actions = actions, EventId = eventId, ExcludedActions = excludedActions, DeferActivation = deferActivation })); }
public async Task UpdatePolicy() { using (MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "UpdatePolicy"); IPersonalizerClient client = GetClient(HttpMockServer.CreateInstance()); var policy = new PolicyContract { Name = "app1", Arguments = "--cb_explore_adf --quadratic GT --quadratic MR --quadratic GR --quadratic ME --quadratic OT --quadratic OE --quadratic OR --quadratic MS --quadratic GX --ignore A --cb_type ips --epsilon 0.2" }; var updatedPolicy = await client.Policy.UpdateAsync(policy); Assert.NotNull(updatedPolicy); Assert.Equal(policy.Arguments, updatedPolicy.Arguments); } }
/// <summary> /// A Personalizer rank request. /// </summary> /// <param name="client">The PersonalizerClient for this extension method.</param> /// <param name="features">Features of the context used for Personalizer as a dictionary of dictionaries.</param> /// <param name="actions">The set of actions the Personalizer service can pick from.</param> /// <param name="eventId">Optionally pass an eventId that uniquely identifies this Rank event.</param> /// <param name="excludedActions">The set of action ids to exclude from ranking.</param> /// <param name="deferActivation">Send false if the user will see the rank results.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public static Task <RankResponse> RankAsync( this IPersonalizerClient client, List <object> features, List <RankableAction> actions, string eventId = null, List <string> excludedActions = null, bool deferActivation = false, CancellationToken cancellationToken = default(CancellationToken)) { return(client.Events.RankAsync(new RankRequest { ContextFeatures = features, Actions = actions, EventId = eventId, ExcludedActions = excludedActions, DeferActivation = deferActivation }, cancellationToken)); }
/// <summary> /// Report reward to allocate to the top ranked action for the specified event. /// </summary> /// <param name='client'> /// The PersonalizerClient for this extension method. /// </param> /// <param name='eventId'> /// The event id this reward applies to. /// </param> /// <param name='reward'> /// The reward to be assigned to an action. Value must be /// between -1 and 1 inclusive. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static Task RewardAsync(this IPersonalizerClient client, string eventId, double reward, CancellationToken cancellationToken = default(CancellationToken)) { return(client.Events.RewardAsync(eventId, new RewardRequest { Value = reward }, cancellationToken)); }
/// <summary> /// Report reward to allocate to the top ranked action for the specified event. /// </summary> /// <param name='client'> /// The PersonalizerClient for this extension method. /// </param> /// <param name='eventId'> /// The event id this reward applies to. /// </param> /// <param name='reward'> /// The reward to be assigned to an action. Value must be /// between -1 and 1 inclusive. /// </param> public static void Reward(this IPersonalizerClient client, string eventId, double reward) { client.Events.Reward(eventId, new RewardRequest { Value = reward }); }
/// <summary> /// Report reward to allocate to the top ranked action for the specified event. /// </summary> /// <param name='client'> /// The PersonalizerClient for this extension method. /// </param> /// <param name='eventId'> /// The event id this reward applies to. /// </param> /// <param name='reward'> /// The reward should be a floating point number. /// </param> public static void Reward(this IPersonalizerClient client, string eventId, RewardRequest reward) { client.Events.Reward(eventId, reward); }
/// <summary> /// A Personalizer rank request. /// </summary> /// <param name='client'> /// The PersonalizerClient for this extension method. /// </param> /// <param name='rankRequest'> /// A Personalizer request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static Task <RankResponse> RankAsync(this IPersonalizerClient client, RankRequest rankRequest, CancellationToken cancellationToken = default(CancellationToken)) { return(client.Events.RankAsync(rankRequest, cancellationToken)); }
/// <summary> /// A Personalizer rank request. /// <param name='client'> /// The PersonalizerClient for this extension method. /// The operations group for this extension method. /// </param> /// <param name='rankRequest'> /// A Personalizer request. /// </param> public static RankResponse Rank(this IPersonalizerClient client, RankRequest rankRequest) { return(client.Events.Rank(rankRequest)); }
/// <summary> /// A Personalizer rank request. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='rankRequest'> /// A Personalizer request. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> public static HttpOperationResponse <RankResponse> RankWithHttpMessages(this IPersonalizerClient operations, RankRequest rankRequest, Dictionary <string, List <string> > customHeaders = null) { return(operations.RankWithHttpMessagesAsync(rankRequest, customHeaders, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult()); }
public PersonalizerController(IPersonalizerClient client, IActionsRepository actionsRepository) { _client = client; _actionsRepository = actionsRepository; }
/// <summary> /// A Personalizer rank request. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='rankRequest'> /// A Personalizer request. /// </param> public static RankResponse Rank(this IPersonalizerClient operations, RankRequest rankRequest) { return(operations.RankAsync(rankRequest).GetAwaiter().GetResult()); }
public PersonalizerService(IActionsRepository actionsRepository, IPersonalizerClient personalizerClient, IArticleRepository articleRepository) { _actionsRepository = actionsRepository; _personalizerClient = personalizerClient; _articleRepository = articleRepository; }