Esempio n. 1
0
        //public bool IsAtTemperatureThreshold
        //{
        //	get
        //	{
        //		foreach (TemperatureThreshold temperatureThreshold in _temperatureThresholdList)
        //		{
        //			Temperature.ResetToleranceToDefault();
        //			bool previouslyAtThisThreshold = temperatureThreshold == CurrentTemperatureThreshold;

        //			// If previously at this threshold, then set "wider" tolerance for this threshold to reduce fluctuations
        //			if (previouslyAtThisThreshold)
        //			{
        //				Temperature.Tolerance = temperatureThreshold.Tolerance;
        //			}

        //			if (_temperature == temperatureThreshold.Temperature)
        //			{
        //				if (previouslyAtThisThreshold)
        //				{
        //					_eventHandlerFiredForTemperatureThreshold = true;
        //					return true;
        //				}

        //				TemperatureDirection temperatureDirection = _temperature >= _previousTemperature ? TemperatureDirection.Increasing : TemperatureDirection.Decreasing;
        //				bool isSameTemperatureDirection = temperatureDirection == temperatureThreshold.Direction;

        //				if (isSameTemperatureDirection)
        //				{
        //					CurrentTemperatureThreshold = temperatureThreshold;
        //					_eventHandlerFiredForTemperatureThreshold = false;

        //				}

        //				return isSameTemperatureDirection;
        //			}
        //		}

        //		return false;
        //	}
        //}

        public bool PassedThroughTemperatureThreshold(TemperatureThreshold temperatureThreshold)
        {
            Temperature          thresholdTemperature = temperatureThreshold.Temperature;
            TemperatureDirection thresholdDirection   = temperatureThreshold.Direction;

            bool passedThroughThreshold = _previousTemperature <= thresholdTemperature && thresholdTemperature <= _temperature;
            bool rightDirection         = _previousTemperature <= _temperature && thresholdDirection == TemperatureDirection.Increasing;

            return(passedThroughThreshold && rightDirection);
        }
Esempio n. 2
0
 public void AddThreshold(TemperatureThreshold temperatureThreshold)
 {
     _temperatureThresholdList.Add(temperatureThreshold);
 }
Esempio n. 3
0
        private void CheckTemperatureThreshold(double temperature, double previousTemperature, TemperatureThreshold temperatureThreshold)
        {
            // Increase tolerance once at threshold
            var tolerance = !temperatureThreshold.IsAtThreshold ? .001 : temperatureThreshold.Tolerance;

            // Check if the temperatures are equal to within the threshold tolerance
            bool areTemperaturesEqualWinthinTolerance = AreEqualWithinTolerance(temperature, temperatureThreshold.Temperature, tolerance);

            // If the temperatures are not approximately equal, then set the threshold triggered to false
            if (!areTemperaturesEqualWinthinTolerance)
            {
                temperatureThreshold.IsAtThreshold = false;
                return;
            }

            bool isAtThreshold = temperatureThreshold.IsAtThreshold;
            TemperatureDirection temperatureDirection = ((temperature > previousTemperature) ? TemperatureDirection.Increasing : TemperatureDirection.Decreasing);
            bool isSameTemperatureDirection = (temperatureDirection == temperatureThreshold.Direction);

            // Once at a threshold temperature, the alert is generated only if
            // 1) the threshold has not been reached
            // 2) the direct of the temperature change is consistent with the threshold
            if (!isAtThreshold && isSameTemperatureDirection)
            {
                temperatureThreshold.IsAtThreshold = true;
                OnTemperatureThresholdReached(new TemperatureThresholdEventArgs(temperatureThreshold));
            }
        }
 public TemperatureThresholdEventArgs(TemperatureThreshold temperatureThreshold)
 {
     TemperatureThreshold = temperatureThreshold;
 }
 public TemperatureThresholdEventArgs(TemperatureThreshold temperatureThreshold)
 {
     TemperatureThreshold = temperatureThreshold;
 }