public override void CalculateValue(double value, DateTime timestamp) { GaugeDuration aggregateDuration = base.aggregateDuration; if (aggregateDuration.IsEmpty || ((IValueConsumer)this).GetProvider() == null) { base.CalculateValue(value, timestamp); } else { base.noMoreData = false; HistoryCollection data = ((IValueConsumer)this).GetProvider().GetData(aggregateDuration, timestamp); HistoryEntry[] array = data.Select(aggregateDuration, timestamp); double num = value; bool flag = false; HistoryEntry[] array2 = array; foreach (HistoryEntry historyEntry in array2) { if (!double.IsNaN(historyEntry.Value)) { num = Math.Max(historyEntry.Value, num); flag = true; } } if (!flag) { num = ((data.Count <= 0) ? double.NaN : data.Top.Value); base.noMoreData = true; } base.CalculateValue(num, timestamp); } }
HistoryCollection IValueProvider.GetData(GaugeDuration period, DateTime currentDate) { if (this.History.Count > 0) { this.queryDept.Extend(period, currentDate, this.History[0].Timestamp); } return(this.History); }
public virtual void Reset() { this.History.Clear(); this.queryDept = new GaugeDuration(this.historyDept.Count, this.historyDept.DurationType); foreach (IValueConsumer consumer in this.consumers) { consumer.Reset(); } }
public HistoryEntry[] Select(GaugeDuration duration, DateTime currentDate) { if (!duration.IsInfinity) { if (duration.IsTimeBased) { DateTime fromDate = currentDate - duration.ToTimeSpan(); return(this.Select(fromDate, currentDate)); } return(this.Select((int)duration.Count)); } return(this.Select()); }
public override void CalculateValue(double value, DateTime timestamp) { GaugeDuration aggregateDuration = base.aggregateDuration; if (aggregateDuration.IsEmpty) { base.CalculateValue(value, timestamp); } else { base.noMoreData = false; double num = value; if (((IValueConsumer)this).GetProvider() != null) { HistoryCollection data = ((IValueConsumer)this).GetProvider().GetData(aggregateDuration, timestamp); HistoryEntry[] array = data.Select(aggregateDuration, timestamp); if (array.Length > 1) { num = 0.0; long num2 = 0L; long num3 = 0L; for (int i = 0; i < array.Length - 1; i++) { num2 = array[i + 1].Timestamp.Ticks - array[i].Timestamp.Ticks; if (num2 == 0) { num += (array[i + 1].Value - array[i].Value) / 2.0; } else { num += array[i + 1].Value * (double)num2; num3 += num2; } } if (num3 > 0) { num /= (double)num3; } } else if (array.Length > 0) { num = array[0].Value; } else { base.noMoreData = true; } } base.CalculateValue(num, timestamp); } }
public TimeSpan ToTimeSpan() { if (this.IsTimeBased && !this.IsEmpty) { if (this.IsInfinity) { return(TimeSpan.MaxValue); } if (this.ivalidated) { this.timeSpan = GaugePeriod.PeriodToTimeSpan(this.count, GaugeDuration.MapToPeriodType(this.durationType)); this.ivalidated = false; } return(this.timeSpan); } return(TimeSpan.Zero); }
public void Extend(GaugeDuration extend, DateTime topDate, DateTime btmDate) { if (extend.IsInfinity) { this.DurationType = DurationType.Infinite; } else if (extend.IsCountBased && this.Count < extend.Count) { this.Count = extend.Count; } else if (extend.IsTimeBased) { DateTime t = topDate - extend.ToTimeSpan(); if (btmDate > t) { this.Count += 1.0; } } }
public void Truncate(GaugeDuration d) { if (!d.IsInfinity) { if (d.IsEmpty) { lock (this) { base.Clear(); } } else if (d.IsCountBased) { if ((double)base.Count > d.Count) { lock (this) { while ((double)base.Count > d.Count) { base.RemoveAt(0); } } } } else { DateTime timestamp = this.Top.Timestamp; DateTime t = timestamp - d.ToTimeSpan(); if (this[0].Timestamp < t) { lock (this) { while (this[0].Timestamp < t) { base.RemoveAt(0); } } } } } }