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; }
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); }
private object BuildLocationModel(WeatherLocatioinModel data) { return new { id = data.LocationId, name = data.LocationName, now = BuildModel(data.Now), day = data.Today.Select(BuildModel).ToArray(), forecast = data.Forecast.Select(BuildModel).ToArray() }; }