示例#1
0
        public bool Evaluate(out byte speed)
        {
            var temp = _temperature.RecentMaximum(TimeSpan.FromSeconds(15));

            if (_currentMode == Mode.Idling)
            {
                var overheatAlpha         = Mathf.Clamp((_maxTemperature - temp) / (float)(_maxTemperature - _overheatThreshold), 0, 1);
                var overheatTimeAllowance = _maxOverheatAllowance * overheatAlpha;

                if (_temperature.RecentPercentOverThreshold(overheatTimeAllowance, _overheatThreshold) > 0.9)
                {
                    _currentMode = Mode.SustainedLoad;
                }
            }
            else
            {
                if (_temperature.RecentPercentOverThreshold(_maxOverheatAllowance, _overheatThreshold) < 0.1)
                {
                    _currentMode = Mode.Idling;
                }
            }

            if (_currentMode == Mode.Idling)
            {
                speed = (byte)_quietProfile.Evaluate(temp);
            }
            else
            {
                speed = (byte)_sustainedProfile.Evaluate(temp);
            }

            return(temp <= _maxTemperature);
        }
示例#2
0
        public void RecentWhenNewyReturnsZero()
        {
            var record = new TemperatureRecord(TimeSpan.FromMinutes(5));
            var recent = record.RecentMaximum(TimeSpan.FromSeconds(5));

            Assert.Equal(0, recent);
        }
示例#3
0
        public void RecentWhenOldReturnsLast()
        {
            var record = new TemperatureRecord(TimeSpan.FromMinutes(5));

            record.Push(DateTime.Now - TimeSpan.FromMinutes(30), 50);
            record.Push(DateTime.Now - TimeSpan.FromMinutes(25), 55);

            var recent = record.RecentMaximum(TimeSpan.FromSeconds(5));

            Assert.Equal(55, recent);
        }
示例#4
0
        public void RecentReturnsMostRecentOnly()
        {
            var now    = DateTime.Now;
            var record = new TemperatureRecord(TimeSpan.FromMinutes(5));

            record.Push(now - TimeSpan.FromMinutes(30), 55);
            record.Push(now - TimeSpan.FromMinutes(25), 54);
            record.Push(now - TimeSpan.FromMinutes(10), 53);
            record.Push(now - TimeSpan.FromMinutes(4), 52);
            record.Push(now - TimeSpan.FromMinutes(3), 51);
            record.Push(now - TimeSpan.FromMinutes(2), 50);

            var recent = record.RecentMaximum(TimeSpan.FromMinutes(5));

            Assert.Equal(52, recent);
        }