Exemple #1
0
        internal static List <DeviceProjection> ConvertSensorsNearbyResponseToDeviceProjections(SensorsNearbyResponse response)
        {
            var result = new List <DeviceProjection>();

            foreach (var device in response.Devices)
            {
                var projection = new DeviceProjection
                {
                    Id        = device.Id,
                    Name      = device.Name,
                    Location  = device.Location,
                    Distance  = device.Distance,
                    Latitude  = device.Lat,
                    Longitude = device.Lng,
                    Sensors   =
                        device.Sensors.Select(
                            sensor =>
                            new SensorProjection
                    {
                        Id    = sensor.Id,
                        Type  = sensor.Type,
                        Name  = sensor.Name,
                        Value = sensor.Value,
                        Unit  = sensor.Unit,
                        Time  = ModelExtensions.UnixTimeStampToDateTime(sensor.Time, true),
#if DEBUG
                        IsPinned = new Random().Next() % 2 == 1
#endif
                    }).ToList()
                };
                result.Add(projection);
            }
            return(result);
        }
Exemple #2
0
        internal static List <WeatherForecastProjection> ConvertToWeatherForecastProjections(Rp5WeatherForecastRootObject deserializeObject)
        {
            var result = new List <WeatherForecastProjection>();

            foreach (var forecastItems in deserializeObject.Response.Forecast.Items)
            {
                foreach (var forecastItem in forecastItems)
                {
                    result.Add(new WeatherForecastProjection
                    {
                        ForecastDateTime = ModelExtensions.UnixTimeStampToDateTime(forecastItem.Gmt, false),
                        Temperature      = new TemperatureProjection {
                            Celsius = forecastItem.Temperature.C, Fahrenheit = forecastItem.Temperature.F
                        },
                        FeelTemperature = new TemperatureProjection {
                            Celsius = forecastItem.FeelTemperature.C, Fahrenheit = forecastItem.FeelTemperature.F
                        },
                        Cloudiness =
                            new CloudinessProjection
                        {
                            Percents = forecastItem.CloudCover.Pct,
                            Decimal  = forecastItem.CloudCover.Decimal,
                            Oktas    = forecastItem.CloudCover.Oktas
                        },
                        WindSpeed =
                            new WindProjection
                        {
                            Ms    = forecastItem.WindVelocity.Ms,
                            Kmh   = forecastItem.WindVelocity.Kmh,
                            Mph   = forecastItem.WindVelocity.Mph,
                            Knots = forecastItem.WindVelocity.Knots,
                            Bft   = forecastItem.WindVelocity.Bft
                        },
                        WindGusts =
                            new WindProjection
                        {
                            Ms    = forecastItem.WindGusts.Ms,
                            Kmh   = forecastItem.WindGusts.Kmh,
                            Mph   = forecastItem.WindGusts.Mph,
                            Knots = forecastItem.WindGusts.Knots,
                            Bft   = forecastItem.WindGusts.Bft
                        },
                        Pressure =
                            new PressureProjection
                        {
                            Hpa  = forecastItem.Pressure.Hpa,
                            Inhg = forecastItem.Pressure.Inhg,
                            Mbar = forecastItem.Pressure.Mbar,
                            Mmhg = forecastItem.Pressure.Mmhg
                        },
                        Precipitation = new PrecipitationProjection {
                            Mm = forecastItem.Precipitation.Mm, Inches = forecastItem.Precipitation.Inches
                        },
                        PrecipitationType = (PrecipitationType)forecastItem.PrecipitationType,
                        WindDirection     = GetWindDirection(forecastItem.WindDirection),
                        Humidity          = forecastItem.Humidity,
                        Sunrise           = ModelExtensions.UnixTimeStampToDateTime(forecastItem.Sunrise, false),
                        Sunset            = ModelExtensions.UnixTimeStampToDateTime(forecastItem.Sunset, false)
                    });
                }
            }
            return(result);
        }