Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/utils/DataUtil.java @ 1178:1b432c260e97
Enabled the FloodMapState to fetch waterlevel data from external Artifact.
flys-artifacts/trunk@2764 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Sep 2011 15:36:05 +0000 |
parents | 2e0739853807 |
children | 03fbf1b30e72 |
rev | line source |
---|---|
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.utils; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
2 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
3 import java.util.Random; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
4 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
5 import de.intevation.flys.artifacts.model.WKms; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
6 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
7 public class DataUtil |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
8 { |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
9 // TODO: resolve duplicate in WQKms |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
10 public static boolean guessWaterIncreasing(WKms wkms) { |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 return guessWaterIncreasing(wkms, 0.05f); |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
12 } |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
13 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
14 // TODO: resolve duplicate in WQKms |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 public static boolean guessWaterIncreasing(WKms wkms, float factor) { |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
16 int N = wkms.size(); |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
17 if (N < 2) return false; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
18 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 int samples = (int)(factor*N) + 1; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
20 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 int up = 0; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
22 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 Random rand = new Random(); |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 for (int i = 0; i < samples; ++i) { |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
26 int pos2 = rand.nextInt(N-1) + 1; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
27 if (pos2 == 0) continue; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
28 int pos1 = rand.nextInt(pos2); |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
29 double w1 = wkms.getW(pos1); |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 double w2 = wkms.getW(pos2); |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 if (w2 > w1) ++up; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 } |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 return up > samples/2; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 } |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
36 } |