示例#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);

			var model = new WeatherLocatioinModel
			{
				LocationId = location.Id,
				LocationName = location.DisplayName,
				Now = CreateModel(current),
				Today = day.Select(CreateModel).ToArray(),
				Forecast = forecast.Select(CreateDailyModel).ToArray()
			};

			return model;
		}
示例#2
0
		private static void UpdateWeatherDataItem(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;
			}
		}
示例#3
0
		private static WeatherData GetWeatherDataItem(long seconds, ISession session, Location location)
		{
			var date = DateTimeFromUnixTimestampSeconds(seconds);

			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;
		}
示例#4
0
		private static WeatherDataModel CreateModel(WeatherData obj)
		{
			return obj == null 
				? null
				: new WeatherDataModel
						{
							DateTime = obj.Date,
							Code = obj.WeatherCode,
							Description = obj.WeatherDescription,
							Temperature = Convert.ToInt32(obj.Temperature),
							Pressure = Convert.ToInt32(obj.Pressure),
							Humidity = obj.Humidity, 
						};
		}
示例#5
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);
		}