Skip to content

Instantly share code, notes, and snippets.

@jsanda
Created May 14, 2014 18:42
Show Gist options
  • Save jsanda/31e93f1545b1cf7b215d to your computer and use it in GitHub Desktop.
Save jsanda/31e93f1545b1cf7b215d to your computer and use it in GitHub Desktop.
bug in aggregation code
private AggregateNumericMetric calculateAggregate(Iterable<AggregateNumericMetric> metrics, long timestamp) {
double min = Double.NaN;
double max = min;
int count = 0;
ArithmeticMeanCalculator mean = new ArithmeticMeanCalculator();
for (AggregateNumericMetric metric : metrics) {
if (count == 0) {
min = metric.getMin();
max = metric.getMax();
}
if (metric.getMin() < min) {
min = metric.getMin();
} else if (metric.getMax() > max) {
max = metric.getMax();
}
mean.add(metric.getAvg());
++count;
}
// We let the caller handle setting the schedule id because in some cases we do
// not care about it.
return new AggregateNumericMetric(0, mean.getArithmeticMean(), min, max, timestamp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment