Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/DataUtil.java @ 1190:f514894ec2fd
merged flys-artifacts/2.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:17 +0200 |
parents | 2e0739853807 |
children | 03fbf1b30e72 |
comparison
equal
deleted
inserted
replaced
917:b48c36076e17 | 1190:f514894ec2fd |
---|---|
1 package de.intevation.flys.utils; | |
2 | |
3 import java.util.Random; | |
4 | |
5 import de.intevation.flys.artifacts.model.WKms; | |
6 | |
7 public class DataUtil | |
8 { | |
9 // TODO: resolve duplicate in WQKms | |
10 public static boolean guessWaterIncreasing(WKms wkms) { | |
11 return guessWaterIncreasing(wkms, 0.05f); | |
12 } | |
13 | |
14 // TODO: resolve duplicate in WQKms | |
15 public static boolean guessWaterIncreasing(WKms wkms, float factor) { | |
16 int N = wkms.size(); | |
17 if (N < 2) return false; | |
18 | |
19 int samples = (int)(factor*N) + 1; | |
20 | |
21 int up = 0; | |
22 | |
23 Random rand = new Random(); | |
24 | |
25 for (int i = 0; i < samples; ++i) { | |
26 int pos2 = rand.nextInt(N-1) + 1; | |
27 if (pos2 == 0) continue; | |
28 int pos1 = rand.nextInt(pos2); | |
29 double w1 = wkms.getW(pos1); | |
30 double w2 = wkms.getW(pos2); | |
31 if (w2 > w1) ++up; | |
32 } | |
33 | |
34 return up > samples/2; | |
35 } | |
36 } |