changeset 1163:2e0739853807

Fix build, added new DataUtil. flys-artifacts/trunk@2700 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 12 Sep 2011 11:30:19 +0000
parents 588798ef4791
children 0398c2b8dbaf
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/utils/DataUtil.java
diffstat 2 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Sep 12 11:26:32 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Sep 12 11:30:19 2011 +0000
@@ -1,3 +1,13 @@
+2011-09-12  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+ Copied and slightly modified implementation of guessWaterIncreasing from
+ WQKms to (new) DataUtils. Accidentally commited usage in last commit, to
+ correct orientation of diagram (invert x axis).
+
+	* src/main/java/de/intevation/flys/utils/DataUtils.java:
+	  New file with guessWaterIncreasing implementation from WQKms,
+	  slightly adjusted.
+
 2011-09-12  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
  Cosmetics.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/DataUtil.java	Mon Sep 12 11:30:19 2011 +0000
@@ -0,0 +1,36 @@
+package de.intevation.flys.utils;
+
+import java.util.Random;
+
+import de.intevation.flys.artifacts.model.WKms;
+
+public class DataUtil
+{
+    // TODO: resolve duplicate in WQKms
+    public static boolean guessWaterIncreasing(WKms wkms) {
+        return guessWaterIncreasing(wkms, 0.05f);
+    }
+
+    // TODO: resolve duplicate in WQKms
+    public static boolean guessWaterIncreasing(WKms wkms, float factor) {
+        int N = wkms.size();
+        if (N < 2) return false;
+    
+        int samples = (int)(factor*N) + 1;
+    
+        int up = 0;
+    
+        Random rand = new Random();
+    
+        for (int i = 0; i < samples; ++i) {
+            int    pos2 = rand.nextInt(N-1) + 1;
+            if (pos2 == 0) continue;
+            int    pos1 = rand.nextInt(pos2);
+            double w1   = wkms.getW(pos1);
+            double w2   = wkms.getW(pos2);
+            if (w2 > w1) ++up;
+        }
+    
+        return up > samples/2;
+    }
+}

http://dive4elements.wald.intevation.org