Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/OfficialLineFinder.java @ 6397:f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 21 Jun 2013 17:36:50 +0200 |
parents | d2803cc7a338 |
children | 1e97d2e95410 |
rev | line source |
---|---|
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
3 * |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
7 */ |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
8 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
9 package org.dive4elements.river.artifacts.model; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
10 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.ArrayList; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.util.Collections; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
13 import java.util.HashMap; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
14 import java.util.List; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
15 import java.util.Map; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
17 import net.sf.ehcache.Cache; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
18 import net.sf.ehcache.Element; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
19 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 import org.dive4elements.river.artifacts.D4EArtifact; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
21 import org.dive4elements.river.artifacts.cache.CacheFactory; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
22 import org.dive4elements.river.model.Gauge; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
23 import org.dive4elements.river.model.MainValue; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
24 import org.dive4elements.river.model.NamedMainValue; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
25 import org.dive4elements.river.model.OfficialLine; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
26 import org.dive4elements.river.model.River; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
27 import org.dive4elements.river.model.Wst; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
28 import org.dive4elements.river.model.WstColumn; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
29 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
30 public class OfficialLineFinder |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
31 { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
32 public static final String CACHE_NAME = "official-lines"; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
33 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
34 // We will only have one entry in this cache. |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
35 public static final String CACHE_KEY = CACHE_NAME; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
36 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
37 public static final double EPSILON = 1e-4; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
38 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
39 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
40 public static class ValueRange extends Range { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
41 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
42 private double value; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
43 private int wstId; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
44 private int columnPos; |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
45 private String name; |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
46 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
47 public ValueRange( |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
48 double start, |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
49 double end, |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
50 double value, |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
51 int wstId, |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
52 int columnPos, |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
53 String name |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
54 ) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
55 super(start, end); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
56 this.value = value; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
57 this.wstId = wstId; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
58 this.columnPos = columnPos; |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
59 this.name = name; |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
61 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
62 public boolean sameValue(double value) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
63 return Math.abs(value - this.value) < EPSILON; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
64 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
65 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
66 public int getWstId() { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
67 return wstId; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
68 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
69 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
70 public int getColumnPos() { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
71 return columnPos; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
72 } |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
73 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
74 public boolean intersectsValueRange(Range r) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
75 return r.inside(value); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
76 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
77 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
78 public String getName() { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
79 return name; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
80 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
81 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
82 @Override |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
83 public boolean equals(Object o) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
84 if (!(o instanceof ValueRange)) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
85 return false; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
86 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
87 ValueRange r = (ValueRange)o; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
88 return wstId == r.wstId && columnPos == r.columnPos; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
89 } |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
91 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
92 public OfficialLineFinder() { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
94 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
95 public static Map<String, List<ValueRange>> getAll() { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
96 Cache cache = CacheFactory.getCache(CACHE_NAME); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
97 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
98 if (cache == null) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
99 return getAllUncached(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
101 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
102 Element element = cache.get(CACHE_KEY); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
103 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
104 if (element != null) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
105 return (Map<String, List<ValueRange>>)element.getValue(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
106 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
107 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
108 Map<String, List<ValueRange>> result = getAllUncached(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
109 if (result != null) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
110 cache.put(new Element(CACHE_KEY, result)); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
112 return result; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
113 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
114 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
115 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
116 public static Map<String, List<ValueRange>> getAllUncached() { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
117 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
118 Map<String, List<ValueRange>> rivers2officialLines = |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
119 new HashMap<String, List<ValueRange>>(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
120 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
121 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
122 for (OfficialLine line: OfficialLine.fetchAllOfficalLines()) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
123 String name = line.getNamedMainValue().getName(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
124 WstColumn wc = line.getWstColumn(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
125 Wst wst = wc.getWst(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
126 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
127 List<ValueRange> ranges = new ArrayList<ValueRange>(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
128 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
129 River river = wst.getRiver(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
130 List<Gauge> gauges = river.getGauges(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
131 for (Gauge gauge: gauges) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
132 List<MainValue> mainValues = gauge.getMainValues(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
133 for (MainValue mainValue: mainValues) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
134 NamedMainValue nmv = mainValue.getMainValue(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
135 if (nmv.getName().equalsIgnoreCase(name)) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
136 // found gauge with this main value |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
137 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
138 double from = gauge.getRange().getA().doubleValue(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
139 double to = gauge.getRange().getA().doubleValue(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
140 double value = mainValue.getValue().doubleValue(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
141 int wstId = wst.getId(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
142 int pos = wc.getPosition(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
143 ValueRange range = |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
144 new ValueRange(from, to, value, wstId, pos, name); |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
145 ranges.add(range); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
146 break; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
147 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
148 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
149 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
150 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
151 if (!ranges.isEmpty()) { |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
152 rivers2officialLines.put(river.getName(), ranges); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
153 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
154 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
155 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
156 return rivers2officialLines; |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
157 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
158 |
6395
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
159 public static final Range MAX_RANGE = new Range(-Double.MAX_VALUE, +Double.MAX_VALUE); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
160 |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
161 private static final String nn(String s) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
162 return s != null ? s : ""; |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
163 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
164 |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
165 public static Range extractRange(D4EArtifact artifact) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
166 String mode = nn(artifact.getDataAsString("ld_mode")); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
167 String locations = nn(artifact.getDataAsString("ld_locations")); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
168 String from = nn(artifact.getDataAsString("ld_from")); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
169 String to = nn(artifact.getDataAsString("ld_to")); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
170 |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
171 if (mode.equals("location")) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
172 try { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
173 String loc = locations.replace(" ", ""); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
174 String[] split = loc.split(","); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
175 if (split.length < 1) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
176 return MAX_RANGE; |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
177 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
178 double min = Double.parseDouble(split[0]); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
179 double max = min; |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
180 for (int i = 1; i < split.length; ++i) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
181 double v = Double.parseDouble(split[i]); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
182 if (v > max) max = v; |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
183 if (v < min) min = v; |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
184 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
185 return new Range(min, max); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
186 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
187 catch (NumberFormatException nfe) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
188 return MAX_RANGE; |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
189 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
190 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
191 try { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
192 return new Range(Double.parseDouble(from), Double.parseDouble(to)); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
193 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
194 catch (NumberFormatException nfe) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
195 return MAX_RANGE; |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
196 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
197 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
198 |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
199 private static List<ValueRange> filterByRange(Range range, List<ValueRange> ranges) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
200 List<ValueRange> list = new ArrayList<ValueRange>(ranges.size()); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
201 for (ValueRange r: ranges) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
202 if (r.intersects(range)) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
203 list.add(r); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
204 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
205 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
206 return list; |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
207 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
208 |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
209 private static List<ValueRange> filterByQRange(Range range, List<ValueRange> ranges) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
210 List<ValueRange> list = new ArrayList<ValueRange>(ranges.size()); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
211 for (ValueRange r: ranges) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
212 if (r.intersectsValueRange(range) && !list.contains(r)) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
213 list.add(r); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
214 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
215 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
216 return list; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
217 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
218 |
6395
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
219 private static boolean isQ(D4EArtifact artifact) { |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
220 Boolean b = artifact.getDataAsBoolean("wq_isq"); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
221 return b != null && b; |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
222 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
223 |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
224 private static boolean isRange(D4EArtifact artifact) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
225 Boolean b = artifact.getDataAsBoolean("wq_isrange"); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
226 return b != null && b; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
227 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
228 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
229 public static final Range Q_OUT_OF_RANGE = new Range(-10000, -9999); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
230 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
231 private static Range singleQs(D4EArtifact artifact) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
232 String singleData = nn(artifact.getDataAsString("wq_single")); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
233 double min = Double.MAX_VALUE; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
234 double max = -Double.MAX_VALUE; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
235 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
236 for (String value: singleData.split(" ")) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
237 try { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
238 double x = Double.parseDouble(value); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
239 if (x < min) min = x; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
240 if (x > max) max = x; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
241 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
242 catch (NumberFormatException nfe) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
243 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
244 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
245 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
246 return min == Double.MAX_VALUE |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
247 ? Q_OUT_OF_RANGE |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
248 : new Range(min, max); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
249 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
250 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
251 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
252 private static Range qRange(D4EArtifact artifact) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
253 try { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
254 Double from = artifact.getDataAsDouble("wq_from"); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
255 Double to = artifact.getDataAsDouble("wq_to"); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
256 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
257 if (from == null || to == null) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
258 return Q_OUT_OF_RANGE; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
259 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
260 double f = from; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
261 double t = to; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
262 return new Range(Math.min(f, t), Math.max(f, t)); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
263 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
264 catch (NumberFormatException nfe) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
265 return Q_OUT_OF_RANGE; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
266 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
267 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
268 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
269 private static Range tripleQRange(D4EArtifact artifact) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
270 String rangesData = nn(artifact.getDataAsString("wq_values")); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
271 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
272 double min = Double.MAX_VALUE; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
273 double max = -Double.MAX_VALUE; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
274 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
275 for (String range: rangesData.split(":")) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
276 String [] parts = range.split(";"); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
277 if (parts.length < 3) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
278 continue; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
279 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
280 String [] values = parts[2].split(","); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
281 for (String value: values) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
282 try { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
283 double x = Double.parseDouble(value); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
284 if (x < min) min = x; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
285 if (x > max) max = x; |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
286 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
287 catch (NumberFormatException nfe) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
288 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
289 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
290 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
291 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
292 return min == Double.MAX_VALUE |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
293 ? Q_OUT_OF_RANGE |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
294 : new Range(min, max); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
295 } |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
296 |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
297 public static List<ValueRange> findOfficialLines(D4EArtifact artifact) { |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
298 |
6395
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
299 if (!isQ(artifact)) { // Only handle Q calculations |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
300 return Collections.<ValueRange>emptyList(); |
6395
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
301 } |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
302 |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
303 Map<String, List<ValueRange>> rivers2officialLines = getAll(); |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
304 |
6395
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
305 String riverName = nn(artifact.getDataAsString("river")); |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
306 |
6395
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
307 List<ValueRange> ranges = rivers2officialLines.get(riverName); |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
308 |
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
309 if (ranges == null) { |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
310 return Collections.<ValueRange>emptyList(); |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
311 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
312 |
6395
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
313 ranges = filterByRange(extractRange(artifact), ranges); |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
314 |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
315 if (ranges.isEmpty()) { |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
316 return Collections.<ValueRange>emptyList(); |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
317 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
318 |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
319 Range qRange = isRange(artifact) |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
320 ? qRange(artifact) |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
321 : singleQs(artifact); |
6395
d2803cc7a338
Artifacts: Official lines: Only apply in Q-Calculations and filter against the ranges of the gauges.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6385
diff
changeset
|
322 |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
323 if (qRange == Q_OUT_OF_RANGE) { |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
324 qRange = tripleQRange(artifact); |
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
325 } |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
326 |
6397
f579e4a80b84
Artifacts: Official lines finder: handle the cases from the state model.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6395
diff
changeset
|
327 return filterByQRange(qRange, ranges); |
6385
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
328 } |
ef08c4f57ede
Artifacts: First part of the official lines guessing.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
329 } |