use of org.elasticsearch.search.aggregations.metrics.percentiles.Percentile in project elasticsearch by elastic.
the class TDigestPercentilesIT method assertConsistent.
private void assertConsistent(double[] pcts, Percentiles percentiles, long minValue, long maxValue) {
final List<Percentile> percentileList = CollectionUtils.iterableAsArrayList(percentiles);
assertEquals(pcts.length, percentileList.size());
for (int i = 0; i < pcts.length; ++i) {
final Percentile percentile = percentileList.get(i);
assertThat(percentile.getPercent(), equalTo(pcts[i]));
double value = percentile.getValue();
assertThat(value, greaterThanOrEqualTo((double) minValue));
assertThat(value, lessThanOrEqualTo((double) maxValue));
if (percentile.getPercent() == 0) {
assertThat(value, equalTo((double) minValue));
}
if (percentile.getPercent() == 100) {
assertThat(value, equalTo((double) maxValue));
}
}
for (int i = 1; i < percentileList.size(); ++i) {
assertThat(percentileList.get(i).getValue(), greaterThanOrEqualTo(percentileList.get(i - 1).getValue()));
}
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.Percentile in project elasticsearch by elastic.
the class HDRPercentilesIT method assertConsistent.
private void assertConsistent(double[] pcts, Percentiles percentiles, long minValue, long maxValue, int numberSigDigits) {
final List<Percentile> percentileList = CollectionUtils.iterableAsArrayList(percentiles);
assertEquals(pcts.length, percentileList.size());
for (int i = 0; i < pcts.length; ++i) {
final Percentile percentile = percentileList.get(i);
assertThat(percentile.getPercent(), equalTo(pcts[i]));
double value = percentile.getValue();
double allowedError = value / Math.pow(10, numberSigDigits);
assertThat(value, greaterThanOrEqualTo(minValue - allowedError));
assertThat(value, lessThanOrEqualTo(maxValue + allowedError));
if (percentile.getPercent() == 0) {
assertThat(value, closeTo(minValue, allowedError));
}
if (percentile.getPercent() == 100) {
assertThat(value, closeTo(maxValue, allowedError));
}
}
for (int i = 1; i < percentileList.size(); ++i) {
assertThat(percentileList.get(i).getValue(), greaterThanOrEqualTo(percentileList.get(i - 1).getValue()));
}
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.Percentile in project elasticsearch by elastic.
the class HDRPercentileRanksIT method assertConsistent.
private void assertConsistent(double[] pcts, PercentileRanks values, long minValue, long maxValue, int numberSigDigits) {
final List<Percentile> percentileList = iterableAsArrayList(values);
assertEquals(pcts.length, percentileList.size());
for (int i = 0; i < pcts.length; ++i) {
final Percentile percentile = percentileList.get(i);
assertThat(percentile.getValue(), equalTo(pcts[i]));
assertThat(percentile.getPercent(), greaterThanOrEqualTo(0.0));
assertThat(percentile.getPercent(), lessThanOrEqualTo(100.0));
if (percentile.getPercent() == 0) {
double allowedError = minValue / Math.pow(10, numberSigDigits);
assertThat(percentile.getValue(), lessThanOrEqualTo(minValue + allowedError));
}
if (percentile.getPercent() == 100) {
double allowedError = maxValue / Math.pow(10, numberSigDigits);
assertThat(percentile.getValue(), greaterThanOrEqualTo(maxValue - allowedError));
}
}
for (int i = 1; i < percentileList.size(); ++i) {
assertThat(percentileList.get(i).getValue(), greaterThanOrEqualTo(percentileList.get(i - 1).getValue()));
}
}
use of org.elasticsearch.search.aggregations.metrics.percentiles.Percentile in project elasticsearch by elastic.
the class PercentilesBucketIT method assertPercentileBucket.
private void assertPercentileBucket(double[] values, PercentilesBucket percentiles) {
for (Percentile percentile : percentiles) {
assertEquals(percentiles.percentile(percentile.getPercent()), percentile.getValue(), 0d);
int index = (int) Math.round((percentile.getPercent() / 100.0) * (values.length - 1));
assertThat(percentile.getValue(), equalTo(values[index]));
}
}
Aggregations