[PATCH] (issue1755) Do not create interpolated themes and disable export of non interpolatable data

Wald Commits scm-commit at wald.intevation.org
Wed Apr 1 17:10:21 CEST 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1427901003 -7200
# Node ID dbec49147f54d83ebb4f2903ae2de8ce1a2cca96
# Parent  22f01b7e802e392189ec1cdc04f1b350173fedbc
(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

diff -r 22f01b7e802e -r dbec49147f54 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityResultValue.java
--- 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) {
diff -r 22f01b7e802e -r dbec49147f54 artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityState.java
--- 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()));
+                }
             }
         }
     }
diff -r 22f01b7e802e -r dbec49147f54 artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java
--- 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();


More information about the Dive4Elements-commits mailing list