コード例 #1
0
        /// <summary>
        /// Function handling the loop to get the requested number of weather results
        /// </summary>
        private static List <WeatherResult> GetResults(
            WeatherParameters parameters, string weather, string previousWeather,
            int weatherStartHour, DateTime weatherStart)
        {
            var tries   = 0;
            var matches = 0;
            var results = new List <WeatherResult>();

            while (tries < parameters.MaxTries && matches < parameters.MaxMatches)
            {
                if (ParametersMatchWindow(parameters, weather, previousWeather, weatherStartHour))
                {
                    results.Add(new WeatherResult
                    {
                        Zone            = parameters.Zone,
                        CurrentWeather  = weather,
                        PreviousWeather = previousWeather,
                        StartTime       = weatherStartHour.ToString(),
                        TimeOfWeather   = weatherStart
                    });
                    matches++;
                }

                weatherStart     = weatherStart.AddSeconds(EorzeaHoursPerWeatherWindow * SecondsPerEorzeaHour);
                weatherStartHour = GetEorzeaHour(weatherStart);
                previousWeather  = weather;
                weather          = GetWeatherNameForTime(weatherStart, parameters.Zone);
                tries++;
            }

            return(results);
        }
コード例 #2
0
        double Delta_t(double Height, double MachNumber, double Length, double K_s, WeatherParameters WeatherParameters)
        {
            double a = 20.046796 * Math.Sqrt(Atmosphere.ParametersAtHeight(Height, WeatherParameters.Temperature).Temperature);

            return(K_t(Height, MachNumber) * 3.42 / a * MachNumber / Math.Pow(Math.Pow(MachNumber, 2) - 1, 3.0 / 8) *
                   Math.Pow(Math.Max(h_e(Height, MachNumber), Height), 1.0 / 4) * Math.Pow(Length, 3.0 / 4) * K_s);
        }
コード例 #3
0
        public static double[] Propagation(double[] Frequencies, WeatherParameters weatherParameters, double Height, double DistanceToGround) //Функция, возвращающая значения затуханий звука вследствие звукополгощения для заданных частот
        {
            // Frequencies -- массив частот
            // Height -- расстояние источника шума от Земли по вертикали
            // DistanceToGround -- расстоянии от источника шума до наблюдателя на Земле
            int N = 20;                                                                // Число разбиений отрезка, соединяющего наблюдателя и источник шума

            AtmosphereParameters[] atmosphereParameters = new AtmosphereParameters[N]; // Параметры атмосферы на участках отрезка, соединяющего наблюдателя и источник шума
            double[] Humidity = new double[N];                                         // Массив относительных влажностей вохдуха на участках отрезка, соединяющего наблюдателя и источник шума
            for (int i = 0; i < N; i++)                                                // Заполнение массивов atmosphereParameters и Humidity
            {
                atmosphereParameters[i] = ParametersAtHeight(i * Height / N, weatherParameters.Temperature);
                Humidity[i]             = weatherParameters.Humidity * Math.Pow(10,
                                                                                -0.0387 * (weatherParameters.Temperature - atmosphereParameters[i].Temperature) -
                                                                                6.8346 * (Math.Pow(273.16 / weatherParameters.Temperature, 1.261) -
                                                                                          Math.Pow(273.16 / atmosphereParameters[i].Temperature, 1.261)));
            }
            double[] atmospherePropagation = new double[Frequencies.Length]; // Массив значений затухания звука
            for (int j = 0; j < Frequencies.Length; j++)                     // Заполнение массива atmospherePropagation
            {
                double currentPropogation = 0;
                for (int i = 0; i < N; i++) // Суммирование затуханий звука при частоте Frequencies[j] на участках отрезка, соединяющего наблюдателя и источник шума
                {
                    currentPropogation += AbsorptionRatio(Humidity[i], atmosphereParameters[i], Frequencies[j]) * DistanceToGround / N;
                }
                atmospherePropagation[j] = currentPropogation;
            }
            return(atmospherePropagation);
        }
コード例 #4
0
 public WeatherParameters(WeatherParameters c)
 {
     this.WeatherType         = c.WeatherType;
     this.BaseValue           = c.BaseValue;
     this.ChangeRate          = c.ChangeRate;
     this.VariableLowerBound  = c.VariableLowerBound;
     this.VariableHigherBound = c.VariableHigherBound;
 }
コード例 #5
0
 private void FlightNoiseWeatherParametersButton_Click(object sender, EventArgs e)
 {
     if (FlightNoiseWeatherParameters == null)
     {
         FlightNoiseWeatherParameters = new List <WeatherParameters>();
     }
     if (sender == AddFlightNoiseWeatherParameterButton)
     {
         if (FlightNoiseWeatherParameters.FindIndex(x => x.Mounth == textBox1.Text) != -1)
         {
             MessageBox.Show("Погодные условия с указанным наименованием уже существуют");
             return;
         }
         FlightNoiseWeatherParameters.Add(new WeatherParameters(
                                              textBox1.Text,
                                              Convert.ToDouble(textBox3.Text),
                                              Convert.ToDouble(textBox2.Text) + 273));
         FlightNoiseWeatherParametersListBox.Items.Add(textBox1.Text);
     }
     else if (sender == ModifyFlightNoiseWeatherParameterButton)
     {
         int Selected = FlightNoiseWeatherParametersListBox.SelectedIndex;
         if (Selected == -1)
         {
             return;
         }
         int FirstEqual = FlightNoiseWeatherParameters.FindIndex(x => x.Mounth == textBox1.Text);
         if ((FirstEqual == Selected) || (FirstEqual == -1))
         {
             var weatherParameter = new WeatherParameters(
                 textBox1.Text,
                 Convert.ToDouble(textBox3.Text),
                 Convert.ToDouble(textBox2.Text) + 273);
             FlightNoiseWeatherParameters[Selected] = weatherParameter;
             FlightNoiseWeatherParametersListBox.Items[Selected] = textBox1.Text;
         }
         else
         {
             MessageBox.Show("Погодные условия с указанным наименованием уже существуют");
             return;
         }
     }
     else if (sender == DeleteFlightNoiseWeatherParameterButton)
     {
         int Selected = FlightNoiseWeatherParametersListBox.SelectedIndex;
         if (Selected == -1)
         {
             return;
         }
         FlightNoiseWeatherParameters.RemoveAt(Selected);
         FlightNoiseWeatherParametersListBox.Items.RemoveAt(Selected);
     }
     else if (sender == ApplyFlightNoiseWeatherParameterButton)
     {
         ApplyFlightNoiseWeatherParameters(FlightNoiseWeatherParameters);
     }
 }
コード例 #6
0
        public IHttpActionResult WeatherInformation([FromUri] LocationModel location)
        {
            try
            {
                if (location != null && location.HasLocation)
                {
                    var weatherservice = UnityConfig
                                         .GetConfiguredContainer()
                                         .ResolveAll <IWeatherService>()
                                         .Where(x => x.IsUnderThresholdLimit)
                                         .OrderBy(x => x.UnsuccessfulCalls).ThenBy(x => x.NumberOfQueriesMade)
                                         .FirstOrDefault();

                    //parameters for the service
                    var wparams = new WeatherParameters
                    {
                        Latitude    = location.Latitude,
                        Longitude   = location.Longitude,
                        City        = location.City,
                        Region      = location.Region,
                        RegionCode  = location.RegionCode,
                        Country     = location.Country,
                        CountryCode = location.CountryCode,
                    };

                    //finds weather information
                    var m = weatherservice.Weather(wparams);

                    //And because not every weather provider works the same way, we need to check if forecast info
                    //needs to be obtained as well

                    if (weatherservice.ProvidesForecastWithoutAnotherCall == false)
                    {
                        //I don't recall the same weather service, because it can be maxed out

                        var forecastservice = UnityConfig
                                              .GetConfiguredContainer()
                                              .ResolveAll <IWeatherService>()
                                              .Where(x => x.IsUnderThresholdLimit)
                                              .OrderBy(x => x.UnsuccessfulCalls).ThenBy(x => x.NumberOfQueriesMade)
                                              .FirstOrDefault();

                        m.Forecast = forecastservice.Forecast(wparams);
                    }

                    return(Ok(m));
                }
            }
            catch
            {
                return(InternalServerError());
            }

            return(NotFound());
        }
コード例 #7
0
        /// <summary>
        /// Given a zone and desired weather/pre conditions, find up to the specified
        /// number of occurrences within the indicated number of windows.
        /// </summary>
        public static List <WeatherResult> GetUpcomingWeatherResults(
            WeatherParameters parameters)
        {
            var date             = DateTime.UtcNow;
            var weatherStart     = GetWeatherTimeFloor(date);
            var weatherStartHour = GetEorzeaHour(weatherStart);

            var weather         = GetWeatherNameForTime(weatherStart, parameters.Zone);
            var previousWeather = GetWeatherNameForTime(weatherStart.AddSeconds((EorzeaHoursPerWeatherWindow * SecondsPerEorzeaHour) * -1.0), parameters.Zone);

            return(GetResults(parameters, weather, previousWeather, weatherStartHour, weatherStart));
        }
コード例 #8
0
        /// <summary>
        /// Checks whether the desired conditions in parameters match the window being tested.
        /// </summary>
        private static bool ParametersMatchWindow(
            WeatherParameters parameters, string weather,
            string previousWeather, int weatherStartHour)
        {
            var weatherMatch = !parameters.DesiredWeather.Any() ||
                               parameters.DesiredWeather.Any(x => x == weather);
            var previousWeatherMatch = !parameters.DesiredPreviousWeather.Any() ||
                                       parameters.DesiredPreviousWeather.Any(x => x == previousWeather);
            var timeMatch = !parameters.DesiredTimes.Any() ||
                            parameters.DesiredTimes.Any(x => weatherStartHour.ToString() == x);

            return(weatherMatch && previousWeatherMatch && timeMatch);
        }
コード例 #9
0
        public IActionResult TemperatureByCity(WeatherParameters parameters)
        {
            string city = parameters.city;

            if (string.IsNullOrEmpty(city))
            {
                return(NoContent());
            }

            //throw new NotImplementedException();

            var result = _weather.getTemperatureByCity(city);

            return(Ok(result));
        }
コード例 #10
0
        double Delta_p(double Height, double MachNumber, double Length, double K_s, WeatherParameters WeatherParameters)
        {
            double _M_e = M_e(MachNumber);
            double d    = d_x(Height, MachNumber);
            double _H_e = Math.Max(d, Height);

            if (_M_e < M_c(MachNumber))
            {
                return(0);
            }
            else
            {
                return(Math.Max(2 * K_p(Height, MachNumber) * Math.Sqrt(1.0135E5 * Atmosphere.ParametersAtHeight(Height, WeatherParameters.Temperature).Pressure) *
                                Math.Pow(Math.Pow(MachNumber, 2) - 1, 1.0 / 8) * Math.Pow(Length / _H_e, 3.0 / 4) * K_s * Delta_atm(Height, d, WeatherParameters), 0));
            }
        }
コード例 #11
0
        public async Task <ActionResult <JeffShared.ViewModel.Weather> > Get([FromQuery] WeatherParameters data)
        {
            var cacheKey          = $"FORECAST_{data.Name}";
            var weatherParameters = _cities.FirstOrDefault(c => c.Name.ToLower() == data.Name.ToLower());

            if (!_cache.TryGetValue(cacheKey, out JeffShared.ViewModel.Weather weather))
            {
                var weatherData = await _weatherService.GetForecast($"{ weatherParameters.Name},{weatherParameters.Country}");

                weather       = _mapper.Map <JeffShared.ViewModel.Weather>(weatherData);
                weather.Query = weatherParameters;
                // Save data in cache.
                _cache.Set(cacheKey, weather, _cacheExpirationOptions);
            }

            return(weather);
        }
コード例 #12
0
        /// <summary>
        /// Get the upcoming weather forecast for the specified region
        /// </summary>
        /// <param name="region"></param>
        /// <returns></returns>
        public static RegionForecast GetWeatherForecastForRegion(string region)
        {
            var forecast   = new RegionForecast(region);
            var zones      = GetZonesForRegion(region);
            var parameters = new WeatherParameters
            {
                MaxMatches = 25,
                MaxTries   = 25
            };

            foreach (var zone in zones)
            {
                parameters.Zone = zone;
                var order   = GetOrderForZone(zone);
                var results = GetUpcomingWeatherResults(parameters);
                forecast.AddZoneForecast(zone, order, results);
            }

            return(forecast);
        }
コード例 #13
0
        /// <summary>
        /// Gets the weather results to display.
        /// </summary>
        private List <WeatherResult> GetWeatherResults()
        {
            var zone     = _view.FindViewById <Spinner>(Resource.Id.ZoneSpinner).SelectedItem.ToString();
            var dWeather = GetSelectedWeather(_view.FindViewById <MultiSelectionSpinner>(Resource.Id.DesiredSpinner));
            var pWeather = GetSelectedWeather(_view.FindViewById <MultiSelectionSpinner>(Resource.Id.PreviousSpinner));
            var dMatches = (int)_view.FindViewById <Spinner>(Resource.Id.MaximumMatches).SelectedItem;
            var dWindows = (int)_view.FindViewById <Spinner>(Resource.Id.MaximumWindows).SelectedItem;
            var times    = GetSelectedTimes();

            var parameters = new WeatherParameters
            {
                Zone                   = zone,
                DesiredWeather         = dWeather,
                DesiredPreviousWeather = pWeather,
                DesiredTimes           = times,
                MaxTries               = dWindows,
                MaxMatches             = dMatches
            };

            return(WeatherService.GetUpcomingWeatherResults(parameters));
        }
コード例 #14
0
ファイル: MainForm.cs プロジェクト: efendievm/RocketNoise
 public WeatherParametersContainer(
     TextBox NameTextBox,
     TextBox HumidityTextBox,
     TextBox TemperatureTextBox,
     Button AddButton,
     Button ModifyButton,
     Button DeleteButton,
     Button ApplyButton,
     ListBox WeatherParametersListBox,
     Action <List <WeatherParameters> > Apply)
 {
     this.WeatherParametersListBox = WeatherParametersListBox;
     AddButton.Click += (sender, e) =>
     {
         if (weatherParameters == null)
         {
             weatherParameters = new List <WeatherParameters>();
         }
         if (weatherParameters.FindIndex(x => x.Mounth == NameTextBox.Text) != -1)
         {
             MessageBox.Show("Погодные условия с указанным наименованием уже существуют");
             return;
         }
         weatherParameters.Add(new WeatherParameters(
                                   NameTextBox.Text,
                                   Convert.ToDouble(HumidityTextBox.Text),
                                   Convert.ToDouble(TemperatureTextBox.Text) + 273));
         WeatherParametersListBox.Items.Add(NameTextBox.Text);
     };
     ModifyButton.Click += (sender, e) =>
     {
         int Selected = WeatherParametersListBox.SelectedIndex;
         if (Selected == -1)
         {
             return;
         }
         int FirstEqual = weatherParameters.FindIndex(x => x.Mounth == NameTextBox.Text);
         if ((FirstEqual == Selected) || (FirstEqual == -1))
         {
             var weatherParameter = new WeatherParameters(
                 NameTextBox.Text,
                 Convert.ToDouble(HumidityTextBox.Text),
                 Convert.ToDouble(TemperatureTextBox.Text) + 273);
             weatherParameters[Selected] = weatherParameter;
             WeatherParametersListBox.Items[Selected] = NameTextBox.Text;
         }
         else
         {
             MessageBox.Show("Погодные условия с указанным наименованием уже существуют");
             return;
         }
     };
     DeleteButton.Click += (sender, e) =>
     {
         int Selected = WeatherParametersListBox.SelectedIndex;
         if (Selected == -1)
         {
             return;
         }
         weatherParameters.RemoveAt(Selected);
         WeatherParametersListBox.Items.RemoveAt(Selected);
     };
     ApplyButton.Click += (sender, e) => Apply(weatherParameters);
     WeatherParametersListBox.Click += (sender, e) =>
     {
         if (WeatherParametersListBox.SelectedIndex == -1)
         {
             return;
         }
         var SelectedWeatherParameters = weatherParameters[WeatherParametersListBox.SelectedIndex];
         NameTextBox.Text        = SelectedWeatherParameters.Mounth;
         TemperatureTextBox.Text = FormatConvert.ToString(SelectedWeatherParameters.Temperature - 273);
         HumidityTextBox.Text    = FormatConvert.ToString(SelectedWeatherParameters.Humidity);
     };
 }
コード例 #15
0
        double Delta_atm(double Height, double DistanceToGround, WeatherParameters WeatherParameters)
        {
            var atmospherePropagation = Atmosphere.Propagation(SonicBoomFrequencies, WeatherParameters, Height, DistanceToGround);

            return(Math.Pow(10, 10 * Math.Log10(atmospherePropagation.Select(x => Math.Pow(10, -0.1 * x)).Sum() / SonicBoomFrequencies.Length) / 20));
        }