changeset 8653:dbec49147f54

(issue1755) Do not create interpolated themes and disable export of non interpolatable data. Due to the fact that data can contain NaN's which will be filtered out before creating the interpolator this requires the actual check for interpolatable data when data is set in the ResultValue
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 01 Apr 2015 17:10:03 +0200
parents 22f01b7e802e
children bf8590046120
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityResultValue.java artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityState.java artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java
diffstat 3 files changed, 39 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityResultValue.java	Wed Apr 01 13:11:30 2015 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityResultValue.java	Wed Apr 01 17:10:03 2015 +0200
@@ -56,12 +56,15 @@
     private String      type;
     private double [][] data;
     private transient PolynomialSplineFunction interpolFunc;
+    private boolean isInterpolatableData;
 
     public BedQualityResultValue() {
+        isInterpolatableData = false;
     }
 
     public BedQualityResultValue(String name, double [][] data, String type) {
         this.name = name;
+        isInterpolatableData = false;
         setData(data);
         this.type = type;
     }
@@ -74,6 +77,10 @@
         return data == null || data.length < 2 || data[0].length == 0;
     }
 
+    public boolean isInterpolateable() {
+        return isInterpolatableData;
+    }
+
     public void setName(String name) {
         this.name = name;
     }
@@ -113,6 +120,19 @@
 
     public void setData(double [][] data) {
         this.data = data;
+
+        if (!isEmpty() && data[0].length > 1 && data[0].length == data[1].length) {
+            int usable_points = 0;
+            for (double val :data[1]) {
+                if (!Double.isNaN(val)) {
+                    usable_points++;
+                }
+                if (usable_points == 2) {
+                    isInterpolatableData = true;
+                    return;
+                }
+            }
+        }
     }
 
     public void setType(String type) {
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityState.java	Wed Apr 01 13:11:30 2015 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityState.java	Wed Apr 01 17:10:03 2015 +0200
@@ -271,11 +271,13 @@
                     getFacetDescription(meta, range, value),
                     ComputeType.ADVANCE,
                     stateId, hash, value.getName(), value.getType()));
-                newFacets.add(new BedQualityInterpolFacet((idx << 8) + i++,
-                    getFacetName(value) + ".interpol",
-                    getFacetInterpolDescription(meta, range, value),
-                    ComputeType.ADVANCE,
-                    stateId, hash, value.getName(), value.getType()));
+                if (value.isInterpolateable()) {
+                    newFacets.add(new BedQualityInterpolFacet((idx << 8) + i++,
+                        getFacetName(value) + ".interpol",
+                        getFacetInterpolDescription(meta, range, value),
+                        ComputeType.ADVANCE,
+                        stateId, hash, value.getName(), value.getType()));
+                }
             }
         }
     }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java	Wed Apr 01 13:11:30 2015 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java	Wed Apr 01 17:10:03 2015 +0200
@@ -53,7 +53,12 @@
 
         int cols = 1;
         for (BedQualityResult result: results) {
-            cols += result.getValues().size();
+            for (BedQualityResultValue value :result.getValues()) {
+                if (value.isInterpolateable()) {
+                    /* Only add results that can be interpolated */
+                    cols++;
+                }
+            }
         }
         if (cols == 1) {
             return new ArrayList<double[]>();
@@ -67,7 +72,9 @@
             for (BedQualityResult result: results) {
                 int i = resultOffset;
                 for (BedQualityResultValue value: result.getValues()) {
-                    row[i++] = value.getDataInterpolated(km);
+                    if (value.isInterpolateable()) {
+                        row[i++] = value.getDataInterpolated(km);
+                    }
                 }
                 resultOffset = i;
             }
@@ -135,6 +142,9 @@
             String d1 = df.format(result.getDateRange().getFrom());
             String d2 = df.format(result.getDateRange().getTo());
             for (BedQualityResultValue value: result.getValues()) {
+                if (!value.isInterpolateable()) {
+                    continue;
+                }
                 String i18n;
                 if (value.isDiameterResult()) {
                     i18n = CSV_HEADER_BASE + ".diameter." + value.getType();

http://dive4elements.wald.intevation.org