Java Code Examples for java.util.LongSummaryStatistics#getCount()

The following examples show how to use java.util.LongSummaryStatistics#getCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatisticsHelper.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Map<String, String> process(List<Long> samples) {

        // aftermath
        Collections.sort(samples);

        // - average, max, min , sample size
        LongSummaryStatistics statistics = samples.stream().mapToLong(val -> val).summaryStatistics();

        Map<String, String> results = new HashMap<>();
        results.put("average", String.valueOf(Math.round(statistics.getAverage())));
        results.put("max", String.valueOf(statistics.getMax()));
        results.put("min", String.valueOf(statistics.getMin()));
        results.put("sampleSize", String.valueOf(statistics.getCount()));

        // - p25, median, p75
        Integer[] percentiles = new Integer[] { 25, 50, 75 };
        for (Integer percentile : percentiles) {
            double rank = statistics.getCount() * percentile / 100.0;
            Long percentileValue;
            if (samples.size() <= rank + 1)
                percentileValue = samples.get(samples.size() - 1);
            else if (Math.floor(rank) == rank)
                percentileValue = samples.get((int) rank);
            else
                percentileValue = Math.round(samples.get((int) Math.floor(rank))
                        + (samples.get((int) (Math.floor(rank) + 1)) - samples.get((int) Math.floor(rank)))
                                / (rank - Math.floor(rank)));
            results.put("p" + percentile, String.valueOf(percentileValue));
        }

        return results;
    }
 
Example 2
Source File: LongSummary.java    From jenetics with Apache License 2.0 5 votes vote down vote up
/**
 * Return a new value object of the statistical summary, currently
 * represented by the {@code statistics} object.
 *
 * @param statistics the creating (mutable) statistics class
 * @return the statistical moments
 */
public static LongSummary of(final LongSummaryStatistics statistics) {
	return new LongSummary(
		statistics.getCount(),
		statistics.getMin(),
		statistics.getMax(),
		statistics.getSum(),
		statistics.getAverage()
	);
}