/// <summary> /// Converts NWS data into GenericCurrentObservation object /// </summary> /// <returns></returns> public GenericCurrentObservation GetGenericCurrentObservation() { if (Properties == null || Properties.Periods == null || Properties.Periods.Length < 1) { return(null); } var currentObservation = new GenericCurrentObservation(); var currentPeriod = Properties.Periods.FirstOrDefault(); currentObservation.Icon = (UseWebIcon) ? currentPeriod.Icon : ConvertIconToEmoji(currentPeriod.Icon); if (currentPeriod.TemperatureUnit == "F") { currentObservation.TemperatureFahrenheit = currentPeriod.Temperature; currentObservation.TemperatureCelsius = WeatherHelper.GetCelsius(currentPeriod.Temperature); } else { currentObservation.TemperatureCelsius = currentPeriod.Temperature; currentObservation.TemperatureFahrenheit = WeatherHelper.GetFahrenheit(currentPeriod.Temperature); } currentObservation.WeatherDescription = currentPeriod.ShortForecast; currentObservation.AdditionalInfo = string.Format(Common.GetLocalizedText("WeatherWindSpeedFormat"), currentPeriod.WindDirection, currentPeriod.WindSpeed); return(currentObservation); }
/// <summary> /// Converts NWS data to GenericForcast object /// </summary> /// <returns></returns> public GenericForecast GetGenericForecast() { if (Properties == null || Properties.Periods == null || Properties.Periods.Length < 1) { return(null); } var forecastDays = new List <GenericForecastDay>(); var dateList = new List <DateTime>(); foreach (var period in Properties.Periods) { if (dateList.Count == 5) { break; } if (!dateList.Contains(period.StartTime.Date)) { forecastDays.Add(new GenericForecastDay { DayOfWeek = period.StartTime.ToString("dddd"), TemperatureFahrenheit = ((period.TemperatureUnit == "F") ? period.Temperature : WeatherHelper.GetFahrenheit(period.Temperature)).ToString() + "°F", TemperatureCelsius = ((period.TemperatureUnit == "C") ? period.Temperature : WeatherHelper.GetCelsius(period.Temperature)).ToString() + "°C", WeatherIcon = (UseWebIcon) ? period.Icon : ConvertIconToEmoji(period.Icon), WeatherDescription = period.ShortForecast }); dateList.Add(period.StartTime.Date); } } return(new GenericForecast { Days = forecastDays.ToArray() }); }
/// <summary> /// Converts NWS data to GenericForcast object /// </summary> /// <returns></returns> public GenericForecast GetGenericForecast() { if (Properties == null || Properties.Periods == null || Properties.Periods.Length < 1) { return(null); } var forecastDays = new List <GenericForecastDay>(); var dateList = new List <DateTime>(); foreach (var period in Properties.Periods) { if (!dateList.Contains(period.StartTime.Date)) { forecastDays.Add(new GenericForecastDay { Date = period.StartTime.Date, TemperatureHigh = ((period.TemperatureUnit == "F") ? period.Temperature : WeatherHelper.GetFahrenheit(period.Temperature)), TemperatureLow = ((period.TemperatureUnit == "F") ? period.Temperature : WeatherHelper.GetFahrenheit(period.Temperature)), WeatherIcon = (UseWebIcon) ? period.Icon : ConvertIconToEmoji(period.Icon), WeatherDescription = period.ShortForecast }); dateList.Add(period.StartTime.Date); } else { var existing = forecastDays.FirstOrDefault(x => x.Date == period.StartTime.Date); if (existing != null) { existing.TemperatureLow = ((period.TemperatureUnit == "F") ? period.Temperature : WeatherHelper.GetFahrenheit(period.Temperature)); } // Swap if needed if (existing.TemperatureLow > existing.TemperatureHigh) { var temp = existing.TemperatureLow; existing.TemperatureLow = existing.TemperatureHigh; existing.TemperatureHigh = temp; } } } return(new GenericForecast { Days = forecastDays.Take(5).ToArray() }); }