public override Aggregates GetAggregates(long tStart, long tEnd) { var agg = new Aggregates(); agg.First = agg.Last = agg.Min = agg.Max = agg.Average = value; agg.Total = value*(tEnd - tStart); return agg; }
internal Aggregates GetAggregates(long tStart, long tEnd) { var agg = new Aggregates(); long totalSeconds = 0; bool firstFound = false; for (int i = 0; i < timestamps.Length; i++) { long left = Math.Max(timestamps[i] - step, tStart); long right = Math.Min(timestamps[i], tEnd); long delta = right - left; // delta is only > 0 when the timestamp for a given buck is within the range of tStart and tEnd if (delta > 0) { double value = values[i]; agg.Min = Util.Min(agg.Min, value); agg.Max = Util.Max(agg.Max, value); if (!firstFound) { agg.First = value; firstFound = true; agg.Last = value; } else if (delta >= step) { // an entire bucket is included in this range agg.Last = value; /* * Algorithmically, we're only updating last if it's either the first * bucket encountered, or it's a "full" bucket. if ( !isInRange(tEnd, left, right) || (isInRange(tEnd, left, right) && !Double.isNaN(value)) ) { agg.last = value; } */ } if (!Double.IsNaN(value)) { agg.Total = Util.Sum(agg.Total, delta*value); totalSeconds += delta; } } } agg.Average = totalSeconds > 0 ? (agg.Total/totalSeconds) : Double.NaN; return agg; }