Example usage for org.apache.commons.math3.stat.descriptive.rank PSquarePercentile PSquarePercentile

List of usage examples for org.apache.commons.math3.stat.descriptive.rank PSquarePercentile PSquarePercentile

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive.rank PSquarePercentile PSquarePercentile.

Prototype

public PSquarePercentile(final double p) 

Source Link

Document

Constructs a PSquarePercentile with the specific percentile value.

Usage

From source file:org.hawkular.metrics.core.service.metrics.CounterITest.java

@Test
public void testBucketPercentiles() {
    String tenantId = "counter-stats-test";

    int testSize = 100;
    List<DataPoint<Long>> counterList = new ArrayList<>(testSize);

    PSquarePercentile top = new PSquarePercentile(99.9);

    for (long i = 0; i < testSize; i++) {
        counterList.add(new DataPoint<Long>((long) 60000 + i, i));
        top.increment(i);// w  w  w  . jav a 2s.  c om
    }

    List<Percentile> percentiles = asList(new Percentile("50.0"), new Percentile("90.0"),
            new Percentile("99.0"), new Percentile("99.9"));

    Metric<Long> counter = new Metric<>(new MetricId<>(tenantId, COUNTER, "C1"), counterList);

    doAction(() -> metricsService.addDataPoints(COUNTER, Observable.just(counter)));

    List<NumericBucketPoint> actual = metricsService.findCounterStats(counter.getMetricId(), 0,
            now().getMillis(), Buckets.fromStep(60_000, 60_100, 60_100), percentiles).toBlocking().single();

    assertEquals(1, actual.size());

    NumericBucketPoint bucket = actual.get(0);

    assertEquals((Integer) testSize, bucket.getSamples());
    assertEquals(percentiles.size(), bucket.getPercentiles().size());
    assertEquals(top.getResult(), bucket.getPercentiles().get(3).getValue());
}

From source file:org.hawkular.metrics.core.service.MetricsServiceITest.java

@Test
public void testBucketPercentiles() {
    String tenantId = "counter-stats-test";

    int testSize = 100;
    List<DataPoint<Long>> counterList = new ArrayList<>(testSize);

    PSquarePercentile top = new PSquarePercentile(99.9);

    for (long i = 0; i < testSize; i++) {
        counterList.add(new DataPoint<Long>((long) 60000 + i, i));
        top.increment(i);//from  ww  w  .j  av  a  2 s  .  co  m
    }

    List<Double> percentiles = asList(50.0, 90.0, 99.0, 99.9);

    Metric<Long> counter = new Metric<>(new MetricId<>(tenantId, COUNTER, "C1"), counterList);

    doAction(() -> metricsService.addDataPoints(COUNTER, Observable.just(counter)));

    List<NumericBucketPoint> actual = metricsService.findCounterStats(counter.getMetricId(), 0,
            now().getMillis(), Buckets.fromStep(60_000, 60_100, 60_100), percentiles).toBlocking().single();

    assertEquals(1, actual.size());

    NumericBucketPoint bucket = actual.get(0);

    assertEquals(testSize, bucket.getSamples());
    assertEquals(percentiles.size(), bucket.getPercentiles().size());
    assertEquals(top.getResult(), bucket.getPercentiles().get(3).getValue());
}

From source file:org.hawkular.metrics.core.service.NumericDataPointCollector.java

NumericDataPointCollector(Buckets buckets, int bucketIndex, List<Double> percentileList) {
    this.buckets = buckets;
    this.bucketIndex = bucketIndex;
    this.percentiles = new ArrayList<>();
    percentileList.stream().forEach(d -> percentiles.add(new PSquarePercentile(d)));
}