Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java @ 3992:a9c93b7c9da1
Simpify the S(Q) fraction sieving stuff.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 30 Sep 2012 21:15:23 +0200 |
parents | 6bcc50e2cc7d |
children | ab3a4ad82ae1 |
comparison
equal
deleted
inserted
replaced
3991:3a1cac4bfe70 | 3992:a9c93b7c9da1 |
---|---|
1 package de.intevation.flys.artifacts.model.sq; | 1 package de.intevation.flys.artifacts.model.sq; |
2 | 2 |
3 import java.util.List; | |
3 import java.util.Map; | 4 import java.util.Map; |
4 | 5 |
5 import org.apache.commons.logging.Log; | 6 import org.apache.commons.logging.Log; |
6 import org.apache.commons.logging.LogFactory; | 7 import org.apache.commons.logging.LogFactory; |
7 | 8 |
14 public static final double SCALE_8 = Math.log(6.3); | 15 public static final double SCALE_8 = Math.log(6.3); |
15 | 16 |
16 public static final double ADD_4 = Math.log(8) - Math.log(6.3)/Math.log(10); | 17 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 public static final double SCALE_4 = Math.log(6.3); |
18 | 19 |
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 | |
25 protected Map<String, Object> data; | 20 protected Map<String, Object> data; |
21 | |
22 protected List<Sieve> sieves; | |
23 | |
24 protected SieveArray sieveArray; | |
26 | 25 |
27 protected Measurement prev; | 26 protected Measurement prev; |
28 protected Measurement next; | 27 protected Measurement next; |
29 | 28 |
30 public Measurement() { | 29 public Measurement() { |
31 } | 30 } |
32 | 31 |
33 public Measurement(Map<String, Object> data) { | 32 public Measurement(Map<String, Object> data, List<Sieve> sieves) { |
34 this.data = data; | 33 this.data = data; |
34 this.sieves = sieves; | |
35 adjustOriginalSieves(); | |
36 this.sieveArray = calculateSieveArray(); | |
35 } | 37 } |
36 | 38 |
37 public Measurement head() { | 39 public Measurement head() { |
38 Measurement current = this; | 40 Measurement current = this; |
39 while (current.prev != null) { | 41 while (current.prev != null) { |
108 | 110 |
109 public double S_BL_2() { | 111 public double S_BL_2() { |
110 return S_SS() + S_BL_S() + S_BL_FG() + S_BL_CG(); | 112 return S_SS() + S_BL_S() + S_BL_FG() + S_BL_CG(); |
111 } | 113 } |
112 | 114 |
113 public double SIEB(int i) { | |
114 return get(siebString(i)); | |
115 } | |
116 | |
117 public double RSIEB(int i) { | |
118 return get(rsiebString(i)); | |
119 } | |
120 | |
121 public double REST() { | |
122 return get("REST"); | |
123 } | |
124 | |
125 @Override | 115 @Override |
126 public String toString() { | 116 public String toString() { |
127 return "Measurement: " + data; | 117 return "Measurement: " + data; |
128 } | 118 } |
129 | 119 |
130 /** | 120 /** |
121 * Gets the sieves for this instance. | |
122 * | |
123 * @return The sieves. | |
124 */ | |
125 public List<Sieve> getSieves() { | |
126 return this.sieves; | |
127 } | |
128 | |
129 /** | |
130 * Gets the sieveArray for this instance. | |
131 * | |
132 * @return The sieveArray. | |
133 */ | |
134 public SieveArray getSieveArray() { | |
135 return this.sieveArray; | |
136 } | |
137 | |
138 /** | |
131 * Gets the prev for this instance. | 139 * Gets the prev for this instance. |
132 * | 140 * |
133 * @return The prev. | 141 * @return The prev. |
134 */ | 142 */ |
135 public Measurement getPrev() { | 143 public Measurement getPrev() { |
161 */ | 169 */ |
162 public void setNext(Measurement next) { | 170 public void setNext(Measurement next) { |
163 this.next = next; | 171 this.next = next; |
164 } | 172 } |
165 | 173 |
166 protected int findSieveIndex(double diameter) { | 174 protected Sieve findSieve(double diameter) { |
167 for (int i = 1; i <= 22; ++i) { | 175 for (Sieve s: sieves) { |
168 double size = SIEB(i); | 176 if (s.matchesDiameter(diameter)) { |
169 if (Math.abs(size - diameter) < 0.00001) { | 177 return s; |
170 return i; | |
171 } | 178 } |
172 } | 179 } |
173 return -1; | 180 return null; |
174 } | 181 } |
175 | 182 |
176 public static int sieve(double value) { | 183 protected void deleteSieve(double diameter) { |
177 for (int i = 0; i < SIEVE_DIAMETERS.length; ++i) { | 184 for (int i = sieves.size()-1; i >= 0; --i) { |
178 if (value >= SIEVE_DIAMETERS[i]) { | 185 if (sieves.get(i).matchesDiameter(diameter)) { |
179 return i+1; | 186 sieves.remove(i); |
187 break; | |
180 } | 188 } |
181 } | 189 } |
182 return SIEVE_DIAMETERS.length; | 190 } |
183 } | 191 |
184 | 192 protected void adjustOriginalSieves() { |
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 | 193 |
235 // If we already have an 8mm diameter sieve | 194 // If we already have an 8mm diameter sieve |
236 // we dont need to 'invent' it. | 195 // we dont need to 'invent' it. |
237 if (findSieveIndex(8d) > -1) { | 196 if (findSieve(8d) != null) { |
238 return; | 197 return; |
239 } | 198 } |
240 | 199 |
241 // create a new 8mm sieve. | 200 // create a new 8mm sieve. |
242 // delete 6.3mm sieve. | 201 // delete 6.3mm sieve. |
243 // modify 4mm sieve. | 202 // modify 4mm sieve. |
244 // | 203 |
245 int sixIdx = findSieveIndex(6.3d); | 204 Sieve six = findSieve(6.3d); |
246 int tenIdx = findSieveIndex(10d); | 205 Sieve ten = findSieve(10d); |
247 int fourIdx = findSieveIndex(4d); | 206 Sieve four = findSieve(4d); |
248 | 207 |
249 if (sixIdx < 0 || tenIdx < 0 || fourIdx < 0) { | 208 if (six == null || ten == null || four == null) { |
250 log.warn("missind diameter"); | 209 log.warn("missind diameter"); |
251 return; | 210 return; |
252 } | 211 } |
253 | 212 |
254 double sixValue = RSIEB(sixIdx); | 213 double sixValue = six.getLoad(); |
255 double tenValue = RSIEB(tenIdx); | 214 double tenValue = ten.getLoad(); |
256 double fourValue = RSIEB(fourIdx); | 215 double fourValue = four.getLoad(); |
257 | 216 |
258 deleteSieve(sixIdx); | 217 deleteSieve(6.3); |
259 | 218 |
260 double eightValue = ADD_8 - SCALE_8*sixValue + tenValue; | 219 double eightValue = ADD_8 - SCALE_8*sixValue + tenValue; |
261 double newFourValue = ADD_4 - SCALE_4*sixValue + fourValue; | 220 double newFourValue = ADD_4 - SCALE_4*sixValue + fourValue; |
262 | 221 |
263 putSieve(22, 8d, eightValue); | 222 sieves.add(new Sieve(8d, eightValue)); |
264 putSieve(fourIdx, 4d, newFourValue); | 223 sieves.add(new Sieve(4d, newFourValue)); |
265 } | 224 } |
266 | 225 |
267 | 226 |
268 public void fillSieveCategories() { | 227 public SieveArray calculateSieveArray() { |
269 adjustOriginalSieves(); | 228 |
270 | 229 SieveArray sa = new SieveArray(); |
271 for (int i = 1; i <= 22; ++i) { | 230 |
272 Double rsieb = (Double)getData(rsiebString(i)); | 231 for (Sieve s: sieves) { |
273 Double sieb = (Double)getData(siebString(i)); | 232 sa.doSieving(s); |
274 if (rsieb == null || sieb == null) { | 233 } |
275 continue; | 234 |
276 } | 235 sa.calculateNormLoads(); |
277 | 236 |
278 int idx = sieve(sieb); | 237 return sa; |
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 } | 238 } |
299 } | 239 } |
300 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 240 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |