internal static string GetRainForecast(WeatherModel model) { var currentWeather = model.HourlyForecast.FirstOrDefault(); if (currentWeather == null) { return String.Empty; } var futureWeather = model.HourlyForecast.Skip(1); var rainsNow = currentWeather.Rainfall > 0; if (rainsNow) { var firstSunnyWeather = futureWeather.FirstOrDefault(w => w.Rainfall == 0); // later, change First to FirstAndDefault and add this line: if (firstSunnyWeather == null) return String.Empty; return $"Rain ends at {firstSunnyWeather.Time.ToString("h tt").ToLower()}"; } else { var firstRainyWeather = futureWeather.FirstOrDefault(w => w.Rainfall > 0); // later, change First to FirstAndDefault and add this line: if (firstRainyWeather == null) return String.Empty; return $"Rain starts at {firstRainyWeather.Time.ToString("h tt").ToLower()}"; } }
internal static string GetRainForecast(WeatherModel model) { var currentWeather = model.HourlyForecast.FirstOrDefault(); if (currentWeather == null) { return(String.Empty); } var futureWeather = model.HourlyForecast.Skip(1); var rainsNow = currentWeather.Rainfall > 0; if (rainsNow) { var firstSunnyWeather = futureWeather.FirstOrDefault(w => w.Rainfall == 0); // later, change First to FirstAndDefault and add this line: if (firstSunnyWeather == null) { return(String.Empty); } return($"Rain ends at {firstSunnyWeather.Time.ToString("h tt").ToLower()}"); } else { var firstRainyWeather = futureWeather.FirstOrDefault(w => w.Rainfall > 0); // later, change First to FirstAndDefault and add this line: if (firstRainyWeather == null) { return(String.Empty); } return($"Rain starts at {firstRainyWeather.Time.ToString("h tt").ToLower()}"); } }
internal void Initialize(WeatherModel model) { this.model = model; updateTimestamp(); updateCurrentAndHourlyForecast(); updateAstronomy(); model.PropertyChanged += ModelPropertyChanged; }
internal void Initialize(WeatherModel model) { this.model = model; model.PropertyChanged += ModelPropertyChanged; if (model.Ready) { updateDailyForecast(); updateCurrentWeather(); updateTimestamp(); } }
internal static List<DailyForecastViewModel> GetDailyForecast(WeatherModel model) { var dailyForecast = new List<DailyForecastViewModel>(); foreach (var forecast in model.DailyForecast) { dailyForecast.Add(new DailyForecastViewModel() { Conditions = forecast.Conditions, Date = forecast.Time.ToString("dddd d"), TemperatureHigh = forecast.TemperatureHigh.Value, TemperatureLow = forecast.TemperatureLow.Value }); } return dailyForecast; }
internal static List<HourlyForecastViewModel> GetHourlyForecast(WeatherModel model) { var hourlyForecast = new List<HourlyForecastViewModel>(); foreach (var forecast in model.HourlyForecast.Skip(1)) // the first entry is current weather { hourlyForecast.Add(new HourlyForecastViewModel() { Conditions = forecast.Conditions, Time = Int32.Parse(forecast.Time.ToString("hh")), Temperature = forecast.Temperature.Value, Rainfall = forecast.Rainfall.Value, Snowfall = forecast.Snowfall.Value, }); } return hourlyForecast; }
internal static List <DailyForecastViewModel> GetDailyForecast(WeatherModel model) { var dailyForecast = new List <DailyForecastViewModel>(); foreach (var forecast in model.DailyForecast.Take(6)) { dailyForecast.Add(new DailyForecastViewModel() { Conditions = forecast.Conditions, Date = forecast.Time.ToString("%d"), DayOfWeek = forecast.Time.ToString("dddd"), TemperatureHigh = forecast.TemperatureHigh.Value, TemperatureLow = forecast.TemperatureLow.Value }); } return(dailyForecast); }
internal static HourlyForecastViewModel GetCurrentWeather(WeatherModel model) { var currentWeather = model.HourlyForecast.FirstOrDefault(); if (currentWeather == null) { return null; } var hourlyForecast = new HourlyForecastViewModel() { Conditions = currentWeather.Conditions, Time = Int32.Parse(currentWeather.Time.ToString("hh")), Temperature = currentWeather.Temperature.Value, Rainfall = currentWeather.Rainfall.Value, Snowfall = currentWeather.Snowfall.Value, }; return hourlyForecast; }
internal static List <HourlyForecastViewModel> GetHourlyForecast(WeatherModel model) { var hourlyForecast = new List <HourlyForecastViewModel>(); foreach (var forecast in model.HourlyForecast.Skip(1).Where((t, i) => i % 2 == 0)) // the first entry is current weather. Get only every other hour { hourlyForecast.Add(new HourlyForecastViewModel() { Conditions = forecast.Conditions, Time = Int32.Parse(forecast.Time.ToString("hh")), AmPm = forecast.Time.ToString("tt").ToLower(), Temperature = forecast.Temperature.Value, Rainfall = forecast.Rainfall.Value, Snowfall = forecast.Snowfall.Value, }); } return(hourlyForecast); }
internal static HourlyForecastViewModel GetCurrentWeather(WeatherModel model) { var currentWeather = model.HourlyForecast.FirstOrDefault(); if (currentWeather == null) { return(null); } var hourlyForecast = new HourlyForecastViewModel() { Conditions = currentWeather.Conditions, Time = Int32.Parse(currentWeather.Time.ToString("hh")), AmPm = currentWeather.Time.ToString("tt").ToLower(), Temperature = currentWeather.Temperature.Value, Rainfall = currentWeather.Rainfall.Value, Snowfall = currentWeather.Snowfall.Value, }; return(hourlyForecast); }
internal void Initialize(WeatherModel model) { this.model = model; updateTimestamp(); updateDailyForecast(); updateCurrentWeather(); model.PropertyChanged += ModelPropertyChanged; }