import javax.inject.Inject;
import org.apache.commons.collections4.map.LinkedMap;
-import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
private Map<Feature, CategoricalDataHistogram> featureToHistogramMap = new HashMap<>();
- private Map<Feature, DescriptiveStatistics> featureToQuantStatisticsMap = new HashMap<>();
+ private Map<Feature, QuantitativeDataStatistics> featureToQuantDataStatisticsMap = new HashMap<>();
private ListDataProvider<Object> bodyDataProvider;
return featureToHistogramMap;
}
- public Map<Feature, DescriptiveStatistics> getFeatureToQuantStatisticsMap() {
- return featureToQuantStatisticsMap;
+ public Map<Feature, QuantitativeDataStatistics> getFeatureToQuantDataStatisticsMap() {
+ return featureToQuantDataStatisticsMap;
}
public void toogleIsShowTooltips() {
import java.util.UUID;
import java.util.stream.Collectors;
-import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.QuantitativeData;
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
-import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
matrix.setDirty();
aggregateCategorcialHistogram(matrix.getFeatureToHistogramMap());
- aggregateQuantitativeSummary(matrix.getFeatureToQuantStatisticsMap());
+ aggregateQuantitativeSummary(matrix.getFeatureToQuantDataStatisticsMap());
}
});
}
@SuppressWarnings("unchecked")
- private void aggregateQuantitativeSummary(Map<Feature, DescriptiveStatistics> featureToQuantStatisticsMap) {
- featureToQuantStatisticsMap.clear();
+ private void aggregateQuantitativeSummary(Map<Feature, QuantitativeDataStatistics> featureToQuantDataStatisticsMap) {
+ featureToQuantDataStatisticsMap.clear();
matrix.getDescriptions()
.forEach(o -> ((RowWrapperDTO) o).getSpecimenDescription().getElements().stream()
.filter(descriptionElement -> descriptionElement instanceof QuantitativeData)
.forEach(quantData -> {
Feature feature = ((QuantitativeData) quantData).getFeature();
- DescriptiveStatistics statistics = featureToQuantStatisticsMap.get(feature);
- if(statistics==null){
- statistics = new DescriptiveStatistics();
+ QuantitativeDataStatistics dataStatistics = featureToQuantDataStatisticsMap.get(feature);
+ if(dataStatistics==null){
+ dataStatistics = new QuantitativeDataStatistics();
}
- featureToQuantStatisticsMap.put(feature, statistics);
- ((QuantitativeData) quantData).getStatisticalValues().stream()
- .filter(value -> value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
- .forEach(value -> featureToQuantStatisticsMap.get(feature).addValue(value.getValue()));
+ featureToQuantDataStatisticsMap.put(feature, dataStatistics);
+ dataStatistics.addQuantitativeData((QuantitativeData) quantData);
}));
}
*/
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
-import java.util.Arrays;
+import java.util.List;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.eclipse.jface.window.DefaultToolTip;
import org.swtchart.Chart;
import org.swtchart.IAxis;
import org.swtchart.ILineSeries;
+import org.swtchart.ILineSeries.PlotSymbolType;
import org.swtchart.ISeries.SeriesType;
import org.swtchart.LineStyle;
int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
- DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature);
- double[] ySeries = statistics.getValues();
- Arrays.sort(ySeries);
+ QuantitativeDataStatistics quantitativeDataStatistics = matrix.getFeatureToQuantDataStatisticsMap().get(feature);
+ List<DescriptiveStatistics> statistics = quantitativeDataStatistics.getStatistics();
+
+ //prepare series
+ double[] exactMean = statistics.stream().mapToDouble(statistic->statistic.getMean()).toArray();
+ double[] mins = statistics.stream().mapToDouble(statistic->statistic.getMin()).toArray();
+ double[] maxs = statistics.stream().mapToDouble(statistic->statistic.getMax()).toArray();
// set chart title
chart.getTitle().setText(feature.getLabel());
// create exact/mean series
ILineSeries meanExactSeries = (ILineSeries) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "exact/mean");
- meanExactSeries.setYSeries(ySeries);
+ meanExactSeries.setYSeries(exactMean);
meanExactSeries.setLineStyle(LineStyle.NONE);
meanExactSeries.setSymbolColor(GUIHelper.COLOR_BLUE);
- //TODO get min and max values
// create min series
-// ILineSeries minSeries = (ILineSeries) chart.getSeriesSet()
-// .createSeries(SeriesType.LINE, "min");
-// double[] mins = { 0.3, 0.4, 0.3, 0.9, 1.1, 2.5, 2.6, 2.6};
-// minSeries.setYSeries(mins);
-// minSeries.setLineStyle(LineStyle.NONE);
-// minSeries.setSymbolType(PlotSymbolType.INVERTED_TRIANGLE);
-// minSeries.setSymbolColor(GUIHelper.COLOR_GREEN);
-//
-// // create max series
-// ILineSeries maxSeries = (ILineSeries) chart.getSeriesSet()
-// .createSeries(SeriesType.LINE, "max");
-// double[] maxs = { 1.3, 2.4, 2.5, 2.6, 2.8, 3.6, 3.6, 3.8 };
-// maxSeries.setYSeries(maxs);
-// maxSeries.setLineStyle(LineStyle.NONE);
-// maxSeries.setSymbolType(PlotSymbolType.TRIANGLE);
-// maxSeries.setSymbolColor(GUIHelper.COLOR_RED);
+ ILineSeries minSeries = (ILineSeries) chart.getSeriesSet()
+ .createSeries(SeriesType.LINE, "min");
+ minSeries.setYSeries(mins);
+ minSeries.setLineStyle(LineStyle.NONE);
+ minSeries.setSymbolType(PlotSymbolType.INVERTED_TRIANGLE);
+ minSeries.setSymbolColor(GUIHelper.COLOR_GREEN);
+
+ // create max series
+ ILineSeries maxSeries = (ILineSeries) chart.getSeriesSet()
+ .createSeries(SeriesType.LINE, "max");
+ maxSeries.setYSeries(maxs);
+ maxSeries.setLineStyle(LineStyle.NONE);
+ maxSeries.setSymbolType(PlotSymbolType.TRIANGLE);
+ maxSeries.setSymbolColor(GUIHelper.COLOR_RED);
IAxis yAxis = chart.getAxisSet().getYAxis(0);
yAxis.getTitle().setVisible(false);
int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
int rowPos = matrix.getNatTable().getRowPositionByY(event.y);
Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
- DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature);
+ QuantitativeDataStatistics dataStatistics = matrix.getFeatureToQuantDataStatisticsMap().get(feature);
if(matrix.isShowTooltips()
&& rowPos==1
&& colIndex>=CharacterMatrix.LEADING_COLUMN_COUNT
- && statistics!=null) {
+ && dataStatistics!=null) {
return true;
}
return false;
--- /dev/null
+/**
+* Copyright (C) 2018 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import eu.etaxonomy.cdm.model.description.QuantitativeData;
+import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
+
+/**
+ * @author pplitzner
+ * @since Jul 18, 2018
+ *
+ */
+public class QuantitativeDataStatistics {
+
+ private List<DescriptiveStatistics> statistics = new ArrayList<>();
+
+ public void addQuantitativeData(QuantitativeData quantitativeData){
+ double[] exactValues = quantitativeData.getStatisticalValues().stream()
+ .filter(value -> value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
+ .mapToDouble(value -> value.getValue()).toArray();
+ //if there are exact values we use those
+ if (exactValues.length > 0) {
+ statistics.add(new DescriptiveStatistics(exactValues));
+ }
+ //otherwise we use the aggregated values (min, max, etc.)
+ else{
+ DescriptiveStatistics aggregatedStatistics = new DescriptiveStatistics();
+ if(quantitativeData.getMin()!=null){
+ aggregatedStatistics.addValue(quantitativeData.getMin().doubleValue());
+ }
+ if(quantitativeData.getMax()!=null){
+ aggregatedStatistics.addValue(quantitativeData.getMax().doubleValue());
+ }
+ statistics.add(aggregatedStatistics);
+ }
+ Collections.sort(statistics, (s1, s2)->Double.compare(s1.getMean(), s2.getMean()));
+ }
+
+ public List<DescriptiveStatistics> getStatistics() {
+ return statistics;
+ }
+
+}