Ejemplo n.º 1
0
        /// <summary>
        /// Records a fuse activity.
        /// </summary>
        /// <param name="timestamp">The time associated with the volume passing through the fuse.</param>
        /// <param name="volume">(float) the amount of volume (activity) to record.</param>
        /// <returns>Enumeration describing what tripped the fuse: nothing, or any combination of hits and volume</returns>
        public FuseTrip RecordFuseEvent(float volume, DateTime timestamp)
        {
            FuseTrip result        = FuseTrip.None;
            DateTime now           = timestamp;     // fixes a point in time over several evals
            DateTime oldestTrigger = now.Add(-_Time_Frame);

            // remove and clear any activity outside the timeframe we analyse.
            while (_Triggers.Count > 0 && _Triggers.Peek().Occurred_On < oldestTrigger)
            {
                FuseEvent f = _Triggers.Dequeue();
                _Hits--;
                _Volume -= f.Volume;
            }
            _Triggers.Enqueue(new FuseEvent(now, volume));
            _Hits++;
            _Volume += volume;
            switch (_Fuse_Trigger_Rule)
            {
            case FuseBehavior.Hits_Only:
                result = _Hits > _Hit_Threshold ? FuseTrip.Hits : FuseTrip.None;
                break;

            case FuseBehavior.Volume_Only:
                result = _Volume > _Volume_Threshold ? FuseTrip.Volume : FuseTrip.None;
                break;

            case FuseBehavior.Hits_OR_Volume:
                result = (_Hits > _Hit_Threshold && _Volume > _Volume_Threshold)
                                                ? FuseTrip.HitsAndVolume :
                         (_Hits > Hit_Threshold ? FuseTrip.Hits :
                          (_Volume >= _Volume_Threshold ? FuseTrip.Volume : FuseTrip.None));
                break;

            case FuseBehavior.Hits_AND_Volume:
                result = (_Hits > _Hit_Threshold && _Volume > _Volume_Threshold)
                                                ? FuseTrip.HitsAndVolume : FuseTrip.None;
                break;
            }
            if (result != FuseTrip.None && _Auto_Reset_On_Trigger)
            {
                Reset();
            }
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Load the event from an existing one.  Allows an existing FuseEvent class to be recycled.
 /// </summary>
 /// <param name="p_obj"></param>
 public void Load(FuseEvent p_obj)
 {
     this._Occurred_On = p_obj.Occurred_On;
     this._Volume      = p_obj.Volume;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new fuse event from an existing one.
 /// </summary>
 /// <param name="p_obj">The existing event</param>
 public FuseEvent(FuseEvent p_obj)
 {
     Load(p_obj);
 }