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);
        }
Beispiel #2
0
        public void PercentOverThreshold(int minutes, byte threshold, float expected)
        {
            var now    = DateTime.Now;
            var record = new TemperatureRecord(TimeSpan.FromMinutes(40));

            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);

            var percent = record.RecentPercentOverThreshold(TimeSpan.FromMinutes(minutes), threshold);

            Assert.Equal(expected, percent);
        }