private void update_Humidity(IWeatherProvider provider, WeatherPeriod period) { double hum; if (provider.get_humidity(period, out hum)) { Humidity = hum; Weather_Status_Humidity = true; } else { Weather_Status_Humidity = false; } }
public virtual bool get_character(WeatherPeriod period, out WeatherType type) { lock (_locker) { if (_weather.ContainsKey(period) && _weather[period].WeatherType != WeatherType.Undefined) { type = _weather[period].WeatherType; return(true); } type = WeatherType.Undefined; return(false); } }
private void update_Pressure(IWeatherProvider provider, WeatherPeriod period) { double press; if (provider.get_pressure(period, out press)) { Pressure = press; Weather_Status_Pressure = true; } else { Weather_Status_Pressure = false; } }
public virtual bool get_humidity(WeatherPeriod period, out double hum) { lock (_locker) { if (_weather.ContainsKey(period) && _weather[period].Humidity != null) { hum = (double)_weather[period].Humidity; return(true); } hum = 0.0; return(false); } }
public virtual bool get_pressure(WeatherPeriod period, out double pressure) { lock (_locker) { if (_weather.ContainsKey(period) && _weather[period].Pressure != null) { pressure = (double)_weather[period].Pressure; return(true); } pressure = 0.0; return(false); } }
public void GetDurationOfPeriodTest() { var periodDays = new List <MeteorologicalDay>() { new MeteorologicalDay(1, new Drought(), null), new MeteorologicalDay(2, new Drought(), null), new MeteorologicalDay(3, new Drought(), null), new MeteorologicalDay(4, new Drought(), null), new MeteorologicalDay(5, new Drought(), null), }; var period = new WeatherPeriod(new Drought(), periodDays); Assert.That(period.GetDuration(), Is.EqualTo(5)); }
public virtual bool get_temperature(WeatherPeriod period, out double temp_l, out double temp_h) { lock (_locker) { if (_weather.ContainsKey(period) && _weather[period].TemperatureLow != null) { temp_l = (double)_weather[period].TemperatureLow; temp_h = (double)(_weather[period].TemperatureHigh ?? _weather[period].TemperatureLow); return(true); } temp_l = temp_h = 0.0; return(false); } }
private void update_Wind(IWeatherProvider provider, WeatherPeriod period) { double ws; WindDirection wd; if (provider.get_wind(period, out wd, out ws)) { WindDirection = wd; WindSpeed = ws; Weather_Status_Wind = true; } else { Weather_Status_Wind = false; } }
private void update_Temperature(IWeatherProvider provider, WeatherPeriod period) { double temp_l, temp_h; if (provider.get_temperature(period, out temp_l, out temp_h)) { Temperature = ((temp_l + temp_h) / 2.0).ToString(); TemperatureRange = temp_l + "|" + temp_h; Weather_Status_Temperature = true; } else { Weather_Status_Temperature = false; } }
public virtual bool get_wind(WeatherPeriod period, out WindDirection direction, out double speed) { lock (_locker) { if (_weather.ContainsKey(period) && _weather[period].WindSpeed != null) { direction = _weather[period].WindDirection; speed = (double)_weather[period].WindSpeed; return(true); } direction = WindDirection.Undefined; speed = 0.0; return(false); } }
private void update_Weather(IWeatherProvider provider, WeatherPeriod period) { WeatherType w; if (period == WeatherPeriod.TomorrowNight || period == WeatherPeriod.TomorrowMorning) { int i = 0; } if (provider.get_character(period, out w)) { Weather = w; Weather_Status_Weather = true; } else { Weather_Status_Weather = false; } }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null) { return(null); } WeatherType wt = (WeatherType)values[0]; WeatherPeriod wp = (WeatherPeriod)values[1]; int n = 0; if (wp == WeatherPeriod.DayAfterTomorrowEvening || wp == WeatherPeriod.DayAfterTomorrowNight || wp == WeatherPeriod.TomorrowEvening || wp == WeatherPeriod.TomorrowNight || wp == WeatherPeriod.TodayEvening || wp == WeatherPeriod.TodayNight || (wp == WeatherPeriod.Now && (DateTime.Now.Hour >= 18 || DateTime.Now.Hour < 6))) { n = 1; } return(Application.Current.TryFindResource(weatherformatter.weather_types_to_picture[wt][n]) as Canvas); }
private bool extract_day_forecast(int day, XmlNode tr) { XmlNode tc = tr.SelectSingleNode("./td[@class='elements__section-day']"); if (tc == null) { _error_descr = "cant find day " + day.ToString(); return(false); } // check day of month XmlNodeList spans = tc.SelectNodes("./div/span"); if (spans.Count != 1) { _error_descr = "incorrect days in day" + day.ToString(); return(false); } string dt = spans[0].InnerText; int di; if (!int.TryParse(dt.Substring(0, dt.IndexOf(' ')), out di)) { di = 0; } if ((DateTime.Now + TimeSpan.FromDays(day)).Day != di) { _error_descr = "incorrect day"; return(false); } // day's periods XmlNodeList period_divs = tr.SelectCellDivs("elements__section-daytime"); // temperature XmlNodeList temperature_divs = tr.SelectCellDivs("elements__section-temperature"); if (temperature_divs.Count != period_divs.Count) { throw new Exception(string.Format("incorrect temperature count in day {0}", day)); } // weather type XmlNodeList weather_divs = tr.SelectCellDivs("elements__section-weather"); if (weather_divs.Count != period_divs.Count) { throw new Exception(string.Format("incorrect weather type count in day {0}", day)); } // wind XmlNodeList wind_divs = tr.SelectCellDivs("elements__section-wind"); if (wind_divs.Count != period_divs.Count) { throw new Exception(string.Format("incorrect wind count in day {0}", day)); } // pressure XmlNodeList pressure_divs = tr.SelectCellDivs("elements__section-pressure"); if (pressure_divs.Count != period_divs.Count) { throw new Exception(string.Format("incorrect pressure count in day {0}", day)); } // humidity XmlNodeList humidity_divs = tr.SelectCellDivs("elements__section-humidity"); if (humidity_divs.Count != period_divs.Count) { throw new Exception(string.Format("incorrect humidity count in day {0}", day)); } int pcount = period_divs.Count; for (int period = 0; period < pcount; period++) { WeatherInfo w = new WeatherInfo(); // weather period string pname = period_divs[period].InnerText; if (!_day_periods[day].Keys.Contains(pname)) { throw new Exception("invalid period name"); } WeatherPeriod wp = _day_periods[day][pname]; // temperature string temperature_s = temperature_divs[period].InnerText.Trim().Replace('−', '-'); w.TemperatureLow = w.TemperatureHigh = int.Parse(temperature_s); // weather type string cn = "icon-weather icon-weather-"; XmlNode e = weather_divs[period].SelectSingleNode("./i"); if (e == null) { throw new Exception("cant find weather type"); } string wt = e.SelectSingleNode("@class").Value.Substring(cn.Length); if (wt.IndexOf(' ') != -1) { wt = wt.Substring(0, wt.IndexOf(' ')); } w.WeatherType = weather_type_encoding.Keys.Contains(wt) ? weather_type_encoding[wt] : WeatherType.Undefined; if (w.WeatherType == WeatherType.Undefined) { int i = 0; } // wind cn = "icon-small icon-wind-"; e = wind_divs[period].SelectSingleNode("./i"); if (e == null) { throw new Exception("cant find wind direction"); } string wd = e.SelectSingleNode("@class").Value.Substring(cn.Length); if (wd.IndexOf(' ') != -1) { wd = wd.Substring(0, wd.IndexOf(' ')); } w.WindDirection = wind_direction_encoding.Keys.Contains(wd) ? wind_direction_encoding[wd] : WindDirection.Undefined; string ws = wind_divs[period].InnerText.TrimStart('\n', '\r', '\t', ' '); ws = ws.Substring(0, ws.IndexOf(' ')); w.WindSpeed = int.Parse(ws); // pressure string pr = pressure_divs[period].InnerText.TrimStart('\n', '\r', '\t', ' '); pr = pr.Substring(0, pr.IndexOf(' ')); w.Pressure = int.Parse(pr); // humidity string hu = humidity_divs[period].InnerText; hu = hu.Substring(0, hu.IndexOf('%')); w.Humidity = int.Parse(hu); lock (_locker) { _weather[wp] = w; } } return(true); }
private void extract_weather_forecast(WeatherPeriod weatherPeriod, XmlNode node) { }
private void Client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { try { timer.Dispose(); timer = null; Console.WriteLine("Request for weather finished"); if (e.Cancelled) { Console.WriteLine("Weather timed out"); IsBusy = false; if (Status != null) { Status(this, "Timed out getting the weather"); } } else { Console.WriteLine("Got weather reply"); Forecasts.Clear(); // Process the weather result string text = e.Result; WeatherPeriod info; bool isHigh = false; bool isLow = false; foreach (string line in text.Split('\n')) { string value; if (Framework.ExtractKey(out value, line, "\"period\"", ":", ",")) { info = null; foreach (WeatherPeriod test in Forecasts) { if (test.Period == value) { info = test; break; } } if (info == null) { info = new WeatherPeriod(); info.Period = value; Forecasts.Add(info); } } if (line.Contains("\"high\":")) { isHigh = true; isLow = false; } else if (line.Contains("\"low\":")) { isHigh = false; isLow = true; } if (Framework.ExtractKey(out value, line, "\"icon_url\":", "\"", "\"")) info.Icon = value; if (Framework.ExtractKey(out value, line, "\"title\":", "\"", "\"")) info.Title = value; if (Framework.ExtractKey(out value, line, "\"title\":", "\"", "\"")) info.Title = value; if (Framework.ExtractKey(out value, line, "\"fcttext\":", "\"", "\"")) info.Forecast = value; if (Framework.ExtractKey(out value, line, "\"fcttext_metric\":", "\"", "\"")) info.ForecastMetric = value; if (Framework.ExtractKey(out value, line, "\"conditions\":", "\"", "\"")) info.Conditions = value; if (Framework.ExtractKey(out value, line, "\"fahrenheit\":", "\"", "\"")) { if (isHigh) info.High = value; if (isLow) info.Low = value; } if (Framework.ExtractKey(out value, line, "\"celsius\":", "\"", "\"")) { if (isHigh) info.HighMetric = value; if (isLow) info.LowMetric = value; } } if (Status != null) { Status(this, "Got " + Forecasts.Count + " forecasts"); } } if (!CheckDownload(null)) { IsBusy = false; LastSuccess = DateTime.Now; Console.WriteLine("No images to download - finished"); } } catch (Exception ex) { Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); Console.WriteLine("Error - clear busy"); IsBusy = false; } if (!IsBusy) { if (Completed != null) { Completed(this, null); } } }