Exemplo n.º 1
0
        /// <summary>
        /// This handles the decrementing of stats based on the weather conditions
        /// </summary>
        /// <param name="organism"></param>
        /// <param name="weatherSettings"></param>
        private static void UpdateWeatherAttribute(Organism organism, WeatherSettings weatherSettings)
        {
            switch (weatherSettings)
            {
            case WeatherSettings.Cold:

                if (!organism.Attributes.ResistCold)
                {
                    organism.DecreaseHealth(1);
                }

                break;

            case WeatherSettings.Hot:
                if (!organism.Attributes.ResistHeat)
                {
                    organism.DecreaseHealth(1);
                }
                break;

            case WeatherSettings.Warm:
            default:
                break;
            }
        }
Exemplo n.º 2
0
    private WeatherViewModel GetLocalizedWeather(Weather weather, WeatherSettings settings)
    {
        var weatherVm = new WeatherViewModel
        {
            Description       = weather?.Description,
            Icon              = weather?.Icon,
            TemperatureUnits  = settings?.TemperatureUnits,
            WindSpeedUnits    = settings?.WindSpeedUnits,
            Humidity          = weather?.Humidity,
            CloudCoverPercent = weather?.CloudCoverPercent
        };

        weatherVm.Temperature = _converter.Convert(
            weather?.TemperatureDegreesKelvin,
            _converter.Kelvin,
            settings?.TemperatureUnits
            )?.ToString("N0")
                                ?? weather?.TemperatureString;
        weatherVm.WindSpeed =
            _converter.Convert(
                weather?.WindSpeedMeterPerSecond,
                _converter.MeterPerSecond,
                settings?.WindSpeedUnits)?.ToString("N0")
            ?? weather?.WindSpeedString;
        weatherVm.WindDirection =
            weather?.WindDirectionDegrees?.ToString()
            ?? weather?.WindDirectionString;
        weatherVm.WindGust =
            _converter.Convert(
                weather?.WindGustMeterPerSecond,
                _converter.MeterPerSecond,
                settings?.WindSpeedUnits)?.ToString("N0")
            ?? weather?.WindGustString;
        return(weatherVm);
    }
Exemplo n.º 3
0
        static public void SaveSettings(string userId, WeatherSettings cw)
        {
            Storage storage = new Storage(new DefaultDBUtils());

            cw.id = storage.GetWeatherId(userId);
            storage.SaveWeatherSettings((Data.Models.WeatherSettings)cw);
        }
Exemplo n.º 4
0
 void OnEnable()
 {
     _settingUpdates = _gameSettingsProvider.SettingChanges.Subscribe(settings => {
         _time    = settings.Gameplay.Time;
         _weather = settings.Gameplay.Weather;
     });
 }
        protected void SetAndUpdatePreferredLocation()
        {
            WeatherSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <WeatherSettings>();

            if (settings == null || settings.LocationsList == null)
            {
                return;
            }

            CitySetupInfo city = settings.LocationsList.Find(loc => loc.Id == settings.LocationCode);

            if (city == null)
            {
                return;
            }
            bool result = false;

            try
            {
                City newLocation = new City(city);
                if (ServiceRegistration.Get <IWeatherCatcher>().GetLocationData(newLocation))
                {
                    CurrentLocation.Copy(newLocation);
                    result = true;
                }
            }
            catch (Exception)
            { }

            ServiceRegistration.Get <ILogger>().Info(result ?
                                                     "CurrentWeatherModel: Loaded weather data for {0}, {1}" : "WeatherModel: Failed to load weather data for {0}, {1}",
                                                     CurrentLocation.Name, CurrentLocation.Id);
        }
Exemplo n.º 6
0
        public WorldWeatherOnlineCatcher()
        {
            WeatherSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <WeatherSettings>();

            _parsefileLocation = ServiceRegistration.Get <IPathManager>().GetPath(settings.ParsefileLocation);

            #region Weather code translation

            _weatherCodeTranslation[395] = 42; //  Moderate or heavy snow in area with thunder
            _weatherCodeTranslation[392] = 14; //  Patchy light snow in area with thunder
            _weatherCodeTranslation[389] = 40; //  Moderate or heavy rain in area with thunder
            _weatherCodeTranslation[386] = 3;  //  Patchy light rain in area with thunder
            _weatherCodeTranslation[377] = 18; //  Moderate or heavy showers of ice pellets
            _weatherCodeTranslation[374] = 18; //  Light showers of ice pellets
            _weatherCodeTranslation[371] = 16; //  Moderate or heavy snow showers
            _weatherCodeTranslation[368] = 14; //  Light snow showers
            _weatherCodeTranslation[365] = 6;  //  Moderate or heavy sleet showers
            _weatherCodeTranslation[362] = 6;  //  Light sleet showers
            _weatherCodeTranslation[359] = 12; //  Torrential rain shower
            _weatherCodeTranslation[356] = 40; //  Moderate or heavy rain shower
            _weatherCodeTranslation[353] = 39; //  Light rain shower
            _weatherCodeTranslation[350] = 18; //  Ice pellets
            _weatherCodeTranslation[338] = 42; //  Heavy snow
            _weatherCodeTranslation[335] = 16; //  Patchy heavy snow
            _weatherCodeTranslation[332] = 41; //  Moderate snow
            _weatherCodeTranslation[329] = 14; //  Patchy moderate snow
            _weatherCodeTranslation[326] = 14; //  Light snow
            _weatherCodeTranslation[323] = 14; //  Patchy light snow
            _weatherCodeTranslation[320] = 6;  //  Moderate or heavy sleet
            _weatherCodeTranslation[317] = 6;  //  Light sleet
            _weatherCodeTranslation[314] = 10; //  Moderate or Heavy freezing rain
            _weatherCodeTranslation[311] = 10; //  Light freezing rain
            _weatherCodeTranslation[308] = 40; //  Heavy rain
            _weatherCodeTranslation[305] = 39; //  Heavy rain at times
            _weatherCodeTranslation[302] = 40; //  Moderate rain
            _weatherCodeTranslation[299] = 39; //  Moderate rain at times
            _weatherCodeTranslation[296] = 11; //  Light rain
            _weatherCodeTranslation[293] = 11; //  Patchy light rain
            _weatherCodeTranslation[284] = 8;  //  Heavy freezing drizzle
            _weatherCodeTranslation[281] = 8;  //  Freezing drizzle
            _weatherCodeTranslation[266] = 9;  //  Light drizzle
            _weatherCodeTranslation[263] = 9;  //  Patchy light drizzle
            _weatherCodeTranslation[260] = 20; //  Freezing fog
            _weatherCodeTranslation[248] = 20; //  Fog
            _weatherCodeTranslation[230] = 42; //  Blizzard
            _weatherCodeTranslation[227] = 43; //  Blowing snow
            _weatherCodeTranslation[200] = 35; //  Thundery outbreaks in nearby
            _weatherCodeTranslation[185] = 8;  //  Patchy freezing drizzle nearby
            _weatherCodeTranslation[182] = 6;  //  Patchy sleet nearby
            _weatherCodeTranslation[179] = 41; //  Patchy snow nearby
            _weatherCodeTranslation[176] = 39; //  Patchy rain nearby
            _weatherCodeTranslation[143] = 20; //  Mist
            _weatherCodeTranslation[122] = 26; //  Overcast
            _weatherCodeTranslation[119] = 26; //  Cloudy
            _weatherCodeTranslation[116] = 30; //  Partly Cloudy
            _weatherCodeTranslation[113] = 32; //  Clear/Sunny

            #endregion
        }
Exemplo n.º 7
0
        public override void Save()
        {
            base.Save();
            WeatherSettings settings = SettingsManager.Load <WeatherSettings>();

            settings.ApiKey = _value;
            SettingsManager.Save(settings);
        }
Exemplo n.º 8
0
        public void Awake()
        {
            //this is a comment
            Logger("Awoke!");
            DontDestroyOnLoad(this);
            Logger("Checking basic files");
            WeatherDatabase.BasicSanityCheck();
            WeatherSettings.SettingsFileIntegrityCheck();
            if (WeatherDatabase.BasicFileIntegrityCheck())
            {
                Logger("Integrity check passed, continuing");
            }
            else
            {
                Logger("Integrity check failed, quitting.");
                return;
            }
            //init planet
            WeatherDatabase.LoadInitPlanetaryData();
            WeatherSettings.LoadSettings();
            GameEvents.onGameSceneSwitchRequested.Add(scene =>
            {
                if (scene.from == GameScenes.MAINMENU && scene.to == GameScenes.SPACECENTER)
                {
                    prepToNew = true;
                }
                else if (scene.from == GameScenes.SPACECENTER && scene.to == GameScenes.MAINMENU)
                {
                    prepToDestroy = true;
                    sim           = null;
                    Destroy(this.gameObject.GetComponent <WeatherSimulator>());
                    Destroy(this.gameObject.GetComponent <MapOverlay>());
                    Destroy(this.gameObject.GetComponent <WeatherGUI.WeatherGUI>());
                    prepToDestroy = false;
                }
            });
            GameEvents.onGameStateLoad.Add(node =>
            {
                if (HighLogic.LoadedScene == GameScenes.SPACECENTER && prepToNew)
                {
                    //new up simulator

                    sim = this.gameObject.AddComponent <WeatherSimulator>();
                    this.gameObject.AddComponent <MapOverlay>();
                    this.gameObject.AddComponent <WeatherGUI.WeatherGUI>();
                    prepToNew = false;
                }
                if (HighLogic.LoadedScene == GameScenes.MAINMENU && prepToDestroy)
                {
                    sim = null;
                    Destroy(this.gameObject.GetComponent <WeatherSimulator>());
                    Destroy(this.gameObject.GetComponent <MapOverlay>());
                    Destroy(this.gameObject.GetComponent <WeatherGUI.WeatherGUI>());
                    prepToDestroy = false;
                }
            });
        }
        public CityWeatherControllerTests()
        {
            _mockCityWeatherService = new Mock <ICityWeatherService>();
            WeatherSettings weatherSettings = new WeatherSettings()
            {
                ApiUrl = "some url", ApplicationId = "some id"
            };
            IOptions <WeatherSettings> options = Options.Create(weatherSettings);

            _cityWeatherController = new CityWeatherController(_mockCityWeatherService.Object, options);
        }
Exemplo n.º 10
0
        public WeatherSettings GetWeather(Season season, bool createDefault)
        {
            WeatherSettings settings;

            if (!mWeatherSettings.TryGetValue(season, out settings))
            {
                settings = new WeatherSettings(season, createDefault);
                mWeatherSettings.Add(season, settings);
            }

            return(settings);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Provides command for the skin to change the current location.
        /// </summary>
        /// <param name="item">The location item.</param>
        public void ChangeLocation(ListItem item)
        {
            City city = (City)item.AdditionalProperties[KEY_CITY];

            _preferredLocationCode = city.Id;
            _ = StartBackgroundRefresh(city);

            // also save the last selected city to settings
            WeatherSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <WeatherSettings>();

            settings.LocationCode = city.Id;
            ServiceRegistration.Get <ISettingsManager>().Save(settings);
        }
Exemplo n.º 12
0
 public IHttpActionResult SaveWeatherSettings(string userId, WeatherSettings ws)
 {
     try
     {
         WeatherCrud.SaveSettings(userId, ws);
         return(StatusCode(HttpStatusCode.Accepted));
     }
     catch (Exception e)
     {
         logger.Error(e.Message);
         return(InternalServerError());
     }
 }
Exemplo n.º 13
0
        public override List <ISeasonOption> GetOptions()
        {
            List <ISeasonOption> results = new List <ISeasonOption>();

            WeatherSettings settings = Tempest.Settings.GetWeather(mSeason);

            results.Add(new AddProfile(mSeason));

            foreach (WeatherProfile profile in settings.Profiles)
            {
                results.Add(new Profiles.ListingOption(mSeason, profile));
            }

            return(results);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Saves the current state to the settings file.
        /// </summary>
        public void SaveSettings()
        {
            ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>();
            WeatherSettings  settings        = settingsManager.Load <WeatherSettings>();

            // Apply new locations list
            settings.LocationsList = Locations;
            // Check if preferred location still in list, if not then set the first available
            if (settings.LocationsList.Find(loc => loc.Id == settings.LocationCode) == null && settings.LocationsList.Count > 0)
            {
                settings.LocationCode = settings.LocationsList[0].Id;
            }
            settingsManager.Save(settings);
            WeatherMessaging.SendWeatherMessage(WeatherMessaging.MessageType.LocationChanged);
        }
Exemplo n.º 15
0
        protected void SetLastUpdateTime(DateTime?updateTime)
        {
            WeatherSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <WeatherSettings>();

            settings.LastUpdate = updateTime;
            ServiceRegistration.Get <ISettingsManager>().Save(settings);

            ILocalization localization = ServiceRegistration.Get <ILocalization>();
            CultureInfo   culture      = localization.CurrentCulture;

            string lastUpdate = LocalizationHelper.Translate(LAST_UPDATE_TIME_RES, updateTime.HasValue ?
                                                             updateTime.Value.ToString(culture) : LocalizationHelper.Translate(NOT_UPDATED_YET_RES));

            LastUpdateTime = lastUpdate;
        }
Exemplo n.º 16
0
    private void Awake()
    {
        _time = new TimeSettings();
        _time.DayLengthInMinutes = 2f;
        _time.CurrentDateTime    = new DateTime(2015, 3, 1, 5, 0, 0);
        _time.IsNightSkipped     = false;
        _time.IsTimeSimulated    = true;
        // Lauterbrunnen, Switzerland
        _time.Longitude = -28f;
        _time.Latitude  = 55f;

        _weather = new WeatherSettings();
        _weather.SnowAltitude       = 2750f;
        _weather.IsWeatherSimulated = true;
        _weather.DaysPerSeason      = 2f;
    }
Exemplo n.º 17
0
    private void SetWeatherSettings(WeatherType weatherType)
    {
        currentWeatherSettings = ScriptableObject.CreateInstance <WeatherSettings>();
        currentWeatherSettings.Create(weatherType, skyboxMaterial);

        currentWeatherSettings.UpdateWeather(SecondsOfDay / SecondsPerDay);

        // Rain
        if (weatherType == WeatherType.Rain || weatherType == WeatherType.Thunderstorm)
        {
            rain.SetActive(true);
        }
        else
        {
            rain.SetActive(false);
        }
    }
Exemplo n.º 18
0
        private async Task SendNewSettings(WeatherSettings settings)
        {
            Command cmd = new Command();

            cmd.Program   = GlowPrograms.Weather;
            cmd.MessageId = Command.COMMAND_RECIEVE_SETTINGS;
            cmd.Message   = Newtonsoft.Json.JsonConvert.SerializeObject(settings);

            try
            {
                await App.GlowBack.ConnectionManager.SendCommand(cmd);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Failed to send weather settings " + e.Message);
            }
        }
Exemplo n.º 19
0
        public void SaveWeatherSettings(WeatherSettings ws)
        {
            using (var db = new DefaultContext())
            {
                WeatherSettings currentWeatherSettings = db.WeatherSettings.SingleOrDefault(x => x.Pk_WeatherId == ws.Pk_WeatherId);
                currentWeatherSettings.Enabled    = ws.Enabled;
                currentWeatherSettings.Farenheit  = ws.Farenheit;
                currentWeatherSettings.Cloudiness = ws.Cloudiness;
                currentWeatherSettings.Humidity   = ws.Humidity;
                currentWeatherSettings.WindSpeed  = ws.WindSpeed;
                currentWeatherSettings.Location   = ws.Location;

                db.WeatherSettings.Attach(currentWeatherSettings);
                db.Entry(currentWeatherSettings).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Exemplo n.º 20
0
        // Updates the settings given a settings command.
        private void UpdateSettings(Command command)
        {
            // Get the settings from the message
            WeatherSettings newSettings = Newtonsoft.Json.JsonConvert.DeserializeObject <WeatherSettings>(command.Message);

            if (newSettings == null)
            {
                return;
            }

            // Update the location if needed
            if (m_settings.CurrentLocation.State != newSettings.CurrentLocation.State ||
                m_settings.CurrentLocation.City != newSettings.CurrentLocation.City)
            {
                m_settings.CurrentLocation = newSettings.CurrentLocation;
                UpdateWeather();
            }
        }
Exemplo n.º 21
0
        public static void UpdateAttributes(List <Organism> organisms, WeatherSettings weatherSettings, Boolean SimulationTick, TimeManager timeManager)
        {
            Organism organism;

            for (var i = organisms.Count - 1; i >= 0; i--)
            {
                organism = organisms[i];
                if (SimulationTick)
                {
                    if (timeManager.HasWeatherCooldownExpired(organism))
                    {
                        UpdateWeatherAttribute(organism, weatherSettings);
                    }
                    UpdateHungerAttribute(organism);
                    UpdateAgeAttribute(organism);
                }
                timeManager.UpdateOrganismTimers(organism);
            }
        }
Exemplo n.º 22
0
        protected WeatherProfile GetProfile(XmlDbRow row)
        {
            WeatherSettings settings = GetSeason(row);

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

            string name = row.GetString("Name");

            if (string.IsNullOrEmpty(name))
            {
                BooterLogger.AddError("Missing Name");
                return(null);
            }

            return(settings.AddProfile(name));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Check if the weather has already been configured once by the user (so we only prompt on first use).
        /// </summary>
        public void CheckWeatherConfigured()
        {
            // Check is there's any settings (even empty) that have been saved before, if not trigger first run setup.
            ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>();
            WeatherSettings  settings        = settingsManager.Load <WeatherSettings>();

            if (settings.LocationsList != null)
            {
                return;
            }

            ServiceRegistration.Get <ILogger>().Debug("WeatherModel: Not initialized, entering setup.");

            // Create the configuration file so we won't trigger the setup again.
            settings = new WeatherSettings();
            settings.LocationsList = new List <CitySetupInfo>();
            ServiceRegistration.Get <ISettingsManager>().Save(settings);

            // Prompt to setup the weather plugin.
            ServiceRegistration.Get <IWorkflowManager>().NavigatePushAsync(new Guid("F1CE62B4-32CA-46e8-BCFB-250FE07911B2"));
        }
Exemplo n.º 24
0
        protected void ReadSettings(bool shouldFire)
        {
            // add citys from settings to the locations list
            WeatherSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <WeatherSettings>();

            if (settings == null || settings.LocationsList == null)
            {
                return;
            }

            _preferredLocationCode = settings.LocationCode;
            _refreshIntervalSec    = settings.RefreshInterval;
            SetLastUpdateTime(settings.LastUpdate);

            _locations.Clear();
            _locationsList.Clear();
            foreach (CitySetupInfo loc in settings.LocationsList)
            {
                City city = AddCityToLocations(loc);
                if (loc.Id == _preferredLocationCode)
                {
                    StartBackgroundRefresh(city);
                }
            }

            // if there is no city selected until yet, choose the first one
            if (settings.LocationCode.Equals("<none>") && _locations.Count > 0)
            {
                // Fetch data in background
                _preferredLocationCode = _locations[0].Id;
                StartBackgroundRefresh(_locations[0]);
            }

            // we've added new citys, so update the locations collection
            if (shouldFire)
            {
                _locationsList.FireChange();
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Given <see cref="WeatherSettings"/>, retrieves radar images, overlays them, saves them in the <see cref="IStore"/> under the specified container, and
        /// returns an <see cref="AttachmentResponse"/> with an SAS URI that will expire after <paramref name="sasUriExpiration"/>
        /// </summary>
        /// <param name="settings">The settings to use to determine what images to retrieve.</param>
        /// <param name="blobStore">The storage to use to store images for later retrieval.</param>
        /// <param name="blobContainer">The container in the storage to store the image blobs in.</param>
        /// <param name="sasUriExpiration">The time that the blobs should expire in after <see cref="DateTime.UtcNow"/></param>
        /// <returns>A response with a SAS URI to access the images in PNG format.</returns>
        public static async Task <AttachmentResponse> GetRadarImageAsync(WeatherSettings settings, IStore blobStore, string blobContainer, TimeSpan sasUriExpiration)
        {
            List <Image> images = new List <Image>();

            foreach (RadarLayerType layer in settings.LayerStack.RadarLayers)
            {
                Image image = await LayerRetriever.GetImageAsync(RadarLayerUris.GetRadarLayerUri(settings.Station, layer)).ConfigureAwait(false);

                if (image != null)
                {
                    images.Add(image);
                }
            }

            Image compositeImage = ImageUtils.OverlayImages(images);

            string blobId = $"{DateTime.UtcNow.ToString("o")}-{Guid.NewGuid()}";
            await blobStore.CreateOrUpdateAsync(blobContainer, blobId, (stream) => { compositeImage.Save(stream, ImageFormat.Png); return(Task.CompletedTask); }).ConfigureAwait(false);

            string uri = await blobStore.GetBlobSasUriAsync(blobContainer, blobId, sasUriExpiration).ConfigureAwait(false);

            return(new AttachmentResponse(uri, LayerRetriever.PngMimeType, $"{settings.Station.ToUpper()} weather"));
        }
Exemplo n.º 26
0
        public void WeatherBusinessToData()
        {
            //Arrange
            WeatherSettings ws = new WeatherSettings
            {
                enabled    = false,
                humidity   = true,
                cloudiness = true,
                windSpeed  = false
            };

            //Act
            Data.Models.WeatherSettings wsData = (Data.Models.WeatherSettings)ws;
            bool param1 = false;
            bool param2 = true;
            bool param3 = true;
            bool param4 = false;

            //Assert
            Assert.AreEqual(wsData.Enabled, param1);
            Assert.AreEqual(wsData.Humidity, param2);
            Assert.AreEqual(wsData.Cloudiness, param3);
            Assert.AreEqual(wsData.WindSpeed, param4);
        }
Exemplo n.º 27
0
        public void WeatherDataToBusiness()
        {
            //Arrange
            Data.Models.WeatherSettings wsData = new Data.Models.WeatherSettings()
            {
                Enabled    = false,
                Humidity   = true,
                Cloudiness = true,
                WindSpeed  = false
            };

            //Act
            WeatherSettings ws     = (WeatherSettings)wsData;
            bool            param1 = false;
            bool            param2 = true;
            bool            param3 = true;
            bool            param4 = false;

            //Assert
            Assert.AreEqual(ws.enabled, param1);
            Assert.AreEqual(ws.humidity, param2);
            Assert.AreEqual(ws.cloudiness, param3);
            Assert.AreEqual(ws.windSpeed, param4);
        }
Exemplo n.º 28
0
 public void SaveWeatherSettings(WeatherSettings ws)
 {
     utility.SaveWeatherSettings(ws);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Loads all locations from the settings.
        /// </summary>
        private void GetLocationsFromSettings()
        {
            WeatherSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <WeatherSettings>();

            Locations = settings.LocationsList ?? new List <CitySetupInfo>();
        }
 public static void UpdateWeather(int index, WeatherSettings settings)
 {
     WeatherData[index] = settings;
 }