Ejemplo n.º 1
0
        private WeatherHourly MapWeatherHourly(HourForecast daily, int latitude, int longitude)
        {
            return(new WeatherHourly()
            {
                ApparentTemperature = daily.apparentTemperature,
                CloudCover = daily.cloudCover,
                DewPoint = daily.dewPoint,
                Humidity = daily.humidity,
                Icon = daily.icon,
                Ozone = daily.ozone,
                PrecipIntensity = daily.precipIntensity,
                PrecipProbability = daily.precipProbability,
                PrecipType = daily.precipType,
                Pressure = daily.pressure,
                Summary = daily.summary,
                Temperature = daily.temperature,
                Time = daily.time,
                Visibility = daily.visibility,
                WindBearing = daily.windBearing,
                WindSpeed = daily.windSpeed,

                Latitude = latitude,
                Longitude = longitude
            });
        }
Ejemplo n.º 2
0
        private static DateTime ParseXValidTime(HourForecast hourForecast, int offset)
        {
            var validTime = DateTime.SpecifyKind(ForecastIO.Extensions.Extensions.ToDateTime(
                                                     hourForecast.time).AddHours(offset), DateTimeKind.Unspecified);

            return(validTime);
        }
Ejemplo n.º 3
0
        private static void ConvertHourForecast(HourForecast hourForecast, List <AbstractParameter> parameters)
        {
            parameters.Add(new Temperature(
                               hourForecast.temperature));

            parameters.Add(Pressure.FromHpa(
                               hourForecast.pressure));

            parameters.Add(new PrecipitationAmount(
                               hourForecast.precipIntensity));

            parameters.Add(Humidity.FromPart(
                               hourForecast.humidity));

            parameters.Add(Cloudiness.FromPart(
                               hourForecast.cloudCover));

            parameters.Add(new WindDirection(
                               hourForecast.windBearing));

            parameters.Add(new WindSpeed(
                               hourForecast.windSpeed));
        }
Ejemplo n.º 4
0
        public async Task <IList <HourForecast> > GetHourlyForecasts(string locationKey, ApiSettings apiSettings)
        {
            string url      = BuildUri(locationKey, apiSettings, false);
            var    response = await _httpClient.GetAsync(url);

            string apiResponseText = await response.Content.ReadAsStringAsync();

            JArray         apiResponse = JArray.Parse(apiResponseText);
            IList <JToken> results     = apiResponse.Children().ToList();

            IList <HourForecast> forecasts = new List <HourForecast>();

            foreach (JToken result in results)
            {
                HourForecast forecast = new HourForecast();
                forecast.Time = result.Value <DateTime>("DateTime");

                forecast.Temperature = result.Value <JToken>("Temperature").Value <double>("Value");

                forecasts.Add(forecast);
            }

            return(forecasts);
        }
Ejemplo n.º 5
0
        public async void SetLocation(string location, double latitude, double longitude)
        {
            IsLoading        = true;
            CurrentLocation  = location;
            Latitude         = latitude;
            Longitude        = longitude;
            OlderDataVisible = false;

            var weather = Settings.Settings.Instance.GetWeather(latitude, longitude);

            if (weather is null)
            {
                try
                {
                    weather = await OpenWeather.GetWeather(latitude, longitude, OpenWeather.Units.Metric);

                    Settings.Settings.Instance.UpdatePlace(latitude, longitude, weather);
                }
                catch (Exception)
                {
                    weather = Settings.Settings.Instance.GetWeatherFull(latitude, longitude);
                    if (weather is null)
                    {
                        IsLoading = false;
                        return;
                    }

                    OlderDataVisible = true;
                    OlderDataText    = string.Format(Resources.AppTranslations.OldDataFrom,
                                                     Settings.Settings.Instance.GetWeatherRefreshTime(latitude, longitude)?.ToString("g"));
                }
            }


            DateText = DateTime.Now.ToString("d");
            if (weather.Current.WeatherList.Count > 0)
            {
                WeatherIcon        = StringToIconConverter.Convert(weather.Current.WeatherList[0].Icon);
                WeatherDescription = weather.Current.WeatherList[0].Description.FirstCharToUpper();
            }

            WeatherTemperature = FormatTemperature(weather.Current.Temperature);
            if (weather.Current.Rain != null)
            {
                var max = Math.Max(weather.Current.Rain.ThreeHours, weather.Current.Rain.OneHour);
                WeatherRain = max.ToString("F0") + "mm";
            }
            if (weather.Current.Snow != null)
            {
                var max = Math.Max(weather.Current.Snow.ThreeHours, weather.Current.Snow.OneHour);
                WeatherRain = max.ToString("F0") + "mm";
            }

            WeatherWind = FormatWindSpeed(weather.Current.WindSpeed);

            WeatherPressure = weather.Current.Pressure.ToString("F0") + "hPa";
            WeatherSunrise  = string.Format(AppTranslations.Sunrise,
                                            UnixTimeStampToDateTimeConverter.Convert(weather.Current.Sunrise).ToString("t"));
            WeatherSunset = string.Format(AppTranslations.Sunset,
                                          UnixTimeStampToDateTimeConverter.Convert(weather.Current.Sunset).ToString("t"));

            HoursForecastItems.Clear();
            foreach (var hourlyWeather in weather.Hourly)
            {
                var forecast = new HourForecast()
                {
                    Time = UnixTimeStampToDateTimeConverter.Convert(hourlyWeather.Datetime)
                           .ToString("t"),
                    Temperature = FormatTemperature(hourlyWeather.Temperature)
                };
                if (hourlyWeather.WeatherList.Count > 0)
                {
                    forecast.IconSource = StringToIconConverter.Convert(hourlyWeather.WeatherList[0].Icon);
                }

                HoursForecastItems.Add(forecast);
                if (HoursForecastItems.Count >= 24)
                {
                    break;
                }
            }

            DaysForecastItems.Clear();
            foreach (var dailyWeather in weather.Daily)
            {
                var forecast = new DayForecast()
                {
                    Temperature = FormatTemperature(dailyWeather.Temperature.Day),
                    Time        = UnixTimeStampToDateTimeConverter.Convert(dailyWeather.Datetime + weather.TimezoneOffset)
                                  .ToString("ddd"),
                    Rain = (dailyWeather.Rain + dailyWeather.Snow).ToString("F0") + "mm",
                };
                if (dailyWeather.WeatherList.Count > 0)
                {
                    forecast.IconSource = StringToIconConverter.Convert(dailyWeather.WeatherList[0].Icon);
                }

                DaysForecastItems.Add(forecast);

                if (DaysForecastItems.Count >= 7)
                {
                    break;
                }
            }

            RefreshFavoritePlaces();
            IsLoading = false;
        }