Example usage for org.apache.commons.math.stat.descriptive.rank Percentile Percentile

List of usage examples for org.apache.commons.math.stat.descriptive.rank Percentile Percentile

Introduction

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

Prototype

public Percentile(Percentile original) 

Source Link

Document

Copy constructor, creates a new Percentile identical to the original

Usage

From source file:cc.recommenders.evaluation.data.BoxplotData.java

public double getPercentil(int percent) {
    refreshCache();/*  w  w  w  . j a  v  a 2 s.  c o  m*/
    Percentile p = new Percentile(percent);
    // sorting is implicitly done in the evaluate method
    return p.evaluate(dataAsCachedArray);
}

From source file:com.eviware.loadui.util.statistics.ValueStatistics.java

public synchronized Map<String, Number> getData(long timestamp) {
    long max = 0;
    long min = Long.MAX_VALUE;
    long sum = 0;

    for (Iterator<DataPoint> it = dataPoints.iterator(); it.hasNext();) {
        DataPoint dataPoint = it.next();
        if (dataPoint.timestamp < timestamp - period && period > 0)
            it.remove();//from  www.  ja  v a  2 s.  c  o  m
        else {
            sum += dataPoint.value;
            max = Math.max(max, dataPoint.value);
            min = Math.min(min, dataPoint.value);
        }
    }

    int count = dataPoints.size();
    double avg = count > 0 ? (double) sum / count : 0;

    double stdDev = 0;
    double[] dataSet = new double[count];
    if (count > 0) {
        int i = 0;
        for (DataPoint dataPoint : dataPoints) {
            dataSet[i] = dataPoint.value;
            i++;
            stdDev += Math.pow(dataPoint.value - avg, 2);
        }
        stdDev = Math.sqrt(stdDev / count);
    }

    double tps = 0;
    long vps = 0;
    long duration = 0;
    if (count >= 2) {
        int samples = 0;
        long earliest = timestamp - snapshotLength;
        DataPoint point = null;
        while (++samples < count) {
            point = dataPoints.get(count - samples);
            vps += point.value;
            if (point.timestamp < earliest)
                break;
        }

        long timeDelta = timestamp - Preconditions.checkNotNull(point).timestamp;

        timeDelta = timeDelta == 0 ? 1000 : timeDelta;

        vps = vps * 1000 / timeDelta;
        tps = (samples - 1) * 1000.0 / timeDelta;
        duration = dataPoints.get(count - 1).timestamp - dataPoints.get(0).timestamp;
    }

    Percentile perc = new Percentile(90);

    double percentile = perc.evaluate(dataSet, 90);

    return new ImmutableMap.Builder<String, Number>() //
            .put("Max", max) //
            .put("Min", min == Long.MAX_VALUE ? 0L : min) //
            .put("Avg", avg) //
            .put("Sum", sum) //
            .put("Std-Dev", stdDev) //
            .put("Tps", tps) //
            .put("Avg-Tps", duration > 0L ? 1000L * count / duration : 0) //
            .put("Vps", vps) //
            .put("Avg-Vps", duration > 0L ? 1000L * sum / duration : 0) //
            .put("Percentile", percentile) //
            .put("AvgResponseSize", 1000L * sum / (dataPoints.size() == 0 ? 1 : dataPoints.size())) //
            .build();
}

From source file:com.kylinolap.job.engine.JobEngine.java

public double getPercentileJobStepDuration(double percentile) {
    Collection<Double> values = JOB_DURATION.values();
    Double[] all = (Double[]) values.toArray(new Double[values.size()]);
    Percentile p = new Percentile(percentile);
    return p.evaluate(ArrayUtils.toPrimitive(all));
}