Example usage for java.util DoubleSummaryStatistics getAverage

List of usage examples for java.util DoubleSummaryStatistics getAverage

Introduction

In this page you can find the example usage for java.util DoubleSummaryStatistics getAverage.

Prototype

public final double getAverage() 

Source Link

Document

Returns the arithmetic mean of values recorded, or zero if no values have been recorded.

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleSummaryStatistics stats = new DoubleSummaryStatistics();
    stats.accept(100.0);// w ww.j a  v  a 2  s  . co  m
    stats.accept(300.0);
    stats.accept(230.0);
    stats.accept(532.0);
    stats.accept(422.0);

    long count = stats.getCount();
    double sum = stats.getSum();
    double min = stats.getMin();
    double avg = stats.getAverage();
    double max = stats.getMax();

    System.out.printf("count=%d, sum=%.2f,  min=%.2f,  average=%.2f, max=%.2f%n", count, sum, min, max, avg);
}

From source file:com.epam.ta.reportportal.core.project.impl.ProjectInfoWidgetDataConverter.java

/**
 * <b>Test-cases statistics in unique launches</b> project info widget
 * content data-source/*from w  w w. ja v a  2s.  co m*/
 * 
 * @param initial
 * @return
 */
public Map<String, List<ChartObject>> getTestCasesStatisticsProjectInfo(List<Launch> initial) {
    DecimalFormat formatter = new DecimalFormat("#####.##");
    final String MIN = "min";
    final String MAX = "max";
    final String AVG = "avg";
    String globalAverageSeria = "Median value in all unique launches";

    if (initial.isEmpty()) {
        return new HashMap<>();
    }

    Map<String, List<ChartObject>> result = new HashMap<>();
    Map<String, List<Launch>> grouped = groupBy(initial, BY_NAME);
    for (Entry<String, List<Launch>> pair : grouped.entrySet()) {
        ChartObject singleStat = new ChartObject();
        singleStat.setName(pair.getKey());
        Map<String, String> values = new HashMap<>();
        List<Launch> group = pair.getValue();

        DoubleSummaryStatistics statistics = group.stream()
                .mapToDouble(it -> it.getStatistics().getExecutionCounter().getTotal()).summaryStatistics();
        values.put(MIN, String.valueOf(statistics.getMin()));
        values.put(MAX, String.valueOf(statistics.getMax()));
        values.put(AVG, formatter.format(statistics.getAverage()));
        singleStat.setValues(values);

        result.put(pair.getKey(), Collections.singletonList(singleStat));
    }

    /*
     * Separate label for 'Median value in all unique launches' on the table
     */
    // TODO Implement new MEDIAN calculation!
    result.put(globalAverageSeria, Collections.singletonList(new ChartObject()));
    return result;
}

From source file:org.apache.metron.indexing.dao.metaalert.MetaScores.java

public MetaScores(List<Double> scores) {
    // A meta alert could be entirely alerts with no values.
    DoubleSummaryStatistics stats = scores.stream().mapToDouble(a -> a).summaryStatistics();
    metaScores.put("max", stats.getMax());
    metaScores.put("min", stats.getMin());
    metaScores.put("average", stats.getAverage());
    metaScores.put("count", stats.getCount());
    metaScores.put("sum", stats.getSum());

    // median isn't in the stats summary
    double[] arr = scores.stream().mapToDouble(d -> d).toArray();
    metaScores.put("median", new Median().evaluate(arr));
}

From source file:org.opennms.web.controller.trend.TrendController.java

private Map<String, String> variableReplacements(final List<Double> values) {
    final Map<String, String> replacements = new HashMap<>();

    final DoubleSummaryStatistics doubleSummaryStatistics = values.stream().mapToDouble(Double::doubleValue)
            .summaryStatistics();//from   www. java 2  s . co m

    replacements.put("${doubleMax}", String.format("%.2f", doubleSummaryStatistics.getMax()));
    replacements.put("${intMax}", String.format("%d", (int) doubleSummaryStatistics.getMax()));

    replacements.put("${doubleMin}", String.format("%.2f", doubleSummaryStatistics.getMin()));
    replacements.put("${intMin}", String.format("%d", (int) doubleSummaryStatistics.getMin()));

    replacements.put("${doubleAvg}", String.format("%.2f", doubleSummaryStatistics.getAverage()));
    replacements.put("${intAvg}", String.format("%d", (int) doubleSummaryStatistics.getAverage()));

    replacements.put("${doubleSum}", String.format("%.2f", doubleSummaryStatistics.getSum()));
    replacements.put("${intSum}", String.format("%d", (int) doubleSummaryStatistics.getSum()));

    for (int i = 0; i < values.size(); i++) {
        double current = values.get(i);

        replacements.put("${doubleValue[" + i + "]}", String.format("%.2f", current));
        replacements.put("${intValue[" + i + "]}", String.format("%d", (int) current));

        if (i > 0) {
            double previous = values.get(i - 1);
            double change = current - previous;

            replacements.put("${doubleValueChange[" + i + "]}", String.format("%+.2f", change));
            replacements.put("${intValueChange[" + i + "]}", String.format("%+d", (int) change));
        } else {
            replacements.put("${doubleValueChange[" + i + "]}", "NaN");
            replacements.put("${intValueChange[" + i + "]}", "NaN");
        }
    }

    if (values.size() > 0) {
        replacements.put("${doubleLastValueChange}",
                replacements.get("${doubleValueChange[" + (values.size() - 1) + "]}"));
        replacements.put("${intLastValueChange}",
                replacements.get("${intValueChange[" + (values.size() - 1) + "]}"));

        replacements.put("${doubleLastValue}", replacements.get("${doubleValue[" + (values.size() - 1) + "]}"));
        replacements.put("${intLastValue}", replacements.get("${intValue[" + (values.size() - 1) + "]}"));
    } else {
        replacements.put("${doubleLastValueChange}", "NaN");
        replacements.put("${intLastValueChange}", "NaN");

        replacements.put("${doubleLastValue}", "NaN");
        replacements.put("${intLastValue}", "NaN");
    }

    return replacements;
}