Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java @ 3141:3582e87e9171
FixA: Made GaugeRange a top level class.
flys-artifacts/trunk@4749 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 21 Jun 2012 15:39:34 +0000 |
parents | 9c147bbffc36 |
children | 9aed2e4de3ca |
comparison
equal
deleted
inserted
replaced
3140:3d456d8bca6e | 3141:3582e87e9171 |
---|---|
6 | 6 |
7 import java.util.ArrayList; | 7 import java.util.ArrayList; |
8 import java.util.Collections; | 8 import java.util.Collections; |
9 import java.util.Comparator; | 9 import java.util.Comparator; |
10 import java.util.Date; | 10 import java.util.Date; |
11 import java.util.HashMap; | |
12 import java.util.List; | 11 import java.util.List; |
13 import java.util.Map; | |
14 | 12 |
15 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
16 | 14 |
17 import org.hibernate.SQLQuery; | 15 import org.hibernate.SQLQuery; |
18 import org.hibernate.Session; | 16 import org.hibernate.Session; |
25 public class FixingsOverview | 23 public class FixingsOverview |
26 implements Serializable | 24 implements Serializable |
27 { | 25 { |
28 private static Logger log = Logger.getLogger(FixingsOverview.class); | 26 private static Logger log = Logger.getLogger(FixingsOverview.class); |
29 | 27 |
30 public static final double EPSILON = 1e-5; | 28 public static final double EPSILON = 1e-1; |
31 public static final double EPSILON2 = 1e-1; | |
32 | 29 |
33 public static final String DATE_FORMAT = "dd.MM.yyyy"; | 30 public static final String DATE_FORMAT = "dd.MM.yyyy"; |
34 | 31 |
35 public static final String SQL_RIVER_ID = | 32 public static final String SQL_RIVER_ID = |
36 "SELECT" + | 33 "SELECT" + |
112 "FROM" + | 109 "FROM" + |
113 " wst_column_values " + | 110 " wst_column_values " + |
114 "WHERE" + | 111 "WHERE" + |
115 " wst_column_id = :column_id"; | 112 " wst_column_id = :column_id"; |
116 | 113 |
117 public static class GaugeRange extends Range { | |
118 | |
119 private static final class Sector implements Serializable { | |
120 | |
121 int sector; | |
122 double value; | |
123 | |
124 Sector(int sector, double value) { | |
125 this.sector = sector; | |
126 this.value = value; | |
127 } | |
128 | |
129 } // class Sector | |
130 | |
131 protected int gaugeId; | |
132 | |
133 protected Map<String, Double> mainValues; | |
134 protected List<Sector> sectors; | |
135 | |
136 public GaugeRange() { | |
137 } | |
138 | |
139 public GaugeRange(double start, double end, int gaugeId) { | |
140 super(start, end); | |
141 this.gaugeId = gaugeId; | |
142 mainValues = new HashMap<String, Double>(); | |
143 sectors = new ArrayList<Sector>(3); | |
144 } | |
145 | |
146 public void addMainValue(String label, Double value) { | |
147 int idx = label.indexOf('('); | |
148 if (idx >= 0) { | |
149 label = label.substring(0, idx); | |
150 } | |
151 mainValues.put(label, value); | |
152 } | |
153 | |
154 protected Double getMainValue(String label) { | |
155 Double v = mainValues.get(label); | |
156 if (v == null) { | |
157 log.warn("Missing main value '" | |
158 + label + "' for gauge " + gaugeId); | |
159 } | |
160 return v; | |
161 } | |
162 | |
163 public void buildClasses() { | |
164 Double mnq = getMainValue("MNQ"); | |
165 Double mq = getMainValue("MQ"); | |
166 Double mhq = getMainValue("MHQ"); | |
167 Double hq5 = getMainValue("HQ5"); | |
168 | |
169 Double [][] pairs = { | |
170 { mnq, mq }, | |
171 { mq, mhq }, | |
172 { hq5, hq5 } }; | |
173 | |
174 for (int c = 0; c < pairs.length; ++c) { | |
175 Double [] pair = pairs[c]; | |
176 if (pair[0] != null && pair[1] != null) { | |
177 double value = 0.5*(pair[0] + pair[1]); | |
178 sectors.add(new Sector(c, value)); | |
179 } | |
180 } | |
181 } | |
182 | |
183 public int classify(double value) { | |
184 for (Sector sector: sectors) { | |
185 if (value < sector.value) { | |
186 return sector.sector; | |
187 } | |
188 } | |
189 return sectors.size(); | |
190 } | |
191 } // class GaugeRange | |
192 | 114 |
193 public static class GaugeFinder { | 115 public static class GaugeFinder { |
194 | 116 |
195 protected List<GaugeRange> gauges; | 117 protected List<GaugeRange> gauges; |
196 protected boolean isKmUp; | 118 protected boolean isKmUp; |
310 return sector; | 232 return sector; |
311 } | 233 } |
312 | 234 |
313 public boolean enlarge(SectorRange other) { | 235 public boolean enlarge(SectorRange other) { |
314 if (sector == other.sector | 236 if (sector == other.sector |
315 && Math.abs(end-other.start) < EPSILON2) { | 237 && Math.abs(end-other.start) < EPSILON) { |
316 end = other.end; | 238 end = other.end; |
317 return true; | 239 return true; |
318 } | 240 } |
319 return false; | 241 return false; |
320 } | 242 } |