コード例 #1
0
        public bool TryToGetWeather(WeatherType type, [CanBeNull] ref WeatherObject weather)
        {
            if (type == WeatherType.None)
            {
                return(true);
            }

            try {
                var candidates = WeatherManager.Instance.LoadedOnly.Where(x => x.Enabled && x.TemperatureDiapason?.DiapasonContains(_temperature) != false &&
                                                                          x.TimeDiapason?.TimeDiapasonContains(_time) != false).ToList();
                var closest = WeatherDescription.FindClosestWeather(from w in candidates select w.Type, type);
                if (closest == null)
                {
                    return(false);
                }

                candidates = candidates.Where(x => x.Type == closest).ToList();
                var footprint = candidates.Select(x => x.Id).JoinToString(';');
                if (footprint != _weatherCandidatesFootprint || !candidates.Contains(weather))
                {
                    weather = candidates.RandomElementOrDefault();
                    _weatherCandidatesFootprint = footprint;
                }

                return(true);
            } catch (Exception e) {
                Logging.Error(e);
                return(false);
            }
        }
コード例 #2
0
        public void FindClosestTest()
        {
            var         values = Enum.GetValues(typeof(WeatherType)).OfType <WeatherType>().ToArray();
            WeatherType?result = null;

            foreach (var type in values)
            {
                for (var i = 1; i < values.Length; i++)
                {
                    result = WeatherDescription.FindClosestWeather(GoodShuffle.Get(values).Take(i), type);
                }
            }

            Console.WriteLine($"result: {result}");
        }