예제 #1
0
        public void TestPersonalization()
        {
            var strategyToSave = new SetStrategyRequest
            {
                EventsScoring = new Dictionary <string, EventScoring>
                {
                    { "Add to cart", new EventScoring {
                          Score = 50, Type = "conversion"
                      } },
                    { "Purchase", new EventScoring {
                          Score = 100, Type = "conversion"
                      } }
                },
                FacetsScoring = new Dictionary <string, FacetScoring>
                {
                    { "brand", new FacetScoring {
                          Score = 100
                      } },
                    { "categories", new FacetScoring {
                          Score = 10
                      } }
                }
            };

            // Here we test the payload, as this settings are at app level all tests could overlap
            string json         = JsonConvert.SerializeObject(strategyToSave, JsonConfig.AlgoliaJsonSerializerSettings);
            string expectedJson =
                "{\"eventsScoring\":{\"Add to cart\":{\"type\":\"conversion\",\"score\":50},\"Purchase\":{\"type\":\"conversion\",\"score\":100}},\"facetsScoring\":{\"brand\":{\"score\":100},\"categories\":{\"score\":10}}}";

            Assert.True(json.Equals(expectedJson));
        }
        public void TestRecommendationClient()
        {
            var request = new SetStrategyRequest(
                new List <EventsScoring>
            {
                new EventsScoring("Add to cart", "conversion", 50),
                new EventsScoring("Purchase", "conversion", 100),
            },
                new List <FacetsScoring>
            {
                new FacetsScoring("brand", 100),
                new FacetsScoring("categories", 10),
            },
                0
                );

            // The personalization API is now limiting the number of setPersonalizationStrategy()` successful calls
            // to 15 per day. If the 429 error is returned, the response is considered a "success".
            try
            {
                BaseTest.RecommendationClient.SetPersonalizationStrategy(request);
            }
            catch (AlgoliaApiException e) when(e.HttpErrorCode != 429)
            {
                Assert.Fail($"RecommendationClient.SetPersonalizationStrategy failure: HttpErrorCode: {e.HttpErrorCode}, HttpMessage {e.Message}");
            }
            Assert.DoesNotThrow(() => BaseTest.RecommendationClient.GetPersonalizationStrategy());
        }
예제 #3
0
 /// <inheritdoc />
 public async Task <SetStrategyResponse> SetPersonalizationStrategyAsync(SetStrategyRequest request,
                                                                         RequestOptions requestOptions = null, CancellationToken ct = default)
 {
     return(await _transport.ExecuteRequestAsync <SetStrategyResponse, SetStrategyRequest>(HttpMethod.Post,
                                                                                           "/1/recommendation/personalization/strategy", CallType.Write,
                                                                                           request, requestOptions, ct)
            .ConfigureAwait(false));
 }
예제 #4
0
 public override Task <Empty> SetStrategy(SetStrategyRequest request, ServerCallContext context)
 {
     return(mCreationService.ExecuteOrder(request.WarriorID, async orders =>
     {
         await orders.SetStrategy((Strategy)request.Strategy);
         return new Empty();
     }));
 }
        public void TestSetStrategyPayload()
        {
            var events = new List <EventsScoring>
            {
                new EventsScoring("buy", "conversion", 10), new EventsScoring("add to cart", "conversion", 20)
            };

            var facets = new List <FacetsScoring> {
                new FacetsScoring("brand", 10), new FacetsScoring("category", 20)
            };

            var validStrategy = new SetStrategyRequest(events, facets, 75);

            var payload = JsonConvert.SerializeObject(validStrategy, JsonConfig.AlgoliaJsonSerializerSettings);

            Assert.AreEqual(payload,
                            "{" +
                            "\"eventsScoring\":[{\"eventName\":\"buy\",\"eventType\":\"conversion\",\"score\":10},{\"eventName\":\"add to cart\",\"eventType\":\"conversion\",\"score\":20}]," +
                            "\"facetsScoring\":[{\"facetName\":\"brand\",\"score\":10},{\"facetName\":\"category\",\"score\":20}]," +
                            "\"personalizationImpact\":75}");
        }
예제 #6
0
 /// <inheritdoc />
 public SetStrategyResponse SetPersonalizationStrategy(SetStrategyRequest request,
                                                       RequestOptions requestOptions = null) =>
 AsyncHelper.RunSync(() => SetPersonalizationStrategyAsync(request, requestOptions));