changeset 1626:b9b47af71564

Preparations for ability to display multiple differences in one plot. flys-artifacts/trunk@2801 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 21 Sep 2011 13:49:50 +0000
parents c45e8d6b99a2
children d1b20d0e9eb4
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java
diffstat 2 files changed, 54 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Sep 21 13:03:54 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Sep 21 13:49:50 2011 +0000
@@ -1,3 +1,11 @@
+2011-09-21  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+ Improved WDifferenceState in preparation to be able to deal with multiple
+ pairs for differences.
+
+	* src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java:
+	  Prepare multiple-pairs-case.
+
 2011-09-21  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue315 (Überschwemmungsfläche: String bei Streckenauswahl)
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java	Wed Sep 21 13:03:54 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java	Wed Sep 21 13:49:50 2011 +0000
@@ -85,56 +85,57 @@
             }
         }
 
-        if (datas.length != 2) {
+        if (datas.length < 2) {
             // TODO crash with style
             ;
         }
-        String uuid1 = WaterlevelSelectState.strip(datas[0]).split(";")[0];
-        String uuid2 = WaterlevelSelectState.strip(datas[1]).split(";")[0];
-
-        WINFOArtifact flys1 = (WINFOArtifact) FLYSUtils.getArtifact(
-            uuid1,
-            context);
-        WINFOArtifact flys2 = (WINFOArtifact) FLYSUtils.getArtifact(
-            uuid2,
-            context);
-
-        if (flys1 == null) {
-            logger.warn("One of the artifacts (1) for diff calculation could not be loaded");
-        }
-        if (flys2 == null) {
-            logger.warn("One of the artifacts (2) for diff calculation could not be loaded");
-        }
-        WKms wkms = null;
-        String facetName = "diff ()";
 
-        if (flys1 != null && flys2 != null) {
-            // TODO also check size.
-            // TODO also need index of wqkms.
-            WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData().getData();
-            WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData().getData();
-            wkms = WKmsOperation.SUBTRACTION.operate(minuend[0], subtrahend[0]);
-            facetName = "W ("+minuend[0].getName() + ") - W (" + subtrahend[0].getName()+")";
-            logger.warn("Did a WKMSSubtraction");
-            // Add these datasets also as facets ("absolutes").
-            /*
-            Facet minuendAbsFacet = new WaterlevelFacet(0, LONGITUDINAL_W,
-                "Minuend: W (_todo_)", ComputeType.ADVANCE, id, hash);
-            Facet subtrahendAbsFacet = new WaterlevelFacet(1, LONGITUDINAL_W,
-                "Subtrahend: W (_todo_)", ComputeType.ADVANCE, id, hash);
-            */
-            //facets.add(minuendAbsFacet);
-            //facets.add(subtrahendAbsFacet);
-        }
+        WKms wkms = null;
 
-        if (facets != null) {
-            // TODO: pass computetype and state id.
-            //, ComputeType.ADVANCE, getID(), hash));
-            facets.add(new DataFacet(W_DIFFERENCES, facetName));
-            facets.add(new DataFacet(CSV, "CSV data"));
-        }
-        else {
-            logger.debug("Not adding facets in WDifferencesState.");
+        for(int i = 0; i < datas.length /2; i++) {
+            String uuid1 = WaterlevelSelectState.strip(datas[i+0]).split(";")[0];
+            String uuid2 = WaterlevelSelectState.strip(datas[i+1]).split(";")[0];
+    
+            WINFOArtifact flys1 = (WINFOArtifact) FLYSUtils.getArtifact(
+                uuid1,
+                context);
+            WINFOArtifact flys2 = (WINFOArtifact) FLYSUtils.getArtifact(
+                uuid2,
+                context);
+    
+            if (flys1 == null) {
+                logger.warn("One of the artifacts (1) for diff calculation could not be loaded");
+            }
+            if (flys2 == null) {
+                logger.warn("One of the artifacts (2) for diff calculation could not be loaded");
+            }
+            // TODO: Issue of multiple results in calculation
+            //WKms wkms = null;
+            String facetName = "diff ()";
+    
+            if (flys1 != null && flys2 != null) {
+                // TODO Also check size.
+                // TODO Also need index of wqkms.
+                WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData().getData();
+                WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData().getData();
+
+                if (datas.length > 2) {
+                    logger.error("Cannot keep more than one calculation.");
+                }
+                wkms = WKmsOperation.SUBTRACTION.operate(minuend[0], subtrahend[0]);
+                facetName = "W ("+minuend[0].getName() + ") - W (" + subtrahend[0].getName()+")";
+                logger.debug("WKMSSubtraction happened");
+            }
+    
+            if (facets != null) {
+                // TODO: pass computetype and state id.
+                //, ComputeType.ADVANCE, getID(), hash));
+                facets.add(new DataFacet(W_DIFFERENCES, facetName));
+                facets.add(new DataFacet(CSV, "CSV data"));
+            }
+            else {
+                logger.debug("Not adding facets in WDifferencesState.");
+            }
         }
 
         return wkms;

http://dive4elements.wald.intevation.org