internal WeatherData MapResponse(OpenWeatherApiResponse response) { WeatherData weatherData = new WeatherData() { DataProvider = "Open Weather API", ObservationTime = DateTimeOffset.FromUnixTimeMilliseconds(response.dt).UtcDateTime, Location = response.name, CurrentConditions = response.weather.FirstOrDefault()?.main, Temperature = response.main.temp, Humidity = response.main.humidity, Pressure = response.main.pressure, WindSpeed = response.wind.speed, WindDirection = CompassDirection.Decode(response.wind.deg), WindDirectionDegrees = response.wind.deg }; return(weatherData); }
private WeatherData MapResponse(NoaaResponse response) { WeatherData data = new WeatherData() { DataProvider = "NOAA/National Weather Service", Location = response.location.areaDescription, ObservationTime = DateTime.ParseExact(response.currentobservation.Date.Substring(0, 15), "dd MMM HH:mm tt", CultureInfo.InvariantCulture), CurrentConditions = response.currentobservation.Weather, Temperature = (Convert.ToDouble(response.currentobservation.Temp) - 32) * 5.0 / 9.0, Humidity = Convert.ToDouble(response.currentobservation.Relh), Pressure = (response.currentobservation.Altimeter != "NA") ? Convert.ToDouble(response.currentobservation.Altimeter) : (double?)null, WindSpeed = (response.currentobservation.Winds != "NA") ? Convert.ToDouble(response.currentobservation.Winds) * 1.609 : (double?)null, WindDirection = (response.currentobservation.Windd != "NA") ? CompassDirection.Decode(Convert.ToDouble(response.currentobservation.Windd)) : null, WindDirectionDegrees = (response.currentobservation.Windd != "NA") ? Convert.ToDouble(response.currentobservation.Windd) : (double?)null, }; return(data); }