Example #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()));
            }
        }
Example #2
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()));
            }
        }
Example #3
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()));
            }
        }
Example #4
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()));
            }
        }