Пример #1
0
        private int SendEvents(DecisionServiceClient <MyContext> client, int numberOfEvents)
        {
            var expectedEvents = 0;

            for (int i = 0; i < numberOfEvents; i++)
            {
                var key = Guid.NewGuid().ToString();

                var featureIndex = i % features.Length;

                var action = client.ChooseAction(key, new MyContext {
                    Feature = features[featureIndex]
                });
                expectedEvents++;

                // Feature | Action
                //    A   -->  1
                //    B   -->  2
                //    C   -->  3
                //    D   -->  4
                // only report in 50% of the cases
                if (rnd.NextDouble() < .75 && action - 1 == featureIndex)
                {
                    client.ReportReward(2, key);
                    expectedEvents++;
                }

                var stat = string.Format("'{0}' '{1}' ", features[featureIndex], action);
                int count;
                if (freq.TryGetValue(stat, out count))
                {
                    freq[stat]++;
                }
                else
                {
                    freq.Add(stat, count);
                }
            }

            return(expectedEvents);
        }
Пример #2
0
        public static void Initialize(string settingsUrl)
        {
            var telemetry = new TelemetryClient();

            var config = new DecisionServiceConfiguration(settingsUrl)
            {
                InteractionUploadConfiguration = new BatchingConfiguration
                {
                    MaxDuration       = TimeSpan.FromSeconds(2),
                    UploadRetryPolicy = BatchUploadRetryPolicy.ExponentialRetry
                },
                ModelPollFailureCallback = e => telemetry.TrackException(e, new Dictionary <string, string> {
                    { "Pool failure", "model" }
                }),
                SettingsPollFailureCallback = e => telemetry.TrackException(e, new Dictionary <string, string> {
                    { "Pool failure", "settings" }
                }),
                // AzureStorageConnectionString = ConfigurationManager.AppSettings[ApplicationMetadataStore.AKConnectionString]
            };

            client = DecisionService.CreateJson(config);
        }