Revision 68eab158
Added by Patrick Plitzner about 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java | ||
---|---|---|
22 | 22 |
import javax.inject.Inject; |
23 | 23 |
|
24 | 24 |
import org.apache.commons.collections4.map.LinkedMap; |
25 |
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; |
|
26 | 25 |
import org.eclipse.core.runtime.ICoreRunnable; |
27 | 26 |
import org.eclipse.core.runtime.IProgressMonitor; |
28 | 27 |
import org.eclipse.core.runtime.jobs.IJobChangeEvent; |
... | ... | |
139 | 138 |
|
140 | 139 |
private Map<Feature, CategoricalDataHistogram> featureToHistogramMap = new HashMap<>(); |
141 | 140 |
|
142 |
private Map<Feature, DescriptiveStatistics> featureToQuantStatisticsMap = new HashMap<>();
|
|
141 |
private Map<Feature, QuantitativeDataStatistics> featureToQuantDataStatisticsMap = new HashMap<>();
|
|
143 | 142 |
|
144 | 143 |
private ListDataProvider<Object> bodyDataProvider; |
145 | 144 |
|
... | ... | |
633 | 632 |
return featureToHistogramMap; |
634 | 633 |
} |
635 | 634 |
|
636 |
public Map<Feature, DescriptiveStatistics> getFeatureToQuantStatisticsMap() {
|
|
637 |
return featureToQuantStatisticsMap; |
|
635 |
public Map<Feature, QuantitativeDataStatistics> getFeatureToQuantDataStatisticsMap() {
|
|
636 |
return featureToQuantDataStatisticsMap;
|
|
638 | 637 |
} |
639 | 638 |
|
640 | 639 |
public void toogleIsShowTooltips() { |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixBottomToolbar.java | ||
---|---|---|
18 | 18 |
import java.util.UUID; |
19 | 19 |
import java.util.stream.Collectors; |
20 | 20 |
|
21 |
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; |
|
22 | 21 |
import org.eclipse.jface.layout.GridDataFactory; |
23 | 22 |
import org.eclipse.jface.window.Window; |
24 | 23 |
import org.eclipse.swt.SWT; |
... | ... | |
39 | 38 |
import eu.etaxonomy.cdm.model.description.Feature; |
40 | 39 |
import eu.etaxonomy.cdm.model.description.QuantitativeData; |
41 | 40 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
42 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
|
43 | 41 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
44 | 42 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
45 | 43 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
... | ... | |
160 | 158 |
matrix.setDirty(); |
161 | 159 |
|
162 | 160 |
aggregateCategorcialHistogram(matrix.getFeatureToHistogramMap()); |
163 |
aggregateQuantitativeSummary(matrix.getFeatureToQuantStatisticsMap()); |
|
161 |
aggregateQuantitativeSummary(matrix.getFeatureToQuantDataStatisticsMap());
|
|
164 | 162 |
} |
165 | 163 |
|
166 | 164 |
}); |
... | ... | |
185 | 183 |
} |
186 | 184 |
|
187 | 185 |
@SuppressWarnings("unchecked") |
188 |
private void aggregateQuantitativeSummary(Map<Feature, DescriptiveStatistics> featureToQuantStatisticsMap) {
|
|
189 |
featureToQuantStatisticsMap.clear(); |
|
186 |
private void aggregateQuantitativeSummary(Map<Feature, QuantitativeDataStatistics> featureToQuantDataStatisticsMap) {
|
|
187 |
featureToQuantDataStatisticsMap.clear();
|
|
190 | 188 |
matrix.getDescriptions() |
191 | 189 |
.forEach(o -> ((RowWrapperDTO) o).getSpecimenDescription().getElements().stream() |
192 | 190 |
.filter(descriptionElement -> descriptionElement instanceof QuantitativeData) |
193 | 191 |
.forEach(quantData -> { |
194 | 192 |
Feature feature = ((QuantitativeData) quantData).getFeature(); |
195 |
DescriptiveStatistics statistics = featureToQuantStatisticsMap.get(feature);
|
|
196 |
if(statistics==null){
|
|
197 |
statistics = new DescriptiveStatistics();
|
|
193 |
QuantitativeDataStatistics dataStatistics = featureToQuantDataStatisticsMap.get(feature);
|
|
194 |
if(dataStatistics==null){
|
|
195 |
dataStatistics = new QuantitativeDataStatistics();
|
|
198 | 196 |
} |
199 |
featureToQuantStatisticsMap.put(feature, statistics); |
|
200 |
((QuantitativeData) quantData).getStatisticalValues().stream() |
|
201 |
.filter(value -> value.getType().equals(StatisticalMeasure.EXACT_VALUE())) |
|
202 |
.forEach(value -> featureToQuantStatisticsMap.get(feature).addValue(value.getValue())); |
|
197 |
featureToQuantDataStatisticsMap.put(feature, dataStatistics); |
|
198 |
dataStatistics.addQuantitativeData((QuantitativeData) quantData); |
|
203 | 199 |
})); |
204 | 200 |
} |
205 | 201 |
|
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/QuantitativeChartTooltip.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix; |
10 | 10 |
|
11 |
import java.util.Arrays;
|
|
11 |
import java.util.List;
|
|
12 | 12 |
|
13 | 13 |
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; |
14 | 14 |
import org.eclipse.jface.window.DefaultToolTip; |
... | ... | |
23 | 23 |
import org.swtchart.Chart; |
24 | 24 |
import org.swtchart.IAxis; |
25 | 25 |
import org.swtchart.ILineSeries; |
26 |
import org.swtchart.ILineSeries.PlotSymbolType; |
|
26 | 27 |
import org.swtchart.ISeries.SeriesType; |
27 | 28 |
import org.swtchart.LineStyle; |
28 | 29 |
|
... | ... | |
61 | 62 |
int colPos = matrix.getNatTable().getColumnPositionByX(event.x); |
62 | 63 |
int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos); |
63 | 64 |
Feature feature = matrix.getIndexToFeatureMap().get(colIndex); |
64 |
DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature); |
|
65 |
double[] ySeries = statistics.getValues(); |
|
66 |
Arrays.sort(ySeries); |
|
65 |
QuantitativeDataStatistics quantitativeDataStatistics = matrix.getFeatureToQuantDataStatisticsMap().get(feature); |
|
66 |
List<DescriptiveStatistics> statistics = quantitativeDataStatistics.getStatistics(); |
|
67 |
|
|
68 |
//prepare series |
|
69 |
double[] exactMean = statistics.stream().mapToDouble(statistic->statistic.getMean()).toArray(); |
|
70 |
double[] mins = statistics.stream().mapToDouble(statistic->statistic.getMin()).toArray(); |
|
71 |
double[] maxs = statistics.stream().mapToDouble(statistic->statistic.getMax()).toArray(); |
|
67 | 72 |
|
68 | 73 |
// set chart title |
69 | 74 |
chart.getTitle().setText(feature.getLabel()); |
... | ... | |
71 | 76 |
// create exact/mean series |
72 | 77 |
ILineSeries meanExactSeries = (ILineSeries) chart.getSeriesSet() |
73 | 78 |
.createSeries(SeriesType.LINE, "exact/mean"); |
74 |
meanExactSeries.setYSeries(ySeries);
|
|
79 |
meanExactSeries.setYSeries(exactMean);
|
|
75 | 80 |
meanExactSeries.setLineStyle(LineStyle.NONE); |
76 | 81 |
meanExactSeries.setSymbolColor(GUIHelper.COLOR_BLUE); |
77 | 82 |
|
78 |
//TODO get min and max values |
|
79 | 83 |
// create min series |
80 |
// ILineSeries minSeries = (ILineSeries) chart.getSeriesSet() |
|
81 |
// .createSeries(SeriesType.LINE, "min"); |
|
82 |
// double[] mins = { 0.3, 0.4, 0.3, 0.9, 1.1, 2.5, 2.6, 2.6}; |
|
83 |
// minSeries.setYSeries(mins); |
|
84 |
// minSeries.setLineStyle(LineStyle.NONE); |
|
85 |
// minSeries.setSymbolType(PlotSymbolType.INVERTED_TRIANGLE); |
|
86 |
// minSeries.setSymbolColor(GUIHelper.COLOR_GREEN); |
|
87 |
// |
|
88 |
// // create max series |
|
89 |
// ILineSeries maxSeries = (ILineSeries) chart.getSeriesSet() |
|
90 |
// .createSeries(SeriesType.LINE, "max"); |
|
91 |
// double[] maxs = { 1.3, 2.4, 2.5, 2.6, 2.8, 3.6, 3.6, 3.8 }; |
|
92 |
// maxSeries.setYSeries(maxs); |
|
93 |
// maxSeries.setLineStyle(LineStyle.NONE); |
|
94 |
// maxSeries.setSymbolType(PlotSymbolType.TRIANGLE); |
|
95 |
// maxSeries.setSymbolColor(GUIHelper.COLOR_RED); |
|
84 |
ILineSeries minSeries = (ILineSeries) chart.getSeriesSet() |
|
85 |
.createSeries(SeriesType.LINE, "min"); |
|
86 |
minSeries.setYSeries(mins); |
|
87 |
minSeries.setLineStyle(LineStyle.NONE); |
|
88 |
minSeries.setSymbolType(PlotSymbolType.INVERTED_TRIANGLE); |
|
89 |
minSeries.setSymbolColor(GUIHelper.COLOR_GREEN); |
|
90 |
|
|
91 |
// create max series |
|
92 |
ILineSeries maxSeries = (ILineSeries) chart.getSeriesSet() |
|
93 |
.createSeries(SeriesType.LINE, "max"); |
|
94 |
maxSeries.setYSeries(maxs); |
|
95 |
maxSeries.setLineStyle(LineStyle.NONE); |
|
96 |
maxSeries.setSymbolType(PlotSymbolType.TRIANGLE); |
|
97 |
maxSeries.setSymbolColor(GUIHelper.COLOR_RED); |
|
96 | 98 |
|
97 | 99 |
IAxis yAxis = chart.getAxisSet().getYAxis(0); |
98 | 100 |
yAxis.getTitle().setVisible(false); |
... | ... | |
113 | 115 |
int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos); |
114 | 116 |
int rowPos = matrix.getNatTable().getRowPositionByY(event.y); |
115 | 117 |
Feature feature = matrix.getIndexToFeatureMap().get(colIndex); |
116 |
DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature);
|
|
118 |
QuantitativeDataStatistics dataStatistics = matrix.getFeatureToQuantDataStatisticsMap().get(feature);
|
|
117 | 119 |
|
118 | 120 |
if(matrix.isShowTooltips() |
119 | 121 |
&& rowPos==1 |
120 | 122 |
&& colIndex>=CharacterMatrix.LEADING_COLUMN_COUNT |
121 |
&& statistics!=null) {
|
|
123 |
&& dataStatistics!=null) {
|
|
122 | 124 |
return true; |
123 | 125 |
} |
124 | 126 |
return false; |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/QuantitativeDataStatistics.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Collections; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.model.description.QuantitativeData; |
|
18 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author pplitzner |
|
22 |
* @since Jul 18, 2018 |
|
23 |
* |
|
24 |
*/ |
|
25 |
public class QuantitativeDataStatistics { |
|
26 |
|
|
27 |
private List<DescriptiveStatistics> statistics = new ArrayList<>(); |
|
28 |
|
|
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)); |
|
36 |
} |
|
37 |
//otherwise we use the aggregated values (min, max, etc.) |
|
38 |
else{ |
|
39 |
DescriptiveStatistics aggregatedStatistics = new DescriptiveStatistics(); |
|
40 |
if(quantitativeData.getMin()!=null){ |
|
41 |
aggregatedStatistics.addValue(quantitativeData.getMin().doubleValue()); |
|
42 |
} |
|
43 |
if(quantitativeData.getMax()!=null){ |
|
44 |
aggregatedStatistics.addValue(quantitativeData.getMax().doubleValue()); |
|
45 |
} |
|
46 |
statistics.add(aggregatedStatistics); |
|
47 |
} |
|
48 |
Collections.sort(statistics, (s1, s2)->Double.compare(s1.getMean(), s2.getMean())); |
|
49 |
} |
|
50 |
|
|
51 |
public List<DescriptiveStatistics> getStatistics() { |
|
52 |
return statistics; |
|
53 |
} |
|
54 |
|
|
55 |
} |
Also available in: Unified diff
ref #7549 Add min and max data series to quant data chart