Exemplo n.º 1
0
        public ActionResult Ranker(string defaultActions)
        {
            try
            {
                APIUtil.Authenticate(this.Request);

                int[] defaultActionArray = Array.ConvertAll(defaultActions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), Convert.ToInt32);

                var client  = DecisionServiceClientFactory.AddOrGetExisting(ModelSuccessNotifier);
                var context = APIUtil.ReadBody(this.Request);
                var eventId = APIUtil.CreateEventId();
                var actions = defaultActionArray != null && defaultActionArray.Length > 0 ?
                              client.ChooseRanking(eventId, context, defaultActionArray) :
                              client.ChooseRanking(eventId, context);

                return(Json(new
                {
                    EventId = eventId,
                    Actions = actions,
                    ModelTime = ModelUpdateTime
                }));
            }
            catch (UnauthorizedAccessException ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, ex.Message));
            }
            catch (Exception ex)
            {
                new TelemetryClient().TrackException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }
Exemplo n.º 2
0
        public ActionResult Policy(int defaultAction = -1)
        {
            try
            {
                APIUtil.Authenticate(this.Request);

                var client  = DecisionServiceClientFactory.AddOrGetExisting(ModelSuccessNotifier);
                var context = APIUtil.ReadBody(this.Request);
                var eventId = APIUtil.CreateEventId();
                var action  = defaultAction != -1 ? client.ChooseAction(eventId, context, defaultAction) : client.ChooseAction(eventId, context);

                return(Json(new
                {
                    EventId = eventId,
                    Action = action,
                    ModelTime = ModelUpdateTime
                }));
            }
            catch (UnauthorizedAccessException ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, ex.Message));
            }
            catch (Exception ex)
            {
                new TelemetryClient().TrackException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }
Exemplo n.º 3
0
        public ActionResult Reward(string eventId)
        {
            var telemetry = new TelemetryClient();

            try
            {
                APIUtil.Authenticate(this.Request);

                var client    = DecisionServiceClientFactory.AddOrGetExisting(ModelSuccessNotifier);
                var rewardStr = APIUtil.ReadBody(this.Request);

                var rewardObj = JToken.Parse(rewardStr);

                client.ReportOutcome(rewardObj, eventId);

                //if (rewardObj.Type == JTokenType.Float)
                //    telemetry.TrackEvent("Reward", metrics: new Dictionary<string, double> { { "Reward", rewardObj.ToObject<float>() } });
                //else
                //    telemetry.TrackEvent("Reward");

                // telemetry.TrackTrace($"HTTP Endpoint received reward report of: {rewardStr}");

                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (UnauthorizedAccessException ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, ex.Message));
            }
            catch (Exception ex)
            {
                telemetry.TrackException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }
Exemplo n.º 4
0
        public ActionResult Validate()
        {
            try
            {
                APIUtil.Authenticate(this.Request);

                if (this.metaData == null || lastDownload + TimeSpan.FromMinutes(1) < DateTime.Now)
                {
                    var url = APIUtil.GetSettingsUrl();
                    this.metaData = ApplicationMetadataUtil.DownloadMetadata <ApplicationClientMetadata>(url);
                    lastDownload  = DateTime.Now;
                }

                var context = APIUtil.ReadBody(this.Request);
                using (var vw = new VowpalWabbit(new VowpalWabbitSettings(metaData.TrainArguments)
                {
                    EnableStringExampleGeneration = true,
                    EnableStringFloatCompact = true
                }))
                    using (var serializer = new VowpalWabbitJsonSerializer(vw))
                        using (var example = serializer.ParseAndCreate(context))
                        {
                            return(Json(new { VWExample = example.VowpalWabbitString }));
                        }
            }
            catch (UnauthorizedAccessException ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, ex.Message));
            }
            catch (Exception ex)
            {
                new TelemetryClient().TrackException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Ranker(string defaultActions, string eventId)
        {
            try
            {
                APIUtil.Authenticate(this.Request);

                var client  = DecisionServiceClientFactory.AddOrGetExisting(ModelSuccessNotifier);
                var context = APIUtil.ReadBody(this.Request);
                if (string.IsNullOrEmpty(eventId))
                {
                    eventId = APIUtil.CreateEventId();
                }

                int[] actions;
                if (string.IsNullOrWhiteSpace(defaultActions))
                {
                    actions = await client.ChooseRankingAsync(eventId, context);
                }
                else
                {
                    int[] defaultActionArray = Array.ConvertAll(defaultActions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), Convert.ToInt32);
                    actions = await client.ChooseRankingAsync(eventId, context, defaultActionArray);
                }

                return(Json(new
                {
                    EventId = eventId,
                    Actions = actions,
                    ModelTime = ModelUpdateTime
                }));
            }
            catch (UnauthorizedAccessException ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, ex.Message));
            }
            catch (Exception ex)
            {
                new TelemetryClient().TrackException(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }