Пример #1
0
        private List <MajorLocationJerk> GetHighestJerks(LocationJerkModel locationJerk)
        {
            List <MajorLocationJerk> allJerks = new List <MajorLocationJerk>();

            if (locationJerk != null && locationJerk.DeviceList != null)
            {
                foreach (DeviceJerkModel deviceJerk in locationJerk.DeviceList)
                {
                    //for verticals
                    allJerks.AddRange(deviceJerk.CapturedJerks.OrderByDescending(x => Math.Abs(x.VerticalJerk))
                                      .Select(o => new MajorLocationJerk()
                    {
                        DeviceId  = deviceJerk.DeviceId,
                        JerkValue = o.VerticalJerk,
                        JerkType  = "V",
                        JerkTime  = o.JerkTimeStamp
                    }).Take(3).ToList());

                    //for laterals
                    allJerks.AddRange(deviceJerk.CapturedJerks.OrderByDescending(x => Math.Abs(x.LateralJerk))
                                      .Select(o => new MajorLocationJerk()
                    {
                        DeviceId  = deviceJerk.DeviceId,
                        JerkValue = o.LateralJerk,
                        JerkType  = "L",
                        JerkTime  = o.JerkTimeStamp
                    }).Take(3).ToList());
                }
            }

            return(allJerks.OrderByDescending(x => Math.Abs(x.JerkValue)).Take(3).ToList());
        }
Пример #2
0
        public async Task DeleteLocationsInBatchAsync(IEnumerable <LocationModel> locations)
        {
            if (locations != null)
            {
                LocationJerkBlobResults existingBlobResults = await GetAllLocationJerkInfo();

                List <LocationJerkModel> existingLocationJerks = existingBlobResults.LocationJerkInfo;
                LocationJerkModel        found = null;

                foreach (var location in locations)
                {
                    found = (existingLocationJerks as IEnumerable <LocationJerkModel>).FirstOrDefault(j => j.Latitude == location.Latitude && j.Longitude == location.Longitude);

                    if (found != null)
                    {
                        existingLocationJerks.Remove(found);
                    }

                    found = null;
                }

                string newJsonData = JsonConvert.SerializeObject(existingLocationJerks);
                byte[] newBytes    = Encoding.UTF8.GetBytes(newJsonData);

                await _blobStorageManager.UploadFromByteArrayAsync(
                    _blobName,
                    newBytes,
                    0,
                    newBytes.Length,
                    AccessCondition.GenerateIfMatchCondition(existingBlobResults.ETag),
                    null,
                    null);
            }
        }
Пример #3
0
        private double GetMaximumJerkAtLocation(LocationJerkModel locationJerk)
        {
            double maxVertical = 0;
            double maxLateral  = 0;

            if (locationJerk != null && locationJerk.DeviceList != null)
            {
                foreach (DeviceJerkModel deviceJerk in locationJerk.DeviceList)
                {
                    foreach (JerkModel jerk in deviceJerk.CapturedJerks)
                    {
                        if (Math.Abs(jerk.VerticalJerk) > Math.Abs(maxVertical))
                        {
                            maxVertical = jerk.VerticalJerk;
                        }

                        if (Math.Abs(jerk.LateralJerk) > Math.Abs(maxLateral))
                        {
                            maxLateral = jerk.LateralJerk;
                        }
                    }
                }

                if (Math.Abs(maxVertical) > Math.Abs(maxLateral))
                {
                    return(maxVertical);
                }
            }

            return(maxLateral);
        }
Пример #4
0
        public async Task <LocationJerkModelExtended> GetLocationDetails(double?latitude, double?longitude)
        {
            IEnumerable <LocationJerkModel> fetchedData = await _locationJerkRepository.LoadLatestLocationJerkInfoAsync();

            if (latitude == null || longitude == null)
            {
                return(null);
            }

            if (fetchedData != null)
            {
                LocationJerkModel queriedData = fetchedData.FirstOrDefault(loc => loc.Latitude == latitude && loc.Longitude == longitude);

                if (queriedData != null)
                {
                    LocationJerkModelExtended location = new LocationJerkModelExtended
                    {
                        Latitude    = queriedData.Latitude,
                        Longitude   = queriedData.Longitude,
                        Status      = queriedData.Status,
                        Altitude    = queriedData.Altitude,
                        DeviceList  = queriedData.DeviceList,
                        NoOfDevices = queriedData.DeviceList.Count
                    };

                    return(location);
                }
            }

            return(null);
        }
Пример #5
0
        private void UpdateLocationJerkList(LocationJerkModel newLocationJerk, ref List <LocationJerkModel> newLocationJerkList)
        {
            if (newLocationJerk != null)
            {
                LocationJerkModel found = newLocationJerkList.FirstOrDefault(l => l.Latitude == newLocationJerk.Latitude && l.Longitude == newLocationJerk.Longitude);

                if (found == null)
                {
                    newLocationJerkList.Add(newLocationJerk);
                }
                else
                {
                    foreach (DeviceJerkModel deviceJerk in newLocationJerk.DeviceList)
                    {
                        DeviceJerkModel existingDeviceJerk = found.DeviceList.FirstOrDefault(d => d.DeviceId == deviceJerk.DeviceId);

                        if (existingDeviceJerk == null)
                        {
                            found.DeviceList.Add(deviceJerk);
                        }
                        else
                        {
                            existingDeviceJerk.CapturedJerks.AddRange(deviceJerk.CapturedJerks);
                        }
                    }
                }
            }
        }
Пример #6
0
        private LocationJerkModel GetLocationJerkFromTelemetry(TelemetryJerkModel eventData)
        {
            LocationJerkModel newLocationJerkModel = null;

            if (eventData == null)
            {
                Trace.TraceWarning("Action event is null");
                return(newLocationJerkModel);
            }

            try
            {
                // NOTE: all column names from ASA come out as lowercase; see
                // https://social.msdn.microsoft.com/Forums/office/en-US/c79a662b-5db1-4775-ba1a-23df1310091d/azure-table-storage-account-output-property-names-are-lowercase?forum=AzureStreamAnalytics

                newLocationJerkModel = new LocationJerkModel()
                {
                    Latitude   = eventData.Latitude,
                    Longitude  = eventData.Longitude,
                    Altitude   = eventData.Altitude,
                    Status     = LocationStatus.Caution,
                    DeviceList = null
                };

                string deviceId = eventData.DeviceId;

                if (deviceId != null)
                {
                    newLocationJerkModel.DeviceList = new List <DeviceJerkModel>()
                    {
                        new DeviceJerkModel()
                        {
                            DeviceId      = deviceId,
                            Speed         = eventData.Speed,
                            Heading       = eventData.Heading,
                            CapturedJerks = eventData.Jerks
                        }
                    };
                }
                else
                {
                    Trace.TraceError("ActionProcessor: telemetryDeviceId value is empty");
                }

                if (eventData.Speed > 5)
                {
                    newLocationJerkModel.Status = GetLocationStatus(eventData);
                }
            }
            catch (Exception e)
            {
                Trace.TraceError("ActionProcessor: exception in ProcessTelemetryJerk:");
                Trace.TraceError(e.ToString());
            }

            return(newLocationJerkModel);
        }
Пример #7
0
        public async Task DeleteLocationJerkAsync(double?latitude, double?longitude)
        {
            LocationJerkBlobResults existingBlobResults = await GetAllLocationJerkInfo();

            List <LocationJerkModel> existingLocationJerks = existingBlobResults.LocationJerkInfo;


            if (latitude == null)
            {
                throw new Exception("No Latitude Found in LocationJerkModel-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
            }

            if (longitude == null)
            {
                throw new Exception("No Longitude Found in LocationJerkModel-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
            }

            if (latitude != null && longitude != null)
            {
                LocationJerkModel found = (existingLocationJerks as IEnumerable <LocationJerkModel>).FirstOrDefault(j => j.Latitude == latitude && j.Longitude == longitude);

                if (found != null)
                {
                    existingLocationJerks.Remove(found);
                }
            }

            string newJsonData = JsonConvert.SerializeObject(existingLocationJerks);

            byte[] newBytes = Encoding.UTF8.GetBytes(newJsonData);

            await _blobStorageManager.UploadFromByteArrayAsync(
                _blobName,
                newBytes,
                0,
                newBytes.Length,
                AccessCondition.GenerateIfMatchCondition(existingBlobResults.ETag),
                null,
                null);
        }
Пример #8
0
        public async Task SaveLocationJerkInfoAsync(List <LocationJerkModel> newLocationJerks)
        {
            LocationJerkBlobResults existingBlobResults = await GetAllLocationJerkInfo();

            List <LocationJerkModel> existingLocationJerks = existingBlobResults.LocationJerkInfo;

            foreach (LocationJerkModel newJerkModel in newLocationJerks)
            {
                if (newJerkModel.Latitude == null)
                {
                    throw new Exception("No Latitude Found in LocationJerkModel-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                }

                if (newJerkModel.Longitude == null)
                {
                    throw new Exception("No Longitude Found in LocationJerkModel-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                }

                if (newJerkModel.DeviceList == null)
                {
                    throw new Exception("No DeviceList Found in LocationJerkModel-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                }

                if (newJerkModel.Latitude != null && newJerkModel.Longitude != null)
                {
                    LocationJerkModel found = (existingLocationJerks as IEnumerable <LocationJerkModel>).FirstOrDefault(j => j.Latitude == newJerkModel.Latitude && j.Longitude == newJerkModel.Longitude);

                    if (found == null)
                    {
                        if (newJerkModel.DeviceList != null)
                        {
                            foreach (DeviceJerkModel jerkDevice in newJerkModel.DeviceList)
                            {
                                if (jerkDevice.DeviceId == String.Empty || String.IsNullOrWhiteSpace(jerkDevice.DeviceId))
                                {
                                    throw new Exception("No DeviceID Found in Jerked Device-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                                }

                                if (jerkDevice.CapturedJerks == null || jerkDevice.DeviceId == String.Empty || String.IsNullOrWhiteSpace(jerkDevice.DeviceId))
                                {
                                    newJerkModel.DeviceList.Remove(jerkDevice);
                                }
                            }

                            if (newJerkModel.DeviceList != null && newJerkModel.DeviceList.Count() > 0)
                            {
                                existingLocationJerks.Add(newJerkModel);
                            }
                        }
                    }
                    else
                    {
                        List <DeviceJerkModel> newDevices = newJerkModel.DeviceList;
                        foreach (DeviceJerkModel jerkDevice in newDevices)
                        {
                            if (jerkDevice.DeviceId == String.Empty || String.IsNullOrWhiteSpace(jerkDevice.DeviceId))
                            {
                                throw new Exception("No DeviceID Found in Jerked Device-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                            }

                            if (jerkDevice.DeviceId != String.Empty || !String.IsNullOrWhiteSpace(jerkDevice.DeviceId))
                            {
                                DeviceJerkModel deviceFound = (found.DeviceList as IEnumerable <DeviceJerkModel>).FirstOrDefault(d => d.DeviceId == jerkDevice.DeviceId);

                                if (jerkDevice.CapturedJerks != null)
                                {
                                    if (deviceFound == null)
                                    {
                                        found.DeviceList.Add(jerkDevice);
                                    }
                                    else
                                    {
                                        deviceFound.CapturedJerks.AddRange(jerkDevice.CapturedJerks);
                                    }
                                }
                            }
                        }
                    }

                    //add code here for setting status of Location
                }
            }

            string newJsonData = JsonConvert.SerializeObject(existingLocationJerks);

            byte[] newBytes = Encoding.UTF8.GetBytes(newJsonData);

            await _blobStorageManager.UploadFromByteArrayAsync(
                _blobName,
                newBytes,
                0,
                newBytes.Length,
                AccessCondition.GenerateIfMatchCondition(existingBlobResults.ETag),
                null,
                null);
        }