public DeviceListLocationsModel ExtractLocationsData(List <dynamic> devices)
        {
            var result = new DeviceListLocationsModel();

            // Initialize defaults to opposite extremes to ensure mins and maxes are beyond any actual values
            double minLat  = double.MaxValue;
            double maxLat  = double.MinValue;
            double minLong = double.MaxValue;
            double maxLong = double.MinValue;

            var locationList = new List <DeviceLocationModel>();

            foreach (dynamic device in devices)
            {
                dynamic props = DeviceSchemaHelper.GetDeviceProperties(device);
                if (props.Longitude == null || props.Latitude == null)
                {
                    continue;
                }

                double latitude;
                double longitude;

                try
                {
                    latitude  = DeviceSchemaHelper.GetDeviceProperties(device).Latitude;
                    longitude = DeviceSchemaHelper.GetDeviceProperties(device).Longitude;
                }
                catch (FormatException)
                {
                    continue;
                }

                var location = new DeviceLocationModel()
                {
                    DeviceId  = DeviceSchemaHelper.GetDeviceID(device),
                    Longitude = longitude,
                    Latitude  = latitude
                };
                locationList.Add(location);

                if (longitude < minLong)
                {
                    minLong = longitude;
                }
                if (longitude > maxLong)
                {
                    maxLong = longitude;
                }
                if (latitude < minLat)
                {
                    minLat = latitude;
                }
                if (latitude > maxLat)
                {
                    maxLat = latitude;
                }
            }

            if (locationList.Count == 0)
            {
                // reinitialize bounds to center on Seattle area if no devices
                minLat  = 47.6;
                maxLat  = 47.6;
                minLong = -122.3;
                maxLong = -122.3;
            }

            double offset = 0.05;

            result.DeviceLocationList = locationList;
            result.MinimumLatitude    = minLat - offset;
            result.MaximumLatitude    = maxLat + offset;
            result.MinimumLongitude   = minLong - offset;
            result.MaximumLongitude   = maxLong + offset;

            return(result);
        }
        public DeviceListLocationsModel ExtractLocationsData(List <DeviceModel> devices)
        {
            var result = new DeviceListLocationsModel();

            // Initialize defaults to opposite extremes to ensure mins and maxes are beyond any actual values
            double minLat  = double.MaxValue;
            double maxLat  = double.MinValue;
            double minLong = double.MaxValue;
            double maxLong = double.MinValue;

            var locationList = new List <DeviceLocationModel>();

            if (devices != null && devices.Count > 0)
            {
                foreach (DeviceModel device in devices)
                {
                    if (device.DeviceProperties == null)
                    {
                        throw new DeviceRequiredPropertyNotFoundException("Required DeviceProperties not found");
                    }

                    if (device.DeviceProperties.Longitude == null || device.DeviceProperties.Latitude == null)
                    {
                        continue;
                    }

                    double latitude;
                    double longitude;

                    try
                    {
                        latitude  = device.DeviceProperties.Latitude.Value;
                        longitude = device.DeviceProperties.Longitude.Value;
                    }
                    catch (FormatException)
                    {
                        continue;
                    }

                    var location = new DeviceLocationModel()
                    {
                        DeviceId  = device.DeviceProperties.DeviceID,
                        Longitude = longitude,
                        Latitude  = latitude
                    };
                    locationList.Add(location);

                    if (longitude < minLong)
                    {
                        minLong = longitude;
                    }
                    if (longitude > maxLong)
                    {
                        maxLong = longitude;
                    }
                    if (latitude < minLat)
                    {
                        minLat = latitude;
                    }
                    if (latitude > maxLat)
                    {
                        maxLat = latitude;
                    }
                }
            }
            if (locationList.Count == 0)
            {
                // reinitialize bounds to center on Seattle area if no devices
                minLat  = 47.6;
                maxLat  = 47.6;
                minLong = -122.3;
                maxLong = -122.3;
            }

            double offset = 0.05;

            result.DeviceLocationList = locationList;
            result.MinimumLatitude    = minLat - offset;
            result.MaximumLatitude    = maxLat + offset;
            result.MinimumLongitude   = minLong - offset;
            result.MaximumLongitude   = maxLong + offset;

            return(result);
        }
Пример #3
0
        public DeviceListLocationsModel ExtractLocationsData(List <dynamic> devices)
        {
            var result = new DeviceListLocationsModel();

            //Initialize defaults around Seattle
            double minLat  = 47.6;
            double maxLat  = 47.6;
            double minLong = -122.3;
            double maxLong = -122.3;

            var locationList = new List <DeviceLocationModel>();

            foreach (dynamic device in devices)
            {
                dynamic props = DeviceSchemaHelper.GetDeviceProperties(device);
                if (props.Longitude == null || props.Latitude == null)
                {
                    continue;
                }

                double latitude;
                double longitude;

                try
                {
                    latitude  = DeviceSchemaHelper.GetDeviceProperties(device).Latitude;
                    longitude = DeviceSchemaHelper.GetDeviceProperties(device).Longitude;
                }
                catch (FormatException)
                {
                    continue;
                }

                var location = new DeviceLocationModel()
                {
                    DeviceId  = DeviceSchemaHelper.GetDeviceID(device),
                    Longitude = longitude,
                    Latitude  = latitude
                };
                locationList.Add(location);

                if (longitude < minLong)
                {
                    minLong = longitude;
                }
                if (longitude > maxLong)
                {
                    maxLong = longitude;
                }
                if (latitude < minLat)
                {
                    minLat = latitude;
                }
                if (latitude > maxLat)
                {
                    maxLat = latitude;
                }
            }

            var offset = 0.05;

            result.DeviceLocationList = locationList;
            result.MinimumLatitude    = minLat - offset;
            result.MaximumLatitude    = maxLat + offset;
            result.MinimumLongitude   = minLong - offset;
            result.MaximumLongitude   = maxLong + offset;

            return(result);
        }