Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/utils/DataUtil.java @ 4216:a04862abce42
Don't redirect to the login page without query params
Don't redirect to the login page without query params for the development mode.
Therefore just reload the page after the user object is removed from the session
and GGInAFilter will redirect to the correct long URL.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Tue, 23 Oct 2012 10:50:48 +0200 |
parents | 5642a83420f2 |
children |
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; |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
16 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
17 int samples = (int)(factor*N) + 1; |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
18 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 int up = 0; |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
20 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 Random rand = new Random(); |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
22 |
1163
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 } |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
30 |
1163
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 } |
1982
8afd6a9bb244
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1678
diff
changeset
|
34 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |