ref #7549 Add/use apache common math for frequency distribution
authorPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 13 Jul 2018 06:32:01 +0000 (08:32 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 13 Jul 2018 06:32:01 +0000 (08:32 +0200)
eu.etaxonomy.taxeditor.cdmlib/.classpath
eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.cdmlib/build.properties
eu.etaxonomy.taxeditor.cdmlib/lib/commons-math3-3.6.1.jar [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CategoricalDataHistogram.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/ChartTooltip.java

index c03a7c6e00c9220c44c5575894a7d69666836ebf..2b1ea6a1e0544fe9f5587b3ec1056dd2ca871f25 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+       <classpathentry exported="true" kind="lib" path="lib/commons-math3-3.6.1.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/org.swtchart_0.10.0.v20160212.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/redmine-java-api-3.1.0.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
        <classpathentry exported="true" kind="lib" path="lib/org.swtchart_0.10.0.v20160212.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/redmine-java-api-3.1.0.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
index 50d2891fd926b242d657c91c2d793262dc5dcc15..ba8b680bc19fdc62f4173fd1c6c6528c5d99f61e 100644 (file)
@@ -231,6 +231,7 @@ Export-Package: com.google.api,
  org.apache.commons.lang.exception,
  org.apache.commons.lang.text,
  org.apache.commons.logging,
  org.apache.commons.lang.exception,
  org.apache.commons.lang.text,
  org.apache.commons.logging,
+ org.apache.commons.math3.stat,
  org.apache.fop.apps,
  org.apache.http,
  org.apache.http.client,
  org.apache.fop.apps,
  org.apache.http,
  org.apache.http.client,
@@ -869,5 +870,6 @@ Bundle-ClassPath: .,
  lib/lucene-sandbox-5.4.1.jar,
  lib/lucene-suggest-5.4.1.jar,
  lib/redmine-java-api-3.1.0.jar,
  lib/lucene-sandbox-5.4.1.jar,
  lib/lucene-suggest-5.4.1.jar,
  lib/redmine-java-api-3.1.0.jar,
- lib/org.swtchart_0.10.0.v20160212.jar
+ lib/org.swtchart_0.10.0.v20160212.jar,
+ lib/commons-math3-3.6.1.jar
 Import-Package: eu.etaxonomy.cdm.api.application
 Import-Package: eu.etaxonomy.cdm.api.application
index 0ece366f41cfc6e4dbe7d7d412eaed36c38bd578..2c484805305b1c18c166c452b3ba6fcce0b0c936 100644 (file)
@@ -223,7 +223,8 @@ bin.includes = META-INF/,\
                lib/lucene-suggest-5.4.1.jar,\
                lib/cdmlib-cache-5.2.0-SNAPSHOT.jar,\
                lib/redmine-java-api-3.1.0.jar,\
                lib/lucene-suggest-5.4.1.jar,\
                lib/cdmlib-cache-5.2.0-SNAPSHOT.jar,\
                lib/redmine-java-api-3.1.0.jar,\
-               lib/org.swtchart_0.10.0.v20160212.jar
+               lib/org.swtchart_0.10.0.v20160212.jar,\
+               lib/commons-math3-3.6.1.jar
 
 jars.compile.order = .
 output.. = bin/
 
 jars.compile.order = .
 output.. = bin/
diff --git a/eu.etaxonomy.taxeditor.cdmlib/lib/commons-math3-3.6.1.jar b/eu.etaxonomy.taxeditor.cdmlib/lib/commons-math3-3.6.1.jar
new file mode 100644 (file)
index 0000000..0ff582c
Binary files /dev/null and b/eu.etaxonomy.taxeditor.cdmlib/lib/commons-math3-3.6.1.jar differ
index 5a25d8c5ddde6227088d0c50dffc4e693d4fa7d3..d84cc8ae208a206384c2a6e885b7e5d41c7c2c14 100644 (file)
@@ -8,8 +8,10 @@
 */
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
 
 */
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.math3.stat.Frequency;
 
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.State;
 
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.State;
@@ -22,23 +24,28 @@ import eu.etaxonomy.cdm.model.description.State;
 public class CategoricalDataHistogram {
 
     private Feature feature;
 public class CategoricalDataHistogram {
 
     private Feature feature;
-    private Map<State, Integer> stateCountMap;
+    private Frequency frequency;
+    private List<State> states;
 
     public CategoricalDataHistogram(Feature feature) {
         this.feature = feature;
 
     public CategoricalDataHistogram(Feature feature) {
         this.feature = feature;
-        this.stateCountMap = new HashMap<>();
+        this.states = new ArrayList<>();
+        this.frequency = new Frequency();
         feature.getSupportedCategoricalEnumerations()
         .forEach(voc->voc.getTerms()
         feature.getSupportedCategoricalEnumerations()
         .forEach(voc->voc.getTerms()
-                .forEach(state->stateCountMap.put(state, 0)));
+                .forEach(state->states.add(state)));
     }
 
     public void addState(State state){
     }
 
     public void addState(State state){
-        Integer integer = stateCountMap.get(state);
-        stateCountMap.put(state, integer+1);
+        frequency.addValue(state.getLabel());
+    }
+
+    public long getCount(State state){
+        return frequency.getCount(state.getLabel());
     }
 
     }
 
-    public Map<State, Integer> getStateCountMap() {
-        return stateCountMap;
+    public List<State> getStates() {
+        return states;
     }
 
     public Feature getFeature() {
     }
 
     public Feature getFeature() {
index 607024892262ef9dbcf28f02d5021926921ec88a..f586ffc54701c3db4108dcc04a51c16fffacfbea 100644 (file)
@@ -8,9 +8,7 @@
 */
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
 
 */
 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
 
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
+import java.util.List;
 
 import org.eclipse.jface.window.ToolTip;
 import org.eclipse.swt.SWT;
 
 import org.eclipse.jface.window.ToolTip;
 import org.eclipse.swt.SWT;
@@ -57,22 +55,25 @@ public class ChartTooltip extends ToolTip {
         Chart chart = new Chart(parent, SWT.NONE);
         chart.setLayoutData(new GridData(600, 300));
 
         Chart chart = new Chart(parent, SWT.NONE);
         chart.setLayoutData(new GridData(600, 300));
 
+        //get histogram for column
         int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
         int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
         Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
         CategoricalDataHistogram histogram = matrix.getFeatureToHistogramMap().get(feature);
 
         int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
         int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
         Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
         CategoricalDataHistogram histogram = matrix.getFeatureToHistogramMap().get(feature);
 
-        // set titles
+        // set chart title
         chart.getTitle().setText(feature.getLabel());
         IAxis xAxis = chart.getAxisSet().getXAxis(0);
         chart.getTitle().setText(feature.getLabel());
         IAxis xAxis = chart.getAxisSet().getXAxis(0);
-        Map<State, Integer> stateCountMap = histogram.getStateCountMap();
-        String[] states = new String[stateCountMap.size()];
-        double[] counts = new double[stateCountMap.size()];
+
+        //initalize x and y axis values
+        List<State> statesList = histogram.getStates();
+        String[] states = new String[statesList.size()];
+        double[] counts = new double[statesList.size()];
+
         int index = 0;
         int index = 0;
-        for(Iterator<Entry<State, Integer>> iterator = histogram.getStateCountMap().entrySet().iterator();iterator.hasNext();){
-            Entry<State, Integer> entry = iterator.next();
-            states[index] = entry.getKey().getLabel();
-            counts[index] = entry.getValue();
+        for (State state : statesList) {
+            states[index] = state.getLabel();
+            counts[index] = histogram.getCount(state);
             index++;
         }
         xAxis.setCategorySeries(states);
             index++;
         }
         xAxis.setCategorySeries(states);
@@ -82,12 +83,9 @@ public class ChartTooltip extends ToolTip {
 
         IAxis yAxis = chart.getAxisSet().getYAxis(0);
         yAxis.getTitle().setVisible(false);
 
         IAxis yAxis = chart.getAxisSet().getYAxis(0);
         yAxis.getTitle().setVisible(false);
-//        yAxis.getTick().setVisible(false);
 
 
-//        chart.setOrientation(SWT.VERTICAL);
         chart.getLegend().setVisible(false);
 
         chart.getLegend().setVisible(false);
 
-        // create bar series
         IBarSeries barSeries = (IBarSeries) chart.getSeriesSet()
             .createSeries(SeriesType.BAR, "state counts");
         ISeriesLabel seriesLabel = barSeries.getLabel();
         IBarSeries barSeries = (IBarSeries) chart.getSeriesSet()
             .createSeries(SeriesType.BAR, "state counts");
         ISeriesLabel seriesLabel = barSeries.getLabel();
@@ -95,7 +93,6 @@ public class ChartTooltip extends ToolTip {
         seriesLabel.setVisible(true);
         barSeries.setYSeries(counts);
 
         seriesLabel.setVisible(true);
         barSeries.setYSeries(counts);
 
-        // adjust the axis range
         chart.getAxisSet().adjustRange();
 
         return chart;
         chart.getAxisSet().adjustRange();
 
         return chart;
@@ -116,7 +113,7 @@ public class ChartTooltip extends ToolTip {
                 && rowPos==1
                 && colIndex>=CharacterMatrix.LEADING_COLUMN_COUNT
                 && histogram!=null
                 && rowPos==1
                 && colIndex>=CharacterMatrix.LEADING_COLUMN_COUNT
                 && histogram!=null
-                && !histogram.getStateCountMap().isEmpty()) {
+                && !histogram.getStates().isEmpty()) {
             return true;
         }
         return false;
             return true;
         }
         return false;