Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/utils/DataUtil.java @ 8587:07c9ac22f611
(issue1755) Generalise BedQuality result handling
The bedquality calculation now produces a result for each time period
which has BedQualityResultValues for each specific result type.
Formally this was split up in density, porosity and diameter classes
with some bedload diameter classes mixed in for extra fun.
The intent of this commit is to allow more shared code and generic
access patterns to the BedQuality results.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 18 Mar 2015 18:42:08 +0100 |
parents | 3c4efd4b2c19 |
children | 5e38e2924c07 |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
9 package org.dive4elements.river.utils; |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
10 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 import java.util.Random; |
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 import gnu.trove.TDoubleArrayList; |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
14 |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 public class DataUtil |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
16 { |
7081
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
17 public static boolean guessDataIncreasing(TDoubleArrayList data) { |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
18 return guessDataIncreasing(data, 0.05f); |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 } |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
20 |
7081
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
21 /** Guess if data1 and data2 both grow in the same direction */ |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
22 public static boolean guessSameDirectionData(TDoubleArrayList data1, |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
23 TDoubleArrayList data2) { |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
24 boolean d1dir = DataUtil.guessDataIncreasing(data1, 0.05f); |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
25 boolean d2dir = DataUtil.guessDataIncreasing(data2, 0.05f); |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
26 int size = data1.size(); |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
27 return ((d1dir && d2dir) || (!d1dir && !d2dir)) && size > 1; |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
28 } |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
29 |
3c4efd4b2c19
Simplyfy / unify "invert axis" logic
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
30 public static boolean guessDataIncreasing(TDoubleArrayList data, float factor) { |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
31 int N = data.size(); |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 if (N < 2) return false; |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
33 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 int samples = (int)(factor*N) + 1; |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
35 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
36 int up = 0; |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
37 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
38 Random rand = new Random(); |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
39 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 for (int i = 0; i < samples; ++i) { |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
41 int pos2 = rand.nextInt(N-1) + 1; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
42 int pos1 = rand.nextInt(pos2); |
1678
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
43 double w1 = data.getQuick(pos1); |
03fbf1b30e72
Removed code duplication of guessWaterIncreasing()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1163
diff
changeset
|
44 double w2 = data.getQuick(pos2); |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
45 if (w2 > w1) ++up; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
46 } |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1982
diff
changeset
|
47 |
1163
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
48 return up > samples/2; |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
49 } |
2e0739853807
Fix build, added new DataUtil.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
50 } |
1982
8afd6a9bb244
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1678
diff
changeset
|
51 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |