/// <summary> /// Updates SAM WeatherYear from TBD WeatherYear /// </summary> /// <param name="weatherYear">Destination SAM WeatherYear</param> /// <param name="weatherYear_TBD">Source TBD WeatherYear</param> /// <returns>True if data Updated</returns> public static bool Update(this WeatherYear weatherYear, TBD.WeatherYear weatherYear_TBD) { if (weatherYear == null || weatherYear_TBD == null) { return(false); } weatherYear.Year = weatherYear_TBD.year; List <TBD.WeatherDay> weatherDays_TBD = weatherYear_TBD.WeatherDays(); for (int i = 0; i < weatherDays_TBD.Count; i++) { WeatherDay weatherDay = weatherYear[i]; if (weatherDay == null) { weatherDay = new WeatherDay(); } Update(weatherDay, weatherDays_TBD[i]); weatherYear[i] = weatherDay; } return(true); }
private string CreateWeatherDay(WeatherDay day) { var tempHigh = ConvertToTempString(day.High); var tempLow = ConvertToTempString(day.Low); return(string.Format("{0}: {1} / {2} - {3}", day.Day, tempHigh, tempLow, day.Text)); }
public void A1_GetDiffMaxMin() { WeatherDay weatherDay = new WeatherDay(); weatherDay.Number = 1; weatherDay.TempMax = 34.4; weatherDay.TempMin = 15.5; Assert.AreEqual(weatherDay.GetDiffMaxMin(), 18.9); }
/// <summary> /// Updates TBD Weather Day from SAM WeatherDay /// </summary> /// <param name="weatherDay_TBD">Destination TBD WeatherDay</param> /// <param name="weatherDay">Source SAM WeatherDay </param> /// <returns>True if data updated</returns> public static bool Update(this TBD.WeatherDay weatherDay_TBD, WeatherDay weatherDay) { if (weatherDay_TBD == null || weatherDay == null) { return(false); } for (int i = 1; i <= 24; i++) { double value = double.NaN; if (weatherDay.TryGetValue(WeatherDataType.CloudCover, i - 1, out value)) { weatherDay_TBD.cloudCover[i] = System.Convert.ToSingle(value); } if (weatherDay.TryGetValue(WeatherDataType.DryBulbTemperature, i - 1, out value)) { weatherDay_TBD.dryBulb[i] = System.Convert.ToSingle(value); } if (weatherDay.TryGetValue(WeatherDataType.WindSpeed, i - 1, out value)) { weatherDay_TBD.windSpeed[i] = System.Convert.ToSingle(value); } if (weatherDay.TryGetValue(WeatherDataType.DiffuseSolarRadiation, i - 1, out value)) { weatherDay_TBD.diffuseRadiation[i] = System.Convert.ToSingle(value); } if (weatherDay.TryGetValue(WeatherDataType.GlobalSolarRadiation, i - 1, out value)) { weatherDay_TBD.globalRadiation[i] = System.Convert.ToSingle(value); } else { value = weatherDay.CalculatedGlobalRadiation(i - 1); weatherDay_TBD.globalRadiation[i] = System.Convert.ToSingle(value); } if (weatherDay.TryGetValue(WeatherDataType.RelativeHumidity, i - 1, out value)) { weatherDay_TBD.humidity[i] = System.Convert.ToSingle(value); } if (weatherDay.TryGetValue(WeatherDataType.WindDirection, i - 1, out value)) { weatherDay_TBD.windDirection[i] = System.Convert.ToSingle(value); } } return(true); }
public WeatherDay[] GetWheatherForecast(string area, DateTime start, int days) { var result = new WeatherDay[days]; for (var i = 0; i < result.Length; i++) { result[i] = makeFake(start.AddDays(i), area); } return(result); }
private WeatherDay AssignWeatherDay(SqlDataReader reader) { var weatherDay = new WeatherDay(); try { weatherDay.Hi = int.Parse(reader["high"].ToString()); weatherDay.Lo = int.Parse(reader["low"].ToString()); weatherDay.Forecast = reader["forecast"].ToString(); weatherDay.Index = int.Parse(reader["fiveDayForecastValue"].ToString()); } catch (Exception) { } return(weatherDay); }
public void B1_WeatherMonthAdd() { WeatherDay weatherDay = new WeatherDay(); weatherDay.Number = 1; weatherDay.TempMax = 34.4; weatherDay.TempMin = 15.5; List <WeatherDay> days = new List <WeatherDay>(); days.Add(weatherDay); WeatherMonth weatherMonth = new WeatherMonth(); weatherMonth.Add(weatherDay); CollectionAssert.AreEqual(weatherMonth, days); }
public WeatherDay ParseCurrentWeather(String jsonString) { var json = JObject.Parse(jsonString); var main = json["main"]; var weather = json["weather"][0]; var wind = json["wind"]; var result = new WeatherDay() { Date = DateTimeOffset.FromUnixTimeSeconds(long.Parse(json["dt"].ToString())).DateTime, Temperature = Temperature.FromCelsius(double.Parse(main["temp"].ToString()) / 10), Humidity = RelativeHumidity.FromPercentage(double.Parse(main["humidity"].ToString()) / 100), Condition = OpenWeatherMapConditionParser.Parse(weather["icon"].ToString()), Wind = ParseWind(wind) }; result.ApparentTemperature = ApparentTemperatureCalculator.Calculate(result); return(result); }
/// <summary> /// Updates SAM WeatherDay from TBD WeatherDay /// </summary> /// <param name="weatherDay">Destination SAM WeatherDay</param> /// <param name="weatherDay_TBD">Source TBD WeatherDay</param> /// <returns>True if data Updated</returns> public static bool Update(this WeatherDay weatherDay, TBD.WeatherDay weatherDay_TBD) { if (weatherDay_TBD == null || weatherDay == null) { return(false); } for (int i = 1; i <= 24; i++) { weatherDay[WeatherDataType.CloudCover, i - 1] = weatherDay_TBD.cloudCover[i]; weatherDay[WeatherDataType.DryBulbTemperature, i - 1] = weatherDay_TBD.dryBulb[i]; weatherDay[WeatherDataType.WindSpeed, i - 1] = weatherDay_TBD.windSpeed[i]; weatherDay[WeatherDataType.DiffuseSolarRadiation, i - 1] = weatherDay_TBD.diffuseRadiation[i]; weatherDay[WeatherDataType.GlobalSolarRadiation, i - 1] = weatherDay_TBD.globalRadiation[i]; weatherDay[WeatherDataType.RelativeHumidity, i - 1] = weatherDay_TBD.humidity[i]; weatherDay[WeatherDataType.WindDirection, i - 1] = weatherDay_TBD.windDirection[i]; } return(true); }
public void B2_WeatherMonthAdd() { WeatherDay weatherDay1 = new WeatherDay(); weatherDay1.Number = 1; weatherDay1.TempMax = 34.4; weatherDay1.TempMin = 15.5; WeatherDay weatherDay2 = new WeatherDay(); weatherDay2.Number = 2; weatherDay2.TempMax = 34.4; weatherDay2.TempMin = 34.1; WeatherMonth weatherMonth = new WeatherMonth(); weatherMonth.Add(weatherDay1); weatherMonth.Add(weatherDay2); Assert.AreEqual(weatherMonth.GetNumerDayMinDiff(), 2); }
public void A0_InitWeatherDay() { WeatherDay weatherDay = new WeatherDay(); Assert.IsTrue(weatherDay != null); }
/// <summary> /// Разбор строки xml /// </summary> /// <param name="xmlContent"></param> /// <returns></returns> private static List <WeatherDay> ParseForecastXML(string xmlContent) { XDocument xdoc = XDocument.Parse(xmlContent); List <WeatherDay> list = new List <WeatherDay>(); foreach (var elem in xdoc.Root.Elements().Elements().Elements().Where(r => r.Name == "FORECAST")) { WeatherDay day = new WeatherDay(); day.Tod = elem.Attribute("tod").Value switch { "0" => "Ночь", "1" => "Утро", "2" => "День", _ => "Вечер", }; foreach (var podElem in elem.Elements()) { if (podElem.Name == "PHENOMENA") { day.Cloudiness = podElem.Attribute("cloudiness").Value switch { "-1" => "Туман", "0" => "Ясно", "1" => "Малооблачно", "2" => "Облачно", _ => "Пасмурно", }; day.Precipitation = podElem.Attribute("precipitation").Value switch { "3" => "Смешанные", "4" => "Дождь", "5" => "Ливень", "6" => "Снег", "7" => "Снег", "8" => "Гроза", "9" => "Нет данных", _ => "Без осадков", }; day.RPower = podElem.Attribute("rpower").Value switch { "1" => "Возможны осадки", _ => string.Empty, }; day.SPower = podElem.Attribute("spower").Value switch { "1" => "Возможна гроза", _ => string.Empty, }; } if (podElem.Name == "TEMPERATURE") { int.TryParse(podElem.Attribute("max").Value, out int max); day.Max = max; int.TryParse(podElem.Attribute("min").Value, out int min); day.Min = min; } if (podElem.Name == "WIND") { int.TryParse(podElem.Attribute("max").Value, out int max); day.WindMax = max; int.TryParse(podElem.Attribute("min").Value, out int min); day.WindMin = min; day.WindDirection = podElem.Attribute("direction").Value switch { "0" => "Северный", "1" => "Северо-восточный", "2" => "Восточный", "3" => "Южно-восточный", "4" => "Южный", "5" => "Южно-западный", "6" => "Западный", _ => "Северо-западный" }; } } list.Add(day); } return(list); } }
public static Temperature Calculate(WeatherDay weather) { return(weather.Temperature); }
public void AddNextDayWeather(WeatherDay day) { wetherlist.Add(day); }