Пример #1
0
        private static bool ProcessAlert(string propertyNumber, string imageUrl, string predictionAsJson, int alertStatusId)
        {
            var result     = false;
            var connString = ConfigurationManager.AppSettings["OverwatchConnectionString"];

            using (var context = new OverwatchEntities(connString))
            {
                var property = context.Properties.Where(x => x.propertyNumber == propertyNumber).FirstOrDefault();
                if (property != null)
                {
                    PropertyAlert propertyAlert = new PropertyAlert()
                    {
                        imageUrl              = imageUrl,
                        createTimestamp       = DateTime.Now,
                        propertyAlertStatusId = alertStatusId,
                        propertyId            = property.id,
                        predictionJson        = predictionAsJson
                    };

                    context.PropertyAlerts.Add(propertyAlert);
                    context.SaveChanges();
                    result = true;
                }
            }
            return(result);
        }
Пример #2
0
        public static void Run([BlobTrigger("trucks/{name}", Connection = "blobConnection")] Stream myBlob, string name, TraceWriter log)
        {
            Guid projectId        = Guid.Parse("61f0cc4c-fb4f-4d62-95e1-2b2c631ae9b8");
            var  imageUrl         = $"https://hpkimagestorage.blob.core.windows.net/trucks/{name}";
            var  propertyNumber   = name.Substring(0, name.IndexOf("/"));
            var  imagePredictions = ProcessImagePredictions(imageUrl, projectId);

            if (imagePredictions != null)
            {
                List <PropertyAlertStatu> alertStatuses = new List <PropertyAlertStatu>();

                var connString = ConfigurationManager.AppSettings["OverwatchConnectionString"];
                using (var context = new OverwatchEntities(connString))
                {
                    alertStatuses = context.PropertyAlertStatus.ToList();
                }
                string predictionAsJson = JsonConvert.SerializeObject(imagePredictions.Predictions);
                //check for type of alert
                //this is just getting the first tag that is over 90% but you would want to do more here.
                var tagInAlert    = imagePredictions.Predictions.Where(x => x.Probability > .9).FirstOrDefault();
                var alertStatusId = 1;
                switch (tagInAlert.Tag)
                {
                case "pickups":
                    alertStatusId = alertStatuses.First(x => x.propertyAlertStatus == "Unrecognized pickup").id;
                    break;

                case "trucks":
                    alertStatusId = alertStatuses.First(x => x.propertyAlertStatus == "Unrecognized semi").id;
                    break;

                case "logos":
                    Guid chkProjectId = Guid.Parse("72550364-3d7a-46b7-a191-8369ae2749ba");
                    var  logoResult   = ProcessImagePredictions(imageUrl, chkProjectId);
                    if (logoResult != null)
                    {
                        alertStatusId = alertStatuses.First(x => x.propertyAlertStatus == "Recognized vehicle (Chesapeake)").id;
                    }
                    else
                    {
                        alertStatusId = alertStatuses.First(x => x.propertyAlertStatus == "Unmarked vehicle").id;
                    }
                    break;

                default:
                    alertStatusId = alertStatuses.First(x => x.propertyAlertStatus == "Unmarked vehicle").id;
                    break;
                }

                var result = ProcessAlert(propertyNumber, imageUrl, predictionAsJson, alertStatusId);
            }
        }
Пример #3
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            var connString = ConfigurationManager.AppSettings["OverwatchConnectionString"];
            KeyValuePair <string, string> propertyId = req.GetQueryNameValuePairs().FirstOrDefault(q => string.Compare(q.Key, "propertyId", true) == 0);

            using (var context = new OverwatchEntities(connString))
            {
                var query = context.Properties.Select(n => new
                {
                    id                     = n.id,
                    propertyNumber         = n.propertyNumber,
                    propertyName           = n.propertyName,
                    sourceName             = n.sourceName,
                    latitude               = n.latitude,
                    longitude              = n.longitude,
                    approximateNumOfPeople = n.approximateNumOfPeople,
                    propertyStatus         = n.PropertyStatus.propertyStatus,
                    latestPropertyAlert    = (n.PropertyAlerts.OrderByDescending(x => x.createTimestamp).FirstOrDefault() == null) ? null : new
                    {
                        propertyAlert  = n.PropertyAlerts.OrderByDescending(x => x.createTimestamp).FirstOrDefault().PropertyAlertStatus.propertyAlertStatus,
                        timestamp      = n.PropertyAlerts.OrderByDescending(x => x.createTimestamp).FirstOrDefault().createTimestamp,
                        imageUrl       = n.PropertyAlerts.OrderByDescending(x => x.createTimestamp).FirstOrDefault().imageUrl,
                        severity       = n.PropertyAlerts.OrderByDescending(x => x.createTimestamp).FirstOrDefault().PropertyAlertStatus.Severity.severity1,
                        predictionJson = n.PropertyAlerts.OrderByDescending(x => x.createTimestamp).FirstOrDefault().predictionJson
                    },
                    latestFivePropertyAlerts = (n.PropertyAlerts.OrderByDescending(x => x.createTimestamp).Skip(1).Take(5).Select(x => new
                    {
                        propertyAlert = x.PropertyAlertStatus.propertyAlertStatus,
                        timestamp = x.createTimestamp,
                        imageUrl = x.imageUrl,
                        severity = x.PropertyAlertStatus.Severity.severity1,
                        predictionJson = x.predictionJson
                    }))
                });

                if (propertyId.Value == null)
                {
                    return(req.CreateResponse(query.OrderByDescending(x => x.latestPropertyAlert.timestamp).ToList()));
                }
                else
                {
                    int castedId = Convert.ToInt32(propertyId.Value);
                    return(req.CreateResponse(query.Where(x => castedId == x.id).FirstOrDefault()));
                }
            }
        }