Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/utils/DataUtil.java @ 1747:d2a17e990c70
Improved the Themes: we now support special themes for facets which need to match a given pattern string.
flys-artifacts/trunk@3047 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 20 Oct 2011 13:45:45 +0000 |
parents | 03fbf1b30e72 |
children | 8afd6a9bb244 |
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 |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
5 import gnu.trove.TDoubleArrayList; |
1163
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 { |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
9 public static boolean guessWaterIncreasing(TDoubleArrayList data) { |
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
10 return guessWaterIncreasing(data, 0.05f); |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 } |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
12 |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
13 public static boolean guessWaterIncreasing(TDoubleArrayList data, float factor) { |
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
14 int N = data.size(); |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 if (N < 2) return false; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
16 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
17 int samples = (int)(factor*N) + 1; |
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 up = 0; |
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 Random rand = new Random(); |
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 for (int i = 0; i < samples; ++i) { |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 int pos2 = rand.nextInt(N-1) + 1; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 int pos1 = rand.nextInt(pos2); |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
26 double w1 = data.getQuick(pos1); |
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
27 double w2 = data.getQuick(pos2); |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
28 if (w2 > w1) ++up; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
29 } |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 return up > samples/2; |
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 } |