2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Collections
;
13 import java
.util
.List
;
15 import org
.apache
.commons
.math3
.stat
.descriptive
.DescriptiveStatistics
;
17 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
18 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
25 public class QuantitativeDataStatistics
{
27 private List
<DescriptiveStatistics
> statistics
= new ArrayList
<>();
29 public void addQuantitativeData(QuantitativeData quantitativeData
){
30 double[] exactValues
= quantitativeData
.getStatisticalValues().stream()
31 .filter(value
-> value
.getType().equals(StatisticalMeasure
.EXACT_VALUE()))
32 .mapToDouble(value
-> value
.getValue()).toArray();
33 //if there are exact values we use those
34 if (exactValues
.length
> 0) {
35 statistics
.add(new DescriptiveStatistics(exactValues
));
37 //otherwise we use the aggregated values (min, max, etc.)
39 DescriptiveStatistics aggregatedStatistics
= new DescriptiveStatistics();
40 if(quantitativeData
.getMin()!=null){
41 aggregatedStatistics
.addValue(quantitativeData
.getMin().doubleValue());
43 if(quantitativeData
.getMax()!=null){
44 aggregatedStatistics
.addValue(quantitativeData
.getMax().doubleValue());
46 statistics
.add(aggregatedStatistics
);
48 Collections
.sort(statistics
, (s1
, s2
)->Double
.compare(s1
.getMean(), s2
.getMean()));
51 public List
<DescriptiveStatistics
> getStatistics() {