示例#1
0
        private static Weather ConsolidatedWeatherToWeather(ConsolidatedWeather consolidatedWeather)
        {
            const string noData = "No data";

            return(new Weather
            {
                WeatherStateName = consolidatedWeather.WeatherStateName ?? noData,
                WindDirectionCompass = consolidatedWeather.WindDirectionCompass ?? noData,
                Created = consolidatedWeather.Created == new DateTime() ? noData : consolidatedWeather.Created.ToString(""),
                ApplicableDate = consolidatedWeather.ApplicableDate is null ? noData : consolidatedWeather.ApplicableDate,
                MinTemp = consolidatedWeather.MinTemp == null ? noData : Math.Round((double)consolidatedWeather.MinTemp, 1).ToString(CultureInfo.CurrentCulture),
                MaxTemp = consolidatedWeather.MaxTemp == null ? noData : Math.Round((double)consolidatedWeather.MaxTemp, 1).ToString(CultureInfo.CurrentCulture),
                TheTemp = consolidatedWeather.TheTemp == null ? noData : Math.Round((double)consolidatedWeather.TheTemp, 1).ToString(CultureInfo.CurrentCulture),
                WindSpeed = consolidatedWeather.WindSpeed == null ? noData : Math.Round((double)consolidatedWeather.WindSpeed, 1).ToString(CultureInfo.CurrentCulture),
                Humidity = consolidatedWeather.Humidity == 0 ? noData : consolidatedWeather.Humidity.ToString(),
                Predictability = consolidatedWeather.Predictability == 0 ? noData : consolidatedWeather.Predictability.ToString()
            });
示例#2
0
        public void WeatherStateTest()
        {
            ConsolidatedWeather todayWeather = client.GetLocationInfoAndForecast(location.woeid).consolidated_weather.First();
            string   state = todayWeather.weather_state_name;
            DateTime date  = DateTime.Now;
            bool     weatherStateExists = false;

            while (date > DateTime.Now.AddYears(-5))
            {
                date = date.AddDays(-1);
                IEnumerable <string> previousStates = client.GetForecast(location.woeid, date).Select(w => w.weather_state_name).Distinct();
                if (previousStates.Contains(state))
                {
                    weatherStateExists = true;
                    break;
                }
            }
            Assert.IsTrue(weatherStateExists);
        }
示例#3
0
        private static Weather SaveWeather(ConsolidatedWeather weather, Location location)
        {
            var weatherRepository = DependencyService.Get <IWeatherRepository>();

            var weatherToDb = new Weather
            {
                Id           = Guid.NewGuid(),
                Image        = weather.Weather_state_abbr + ".png",
                LocationId   = location.Id,
                Temperature  = (int)weather.The_temp,
                WeatherState = weather.Weather_state_name,
                MinTemp      = (int)weather.Min_temp,
                MaxTemp      = (int)weather.Max_temp
            };

            weatherRepository.Insert(weatherToDb);

            return(weatherToDb);
        }