Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java @ 3981:6bcc50e2cc7d
More code for S(Q) relation.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 16:41:08 +0200 |
parents | d3e2080d3ada |
children | a9c93b7c9da1 |
comparison
equal
deleted
inserted
replaced
3980:6cc5186b9b48 | 3981:6bcc50e2cc7d |
---|---|
1 package de.intevation.flys.artifacts.model.sq; | 1 package de.intevation.flys.artifacts.model.sq; |
2 | 2 |
3 import java.util.Map; | 3 import java.util.Map; |
4 | |
5 import org.apache.commons.logging.Log; | |
6 import org.apache.commons.logging.LogFactory; | |
4 | 7 |
5 public class Measurement | 8 public class Measurement |
6 { | 9 { |
10 private static final Log log = | |
11 LogFactory.getLog(Measurement.class); | |
12 | |
13 public static final double ADD_8 = Math.log(10) - Math.log(8)/Math.log(6.3); | |
14 public static final double SCALE_8 = Math.log(6.3); | |
15 | |
16 public static final double ADD_4 = Math.log(8) - Math.log(6.3)/Math.log(10); | |
17 public static final double SCALE_4 = Math.log(6.3); | |
18 | |
19 public static final double [] SIEVE_DIAMETERS = { | |
20 100d, 63d, 31.5d, 16d, | |
21 8d, 4d, 2d, 1d, | |
22 0.5d, 0.25d, 0.125d, 0.063d | |
23 }; | |
24 | |
7 protected Map<String, Object> data; | 25 protected Map<String, Object> data; |
8 | 26 |
9 protected Measurement prev; | 27 protected Measurement prev; |
10 protected Measurement next; | 28 protected Measurement next; |
11 | 29 |
12 public Measurement() { | 30 public Measurement() { |
13 } | 31 } |
14 | 32 |
15 public Measurement(Map<String, Object> data) { | 33 public Measurement(Map<String, Object> data) { |
16 this.data = data; | 34 this.data = data; |
35 } | |
36 | |
37 public Measurement head() { | |
38 Measurement current = this; | |
39 while (current.prev != null) { | |
40 current = current.prev; | |
41 } | |
42 return current; | |
17 } | 43 } |
18 | 44 |
19 protected double get(String name) { | 45 protected double get(String name) { |
20 Number value = (Number)data.get(name); | 46 Number value = (Number)data.get(name); |
21 return value != null ? value.doubleValue() : Double.NaN; | 47 return value != null ? value.doubleValue() : Double.NaN; |
22 } | 48 } |
23 | 49 |
50 protected void set(String name, double value) { | |
51 data.put(name, Double.valueOf(value)); | |
52 } | |
53 | |
54 protected Object getData(String name) { | |
55 return data.get(name); | |
56 } | |
57 | |
58 protected void putData(String name, Object value) { | |
59 data.put(name, value); | |
60 } | |
61 | |
24 public double S_SS() { | 62 public double S_SS() { |
25 return get("TSAND"); | 63 return get("TSAND"); |
26 } | 64 } |
27 | 65 |
28 public double S_SF() { | 66 public double S_SF() { |
71 public double S_BL_2() { | 109 public double S_BL_2() { |
72 return S_SS() + S_BL_S() + S_BL_FG() + S_BL_CG(); | 110 return S_SS() + S_BL_S() + S_BL_FG() + S_BL_CG(); |
73 } | 111 } |
74 | 112 |
75 public double SIEB(int i) { | 113 public double SIEB(int i) { |
76 return get(String.format("SIEB%02d", i)); | 114 return get(siebString(i)); |
77 } | 115 } |
78 | 116 |
79 public double RSIEB(int i) { | 117 public double RSIEB(int i) { |
80 return get(String.format("RSIEB%02d", i)); | 118 return get(rsiebString(i)); |
81 } | 119 } |
82 | 120 |
83 public double REST() { | 121 public double REST() { |
84 return get("REST"); | 122 return get("REST"); |
85 } | 123 } |
122 * @param next The next. | 160 * @param next The next. |
123 */ | 161 */ |
124 public void setNext(Measurement next) { | 162 public void setNext(Measurement next) { |
125 this.next = next; | 163 this.next = next; |
126 } | 164 } |
165 | |
166 protected int findSieveIndex(double diameter) { | |
167 for (int i = 1; i <= 22; ++i) { | |
168 double size = SIEB(i); | |
169 if (Math.abs(size - diameter) < 0.00001) { | |
170 return i; | |
171 } | |
172 } | |
173 return -1; | |
174 } | |
175 | |
176 public static int sieve(double value) { | |
177 for (int i = 0; i < SIEVE_DIAMETERS.length; ++i) { | |
178 if (value >= SIEVE_DIAMETERS[i]) { | |
179 return i+1; | |
180 } | |
181 } | |
182 return SIEVE_DIAMETERS.length; | |
183 } | |
184 | |
185 private static final String rsiebString(int idx) { | |
186 return String.format("RSIEB%02d", idx); | |
187 } | |
188 | |
189 private static final String siebString(int idx) { | |
190 return String.format("SIEB%02d", idx); | |
191 } | |
192 | |
193 private static final String quantString(int idx) { | |
194 return String.format("QUANT%02d", idx); | |
195 } | |
196 | |
197 private static final String normQuantString(int idx) { | |
198 return String.format("NORMQUANT%02d", idx); | |
199 } | |
200 | |
201 protected void deleteSieve(int idx) { | |
202 data.remove(rsiebString(idx)); | |
203 data.remove(siebString(idx)); | |
204 } | |
205 | |
206 protected void putSieve(int idx, double diameter, double value) { | |
207 data.put(rsiebString(idx), Double.valueOf(value)); | |
208 data.put(siebString(idx), Double.valueOf(diameter)); | |
209 } | |
210 | |
211 protected double totalRSIEB() { | |
212 double sum = 0d; | |
213 for (int i = 1; i <= 21; ++i) { | |
214 Double x = (Double)data.get(rsiebString(i)); | |
215 if (x != null) { | |
216 sum += x; | |
217 } | |
218 } | |
219 return sum; | |
220 } | |
221 | |
222 protected double totalQUANT() { | |
223 double sum = 0d; | |
224 for (int i = 1; i <= 22; ++i) { | |
225 Double x = (Double)data.get(quantString(i)); | |
226 if (x != null) { | |
227 sum += x; | |
228 } | |
229 } | |
230 return sum; | |
231 } | |
232 | |
233 public void adjustOriginalSieves() { | |
234 | |
235 // If we already have an 8mm diameter sieve | |
236 // we dont need to 'invent' it. | |
237 if (findSieveIndex(8d) > -1) { | |
238 return; | |
239 } | |
240 | |
241 // create a new 8mm sieve. | |
242 // delete 6.3mm sieve. | |
243 // modify 4mm sieve. | |
244 // | |
245 int sixIdx = findSieveIndex(6.3d); | |
246 int tenIdx = findSieveIndex(10d); | |
247 int fourIdx = findSieveIndex(4d); | |
248 | |
249 if (sixIdx < 0 || tenIdx < 0 || fourIdx < 0) { | |
250 log.warn("missind diameter"); | |
251 return; | |
252 } | |
253 | |
254 double sixValue = RSIEB(sixIdx); | |
255 double tenValue = RSIEB(tenIdx); | |
256 double fourValue = RSIEB(fourIdx); | |
257 | |
258 deleteSieve(sixIdx); | |
259 | |
260 double eightValue = ADD_8 - SCALE_8*sixValue + tenValue; | |
261 double newFourValue = ADD_4 - SCALE_4*sixValue + fourValue; | |
262 | |
263 putSieve(22, 8d, eightValue); | |
264 putSieve(fourIdx, 4d, newFourValue); | |
265 } | |
266 | |
267 | |
268 public void fillSieveCategories() { | |
269 adjustOriginalSieves(); | |
270 | |
271 for (int i = 1; i <= 22; ++i) { | |
272 Double rsieb = (Double)getData(rsiebString(i)); | |
273 Double sieb = (Double)getData(siebString(i)); | |
274 if (rsieb == null || sieb == null) { | |
275 continue; | |
276 } | |
277 | |
278 int idx = sieve(sieb); | |
279 String quantString = quantString(idx); | |
280 Double old = (Double)getData(quantString); | |
281 old = old == null ? 0d : rsieb + old; | |
282 putData(quantString, old); | |
283 } | |
284 | |
285 double totalQUANT = totalQUANT(); | |
286 | |
287 for (int i = 1; i <= 22; ++i) { | |
288 String qs = quantString(i); | |
289 String ns = normQuantString(i); | |
290 Double quant = (Double)getData(qs); | |
291 if (quant == null) { | |
292 putData(ns, Double.valueOf(0d)); | |
293 } | |
294 else { | |
295 putData(ns, quant / totalQUANT); | |
296 } | |
297 } | |
298 } | |
127 } | 299 } |
128 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 300 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |