Exemplo n.º 1
0
        public static WeatherLocatioinModel LoadLocationWeatherData(DateTime now, Location location, WeatherData[] locationData)
        {
            var minDate = now.AddMinutes(-90);
            var maxDate = now.AddMinutes(90);

            // погода на текущее время
            var current = locationData.FirstOrDefault(d => d.Date > minDate && d.Date <= maxDate);

            // погода на ближайшие сутки
            var xxx = current != null ? current.Date : now;
            var day = locationData
                        .Where(d => d.Date > xxx && d.Date <= xxx.AddDays(1))
                        .Where(FilterByHours)
                        .OrderBy(d => d.Date)
                        .Take(3)
                        .ToArray();

            // прогноз на несколько дней
            var forecast = locationData
                        .Where(d => d.Date.Date > now.Date)
                        .GroupBy(d => d.Date.Date)
                        .Take(3);

            return new WeatherLocatioinModel
            {
                LocationId = location.Id,
                LocationName = location.DisplayName,
                Now = CreateNowModel(current),
                Today = day.Select(CreateNowModel).ToArray(),
                Forecast = forecast.Select(CreateDayModel).ToArray()
            };
        }
Exemplo n.º 2
0
 private static WeatherNowDataModel CreateNowModel(WeatherData obj)
 {
     return obj == null
         ? null
         : new WeatherNowDataModel
         {
             DateTime = obj.Date,
             Code = obj.WeatherCode,
             Description = obj.WeatherDescription,
             Temperature = Convert.ToInt32(obj.Temperature),
             Pressure = Convert.ToInt32(obj.Pressure),
             Humidity = obj.Humidity,
         };
 }
Exemplo n.º 3
0
 private static bool FilterByHours(WeatherData data)
 {
     return data != null && (
         data.Date.Hour == 3 ||
         data.Date.Hour == 9 ||
         data.Date.Hour == 15 ||
         data.Date.Hour == 21);
 }
Exemplo n.º 4
0
        private static void PopulateWeatherDataItem(WeatherData dataItem, dynamic item)
        {
            dataItem.Temperature = item.main.temp;
            dataItem.Cloudiness = item.clouds.all;
            dataItem.Humidity = item.main.humidity;
            dataItem.Pressure = item.main.pressure;
            dataItem.WindDirection = item.wind.deg;
            dataItem.WindSpeed = item.wind.speed;

            if (item.weather != null && item.weather.First != null)
            {
                dynamic w = item.weather.First;

                dataItem.WeatherDescription = w.description;
                dataItem.WeatherCode = w.icon;
            }
            else
                dataItem.WeatherCode = dataItem.WeatherDescription = null;
        }
Exemplo n.º 5
0
        private static WeatherData GetWeatherDataItem(Location location, DateTime date, ISession session)
        {
            var dataItem = session.Query<WeatherData>().FirstOrDefault(obj => obj.Date == date && obj.Location.Id == location.Id);
            if (dataItem == null)
            {
                dataItem = new WeatherData { Id = Guid.NewGuid(), Date = date, Location = location };
                session.Save(dataItem);
            }

            return dataItem;
        }