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

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

Introduction

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

Prototype

@Override
public void increment(final double observation) 

Source Link

Document

The internal state updated due to the new value in this context is basically of the marker positions and computation of the approximate quantile.

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);
    }/*from  w w w.j a  va  2 s . 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);
    }/* w w w.  j ava  2 s  . c om*/

    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());
}