Ejemplo n.º 1
0
        public void Test_SelectShortTermEntry_SecondOne()
        {
            //Arrange
            IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock());

            var forecast = new ForecastShortTerm();

            var entry1 = new ForecastShortTermEntry();

            entry1.UnixTimestamp = 978361200; //2001/01/01 15:00:00
            var entry2 = new ForecastShortTermEntry();

            entry2.UnixTimestamp = 978368400; //2001/01/01 17:00:00

            forecast.Entries = new List <ForecastShortTermEntry>()
            {
                entry1, entry2
            };

            var locDetail = new LocationDetail();

            locDetail.Time = new DateTime(2001, 01, 01, 16, 0, 1); //978364801

            //Act
            var entry = weatherUtils.SelectShortTermEntry(locDetail, forecast);

            //Assert - entry2 should be selected
            Assert.AreEqual(978368400, entry.UnixTimestamp);
        }
Ejemplo n.º 2
0
        public void Test_SelectLongTermEntry_SecondOne()
        {
            //Arrange
            IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock());

            var forecast = new ForecastLongTerm();

            var entry1 = new ForecastDailyEntry();

            entry1.UnixTimestamp = 1335913200; //2012/05/01 23:00
            var entry2 = new ForecastDailyEntry();

            entry2.UnixTimestamp = 1335927600; //2012/05/02 03:00

            forecast.Entries = new List <ForecastDailyEntry>()
            {
                entry1, entry2
            };

            var locDetail = new LocationDetail();

            locDetail.Time = new DateTime(2012, 5, 1, 0, 0, 0);

            //Act
            var entry = weatherUtils.SelectLongTermEntry(locDetail, forecast);

            //Assert - entry2 should be selected
            Assert.AreEqual(1335913200, entry.UnixTimestamp);
        }
Ejemplo n.º 3
0
        public void Test_SelectLongTermEntry_Argument2Null()
        {
            IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock());

            var loc = new LocationDetail();

            weatherUtils.SelectShortTermEntry(loc, null);
        }
Ejemplo n.º 4
0
        public void Test_SelectLongTermEntry_Argument1Null()
        {
            IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock());

            var fc = new ForecastLongTerm();

            weatherUtils.SelectLongTermEntry(null, fc);
        }
Ejemplo n.º 5
0
        public void Test_AvailableForShortTermForecast_TripNull()
        {
            //Arrange
            DateTime dtNow        = new DateTime(2014, 12, 6, 18, 40, 0);
            var      weatherUtils = new WeatherUtils(new MockClock(dtNow));

            //Act
            weatherUtils.AvailableForShortTermForecast(null);
        }
        public override void FillModel(TileModel model, dynamic options)
        {
            model.title = "Weather";
            model.url   = "webapp/weather/forecast";

            string strCityId = options.cityId;

            if (string.IsNullOrWhiteSpace(strCityId))
            {
                model.content = "Missing cityId parameter";
                return;
            }

            Guid cityId;

            if (!Guid.TryParse(strCityId, out cityId))
            {
                model.content = "CityId parameter must contain GUID value";
                return;
            }

            var data = Context.GetPlugin <WeatherPlugin>().GetWeatherData(DateTime.Now);

            WeatherLocatioinModel location = data.FirstOrDefault(l => l.LocationId == cityId);

            if (location == null)
            {
                model.content = string.Format("Location with id = {0} is not found", cityId);
                return;
            }

            model.title = location.LocationName;

            // текущая погода
            if (location.Now == null)
            {
                model.content = "Current weather is undefined";
                return;
            }

            string formattedNow = WeatherUtils.FormatTemperature(location.Now.Temperature);

            model.content   = string.Format("now: {0}°C", formattedNow);
            model.className = "btn-primary th-tile-icon th-tile-icon-wa " + WeatherUtils.GetIconClass(location.Now.Code);

            // погода на завтра
            var tomorrow = location.Forecast.FirstOrDefault();

            if (tomorrow != null)
            {
                string formattedTomorrow = WeatherUtils.FormatTemperatureRange(tomorrow.MinTemperature, tomorrow.MaxTemperature);
                model.content += string.Format("\nnext: {0}°C", formattedTomorrow);
            }
        }
Ejemplo n.º 7
0
        public void Test_SelectShortTermEntry_NoEntries()
        {
            IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock());

            var loc = new LocationDetail();
            var fc  = new ForecastShortTerm();

            fc.Entries = new List <ForecastShortTermEntry>();

            weatherUtils.SelectShortTermEntry(loc, fc);
        }
Ejemplo n.º 8
0
        public void Test_SelectLongTermEntry_NoEntries()
        {
            IWeatherUtils weatherUtils = new WeatherUtils(new SystemClock());

            LocationDetail loc = new LocationDetail();
            var            fc  = new ForecastLongTerm();

            fc.Entries = new List <ForecastDailyEntry>();

            var result = weatherUtils.SelectLongTermEntry(loc, fc);

            Assert.AreEqual("N/A", result.WeatherDescription[0].Description);
        }
Ejemplo n.º 9
0
        public async Task Test_GetForecastForTrip_TripNull()
        {
            //Arrange

            IClock                  iClock                 = new SystemClock();
            IWeatherProvider        weatherProvider        = new WeatherProvider();
            IWeatherUtils           weatherUtils           = new WeatherUtils(iClock);
            ILocationWeatherManager locationWeatherManager = new LocationWeatherManager(weatherProvider, weatherUtils);
            ITripIntervalManager    tripIntervalManager    = new TripIntervalManager();
            ITripWeatherManager     tripWeatherManager     = new TripWeatherManager(locationWeatherManager, weatherUtils, tripIntervalManager);

            //Act and Assert
            var result = await tripWeatherManager.GetForecastForTrip(null);
        }
Ejemplo n.º 10
0
 private object BuildModel(DailyWeatherDataModel data)
 {
     return(data == null
                         ? null
                         : new
     {
         when = data.DateTime.ToString("M"),
         t = WeatherUtils.FormatTemperatureRange(data.MinTemperature, data.MaxTemperature),
         p = string.Format("{0} .. {1}", data.MinPressure, data.MaxPressure),
         h = string.Format("{0} .. {1}", data.MinHumidity, data.MaxHumidity),
         icon = WeatherUtils.GetIconClass(data.Code),
         description = data.Description
     });
 }
Ejemplo n.º 11
0
 private object BuildModel(WeatherDataModel data)
 {
     return(data == null
                         ? null
                         : new
     {
         when = data.DateTime.ToShortTimeString(),
         t = WeatherUtils.FormatTemperature(data.Temperature),
         p = data.Pressure,
         h = data.Humidity,
         icon = WeatherUtils.GetIconClass(data.Code),
         description = data.Description
     });
 }
Ejemplo n.º 12
0
        public void Test_AvailableForShortTermForecast_UnderBy_15Minutes()
        {
            //Arrange
            var dtNow   = new DateTime(2014, 10, 1, 15, 0, 0);
            var dtStart = new DateTime(2014, 10, 5, 23, 30, 0);

            var trip = new Trip();

            trip.StartDateTime = dtStart;
            trip.Duration      = 900; // 15 minutes

            IClock        staticClock  = new MockClock(dtNow);
            IWeatherUtils weatherUtils = new WeatherUtils(staticClock);

            //Act
            bool available = weatherUtils.AvailableForShortTermForecast(trip);

            //Assert
            Assert.IsTrue(available);
        }
Ejemplo n.º 13
0
        public void Test_AvailableForShortTermForecast_True()
        {
            //Arrange
            var dtNow   = new DateTime(2014, 10, 1, 15, 0, 0);
            var dtStart = new DateTime(2014, 10, 4, 17, 0, 0);

            var trip = new Trip();

            trip.StartDateTime = dtStart;
            trip.Duration      = 3600; // one hour

            IClock        staticClock  = new MockClock(dtNow);
            IWeatherUtils weatherUtils = new WeatherUtils(staticClock);

            //Act
            bool available = weatherUtils.AvailableForShortTermForecast(trip);

            //Assert
            Assert.IsTrue(available);
        }
        public void UpdateView(Weather weather)
        {
#if WINDOWS_UWP
            var userlang = Windows.System.UserProfile.GlobalizationPreferences.Languages[0];
            var culture  = new CultureInfo(userlang);
#else
            var culture = CultureInfo.CurrentCulture;
#endif
            // Update backgrounds
#if WINDOWS_UWP
            wm.SetBackground(Background, weather);
            PendingBackgroundColor = wm.GetWeatherBackgroundColor(weather);
#elif __ANDROID__
            Background        = wm.GetBackgroundURI(weather);
            PendingBackground = wm.GetWeatherBackgroundColor(weather);
#endif

            // Location
            Location = weather.location.name;

            // Date Updated
            UpdateDate = WeatherUtils.GetLastBuildDate(weather);

            // Update Current Condition
            CurTemp = Settings.IsFahrenheit ?
                      Math.Round(weather.condition.temp_f) + "\uf045" : Math.Round(weather.condition.temp_c) + "\uf03c";
            CurCondition = (String.IsNullOrWhiteSpace(weather.condition.weather)) ? "---" : weather.condition.weather;
            WeatherIcon  = weather.condition.icon;

            // WeatherDetails
            // Astronomy
#if WINDOWS_UWP
            Sunrise = weather.astronomy.sunrise.ToString("t", culture);
            Sunset  = weather.astronomy.sunset.ToString("t", culture);
#elif __ANDROID__
            if (Android.Text.Format.DateFormat.Is24HourFormat(Application.Context))
            {
                Sunrise = weather.astronomy.sunrise.ToString("HH:mm");
                Sunset  = weather.astronomy.sunset.ToString("HH:mm");
            }
            else
            {
                Sunrise = weather.astronomy.sunrise.ToString("h:mm tt");
                Sunset  = weather.astronomy.sunset.ToString("h:mm tt");
            }
#endif

            // Wind
            WindChill = Settings.IsFahrenheit ?
                        Math.Round(weather.condition.feelslike_f) + "º" : Math.Round(weather.condition.feelslike_c) + "º";
            WindSpeed = Settings.IsFahrenheit ?
                        Math.Round(weather.condition.wind_mph) + " mph" : Math.Round(weather.condition.wind_kph) + " kph";
            UpdateWindDirection(weather.condition.wind_degrees);

            // Atmosphere
            Humidity = weather.atmosphere.humidity;
            if (!Humidity.EndsWith("%", StringComparison.Ordinal))
            {
                Humidity += "%";
            }

            var pressureVal  = Settings.IsFahrenheit ? weather.atmosphere.pressure_in : weather.atmosphere.pressure_mb;
            var pressureUnit = Settings.IsFahrenheit ? "in" : "mb";

            if (float.TryParse(pressureVal, NumberStyles.Float, CultureInfo.InvariantCulture, out float pressure))
            {
                Pressure = string.Format("{0} {1}", pressure.ToString(culture), pressureUnit);
            }
            else
            {
                Pressure = string.Format("-- {0}", pressureUnit);
            }

            UpdatePressureState(weather.atmosphere.pressure_trend);

            var visibilityVal  = Settings.IsFahrenheit ? weather.atmosphere.visibility_mi : weather.atmosphere.visibility_km;
            var visibilityUnit = Settings.IsFahrenheit ? "mi" : "km";

            if (float.TryParse(visibilityVal, NumberStyles.Float, CultureInfo.InvariantCulture, out float visibility))
            {
                _Visibility = string.Format("{0} {1}", visibility.ToString(culture), visibilityUnit);
            }
            else
            {
                _Visibility = string.Format("-- {0}", visibilityUnit);
            }

            // Add UI elements
            Forecasts.Clear();
            foreach (Forecast forecast in weather.forecast)
            {
                ForecastItemViewModel forecastView = new ForecastItemViewModel(forecast);
                Forecasts.Add(forecastView);
            }

            // Additional Details
            WeatherSource = weather.source;
            string creditPrefix = "Data from";

#if WINDOWS_UWP
            creditPrefix = App.ResLoader.GetString("Credit_Prefix");
#elif __ANDROID__
            creditPrefix = Application.Context.GetString(Resource.String.credit_prefix);
#endif

            if (weather.source == WeatherAPI.WeatherUnderground)
            {
                WeatherCredit = string.Format("{0} WeatherUnderground", creditPrefix);
            }
            else if (weather.source == WeatherAPI.Yahoo)
            {
                WeatherCredit = string.Format("{0} Yahoo!", creditPrefix);
            }
            else if (weather.source == WeatherAPI.OpenWeatherMap)
            {
                WeatherCredit = string.Format("{0} OpenWeatherMap", creditPrefix);
            }
            else if (weather.source == WeatherAPI.MetNo)
            {
                WeatherCredit = string.Format("{0} MET Norway", creditPrefix);
            }
            else if (weather.source == WeatherAPI.Here)
            {
                WeatherCredit = string.Format("{0} HERE Weather", creditPrefix);
            }

            Extras.UpdateView(weather);

            // Language
            WeatherLocale = weather.locale;
        }