/// <summary>
        /// Get the list of devices in a specific radius
        /// </summary>
        /// <param name="pointLocation">Geolocation</param>
        /// <param name="radius">Radius in km</param>
        /// <param name="includeDisabled">Include devices where Enabled = false</param>
        /// <returns></returns>
        public async Task <IEnumerable <DeviceModel> > GetDevicesNearby(Geolocation pointLocation, double radius, bool includeDisabled)
        {
            IEnumerable <DeviceDAO> devices = await _repoDevices.GetItemsAsync(p => (includeDisabled || p.Enabled) && p.IoTDevice,
                                                                               p => new DeviceDAO()
            {
                Id          = p.Id,
                Geolocation = p.Geolocation
            }
                                                                               );

            List <DeviceDAO>     output = new List <DeviceDAO>();
            GeolocationDAOObject daoGeocodeCenterPoint = _mapper.Map <GeolocationDAOObject>(pointLocation);

            if (devices != null)
            {
                foreach (DeviceDAO deviceObj in devices)
                {
                    if (deviceObj.Geolocation != null)
                    {
                        if (RadiusHelper.IsWithinRadius(deviceObj.Geolocation, daoGeocodeCenterPoint, radius))
                        {
                            output.Add(deviceObj);
                        }
                    }
                }
            }
            return(_mapper.Map <IEnumerable <DeviceModel> >(output));
        }
        /// <summary>
        /// Get a list of responses that are within the radius of a point. The size of the radius is the primary radius of the action plan
        /// </summary>
        /// <param name="responseGeolocationObj">ResponseGeolocationModel</param>
        /// <returns>List of Response Model</returns>
        public async Task <IEnumerable <ResponseModel> > GetResponsesFromPointRadius(ResponseGeolocationModel responseGeolocationObj)
        {
            if (responseGeolocationObj == null || responseGeolocationObj.EventClusterGeolocationPointLocation == null)
            {
                return(new List <ResponseModel>());
            }

            IEnumerable <ResponseDAO> responseObjs = await _repoResponses.GetItemsAsync(p => p.EndDate.Value == null);

            if (responseObjs == null)
            {
                return(null);
            }

            List <ResponseDAO>   output = new List <ResponseDAO>();
            GeolocationDAOObject daoGeocodeCenterPoint = _mapper.Map <GeolocationDAOObject>(responseGeolocationObj.EventClusterGeolocationPointLocation);

            foreach (var response in responseObjs)
            {
                if (RadiusHelper.IsWithinRadius(daoGeocodeCenterPoint, response.Geolocation, response.ActionPlan.PrimaryRadius))
                {
                    output.Add(response);
                }
            }
            return(_mapper.Map <IEnumerable <ResponseModel> >(output));
        }
        /// <summary>
        /// Get the list of devices in a specific radius
        /// </summary>
        /// <param name="deviceGeolocationObj">DeviceGeolocationModel</param>
        /// <returns>List of device ids</returns>
        public async Task <IEnumerable <Guid> > GetDevicesInRadius(DeviceGeolocationModel deviceGeolocationObj)
        {
            IEnumerable <DeviceDAO> devices = await _repoDevices.GetItemsAsync(
                p => p.Enabled && ((!string.IsNullOrEmpty(deviceGeolocationObj.DeviceType) && p.DeviceType.ToLower() == deviceGeolocationObj.DeviceType.ToLower()) ||
                                   (string.IsNullOrEmpty(deviceGeolocationObj.DeviceType))),
                p => new DeviceDAO()
            {
                Id          = p.Id,
                Geolocation = p.Geolocation
            }
                );

            List <Guid>          output = new List <Guid>();
            GeolocationDAOObject daoGeocodeCenterPoint = _mapper.Map <GeolocationDAOObject>(deviceGeolocationObj.ResponseGeolocationPointLocation);

            if (devices != null)
            {
                foreach (DeviceDAO deviceObj in devices)
                {
                    if (deviceObj.Geolocation != null)
                    {
                        if (RadiusHelper.IsWithinRadius(deviceObj.Geolocation, daoGeocodeCenterPoint, deviceGeolocationObj.Radius))
                        {
                            output.Add(new Guid(deviceObj.Id));
                        }
                    }
                }
            }
            return(output);
        }
예제 #4
0
        /// <summary>
        /// Get a list of Event Clusters in a specific geolocation radius
        /// </summary>
        /// <param name="eventClusterGeolocationObj">EventClusterGeolocationModel</param>
        /// <returns>List of Event Clusters Ids</returns>
        public async Task <IEnumerable <Guid> > GetClustersInRadius(EventClusterGeolocationModel eventClusterGeolocationObj)
        {
            if (eventClusterGeolocationObj == null || eventClusterGeolocationObj.ResponseGeolocationPointLocation == null)
            {
                return(new List <Guid>());
            }

            IEnumerable <EventClusterDAO> eventClusters = await _repoEventClusters.GetItemsAsync(
                p => p.ClosureDate.Value == null,
                p => new EventClusterDAO()
            {
                Id        = p.Id,
                EventType = p.EventType,
                Device    = new EventClusterDeviceDAOObject()
                {
                    Geolocation = p.Device.Geolocation
                }
            }
                );

            List <Guid>          output = new List <Guid>();
            GeolocationDAOObject daoGeocodeCenterPoint = _mapper.Map <GeolocationDAOObject>(eventClusterGeolocationObj.ResponseGeolocationPointLocation);

            foreach (EventClusterDAO eventClusterObj in eventClusters)
            {
                if (RadiusHelper.IsWithinRadius(eventClusterObj.Device.Geolocation, daoGeocodeCenterPoint, eventClusterGeolocationObj.Radius))
                {
                    output.Add(new Guid(eventClusterObj.Id));
                }
            }
            return(output);
        }
        /// <summary>
        /// Determine if a device location is within the radius of a epicente
        /// </summary>
        /// <param name="userId">User Id</param>
        /// <param name="geolocationPoint">Geolocation of the geolocationPoint</param>
        /// <param name="radius">Radius in kilometer</param>
        /// <returns>True if the device is within the radius</returns>
        public async Task <bool> IsInBoundaries(string userId, Geolocation geolocationPoint, double radius)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new Exception($"The userId was not found.");
            }

            DeviceModel device = await GetMobileDeviceFromUserId(userId);

            return(RadiusHelper.IsWithinRadius(device.Geolocation, geolocationPoint, radius));
        }