コード例 #1
0
 internal void AddValue(string fieldName, double value, DateTime timestamp)
 {
     if (StatisticsLogger.IsValidField(fieldName))
     {
         // add value for StatisticsLogger use
         statValues.Add(new StatValue(value, timestamp));
     }
     // "value" is the occurring event in this very moment,
     // so "Current" is holding previous value right now
     if (Current.Value != value)
     {
         if (value == 0 && lastEvent.Value > 0)
         {
             lastOn  = lastEvent;
             lastOff = new StatValue(value, timestamp);
         }
         else if (value > 0 && lastEvent.Value == 0)
         {
             lastOff = lastEvent;
             lastOn  = new StatValue(value, timestamp);
         }
         lastEvent = new StatValue(Current.Value, Current.Timestamp);
     }
     // insert current value into history and so update "Current" to "value"
     historyValues.Insert(0, new StatValue(value, timestamp));
     // keeep size within historyLimit
     while (historyValues.Count > historyLimit)
     {
         historyValues.RemoveAt(historyValues.Count - 1);
     }
 }
コード例 #2
0
 public ValueStatistics()
 {
     LastProcessedTimestap = DateTime.UtcNow;
     statValues            = new List <StatValue>();
     statValues.Add(new StatValue(0, LastProcessedTimestap));
     lastEvent = lastOn = lastOff = new StatValue(0, LastProcessedTimestap);
     historyValues.Add(lastEvent);
     while (historyValues.Count > historyLimit)
     {
         historyValues.RemoveAt(historyValues.Count - 1);
     }
 }