public async Task <CurrentWeather> GetWeatherByLocationAsync(Coordinates coords, CancellationToken cancellationToken)
        {
            var result = await GetWeatherCurrentAsync(coords, cancellationToken);

            if (result == null)
            {
                return(null);
            }

            var currentDay = result.Daily.Data.FirstOrDefault();

            var temp      = result.Currently.Temperature;
            var humidity  = result.Currently.Humidity;
            var windSpeed = result.Currently.WindSpeed;
            var heatIndex = HeatIndexCalculator.Calculate(temp, humidity);
            var windChill = WindChillCalculator.Calculate(temp, windSpeed);

            return(new CurrentWeather
            {
                Condition = result.Currently.Summary,
                Temperature = temp,
                Humidity = humidity,
                WindChill = windChill,
                WindSpeed = windSpeed,
                ForecastHigh = currentDay.TemperatureHigh,
                ForecastLow = currentDay.TemperatureLow,
                HeatIndex = heatIndex,
                Icon = currentDay.Icon
            });
        }
Exemple #2
0
        public async Task <CurrentWeather> GetWeatherByLocationAsync(Coordinates coords, CancellationToken cancellationToken)
        {
            var result = await GetWeatherAsync($"{coords.Latitude},{coords.Longitude}", cancellationToken);

            var currentDay = result.Forecasts.FirstOrDefault();

            var temp      = result.CurrentObservation.Condition.Temperature;
            var humidity  = result.CurrentObservation.Atmosphere.Humidity;
            var heatIndex = HeatIndexCalculator.Calculate(temp, humidity);

            return(new CurrentWeather
            {
                Condition = result.CurrentObservation.Condition.Text,
                Temperature = temp,
                Humidity = humidity,
                WindChill = result.CurrentObservation.Wind.Chill,
                WindSpeed = result.CurrentObservation.Wind.Speed,
                ForecastHigh = currentDay.High,
                ForecastLow = currentDay.Low,
                HeatIndex = (int)heatIndex
            });
        }