Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java @ 4001:ab3a4ad82ae1
S(Q) accumulated same diameter meassurements per bank distance.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 01 Oct 2012 14:03:13 +0200 |
parents | a9c93b7c9da1 |
children | 3b79e8afca7e |
comparison
equal
deleted
inserted
replaced
4000:92719f122c77 | 4001:ab3a4ad82ae1 |
---|---|
1 package de.intevation.flys.artifacts.model.sq; | 1 package de.intevation.flys.artifacts.model.sq; |
2 | 2 |
3 import java.util.ArrayList; | 3 import java.util.ArrayList; |
4 import java.util.List; | 4 import java.util.List; |
5 import java.util.TreeMap; | |
5 | 6 |
6 import de.intevation.flys.artifacts.model.DateRange; | 7 import de.intevation.flys.artifacts.model.DateRange; |
7 | 8 |
8 import de.intevation.flys.backend.SedDBSessionHolder; | 9 import de.intevation.flys.backend.SedDBSessionHolder; |
9 | 10 |
100 "COALESCE(gs.RSIEB13, 0) + COALESCE(gs.RSIEB14, 0) +" + | 101 "COALESCE(gs.RSIEB13, 0) + COALESCE(gs.RSIEB14, 0) +" + |
101 "COALESCE(gs.RSIEB15, 0) + COALESCE(gs.RSIEB16, 0) +" + | 102 "COALESCE(gs.RSIEB15, 0) + COALESCE(gs.RSIEB16, 0) +" + |
102 "COALESCE(gs.RSIEB17, 0) + COALESCE(gs.RSIEB18, 0) +" + | 103 "COALESCE(gs.RSIEB17, 0) + COALESCE(gs.RSIEB18, 0) +" + |
103 "COALESCE(gs.RSIEB19, 0) + COALESCE(gs.RSIEB20, 0) +" + | 104 "COALESCE(gs.RSIEB19, 0) + COALESCE(gs.RSIEB20, 0) +" + |
104 "COALESCE(gs.RSIEB21, 0) + COALESCE(gs.REST, 0)) > 0 " + | 105 "COALESCE(gs.RSIEB21, 0) + COALESCE(gs.REST, 0)) > 0 " + |
105 "ORDER BY m.DATUM, gp.LFDNR, g.UFERABST"; | 106 "ORDER BY m.DATUM, g.UFERABST, g.GLOTRECHTEID, gp.LFDNR"; |
106 | 107 |
107 public static final class MeasurementResultTransformer | 108 public static final class MeasurementResultTransformer |
108 extends BasicTransformerAdapter | 109 extends BasicTransformerAdapter |
109 { | 110 { |
110 public static MeasurementResultTransformer INSTANCE = | 111 public static MeasurementResultTransformer INSTANCE = |
235 query.setResultTransformer(MeasurementResultTransformer.INSTANCE); | 236 query.setResultTransformer(MeasurementResultTransformer.INSTANCE); |
236 | 237 |
237 @SuppressWarnings("unchecked") | 238 @SuppressWarnings("unchecked") |
238 List<Measurement> measuments = (List<Measurement>)query.list(); | 239 List<Measurement> measuments = (List<Measurement>)query.list(); |
239 | 240 |
241 List<Measurement> same = new ArrayList<Measurement>(); | |
242 | |
240 Integer lastLR = null; | 243 Integer lastLR = null; |
241 | 244 |
242 for (int i = 0, N = measuments.size(); i < N; ++i) { | 245 List<Measurement> accumulated = new ArrayList<Measurement>(); |
243 Measurement m = measuments.get(i); | 246 |
247 for (Measurement m: measuments) { | |
244 | 248 |
245 Integer currentLR = (Integer)m.getData("GLOTRECHTEID"); | 249 Integer currentLR = (Integer)m.getData("GLOTRECHTEID"); |
246 | 250 |
247 boolean newDS = lastLR == null | 251 boolean newDS = lastLR == null |
248 || (currentLR != null && !lastLR.equals(currentLR)); | 252 || (currentLR != null && !lastLR.equals(currentLR)); |
249 | 253 |
250 Measurement p = i > 0 ? measuments.get(i-1) : null; | 254 if (newDS && !same.isEmpty()) { |
251 Measurement n = i < N-1 ? measuments.get(i+1) : null; | 255 accumulated.add(accumulate(same)); |
252 m.setPrev(newDS ? null : p); | 256 same.clear(); |
253 m.setNext(n); | |
254 | |
255 if (p != null && newDS) { | |
256 p.setNext(null); | |
257 } | 257 } |
258 | 258 |
259 lastLR = currentLR; | 259 lastLR = currentLR; |
260 } | 260 } |
261 | 261 |
262 return new Measurements(measuments); | 262 if (!same.isEmpty()) { |
263 accumulated.add(accumulate(same)); | |
264 } | |
265 | |
266 for (Measurement m: accumulated) { | |
267 m.adjustSieves(); | |
268 } | |
269 | |
270 return new Measurements(measuments, accumulated); | |
271 } | |
272 | |
273 protected static Measurement accumulate(List<Measurement> measuments) { | |
274 | |
275 int N = measuments.size(); | |
276 if (N == 1) { | |
277 return measuments.get(0); | |
278 } | |
279 | |
280 TreeMap<Double, double []> diameters = | |
281 new TreeMap<Double, double []>(Sieve.DIAMETER_CMP); | |
282 | |
283 for (Measurement m: measuments) { | |
284 for (Sieve s: m.getSieves()) { | |
285 Double key = s.getDiameter(); | |
286 double [] sum = diameters.get(key); | |
287 if (sum == null) { | |
288 sum = new double[1]; | |
289 diameters.put(key, sum); | |
290 } | |
291 sum[0] += s.getLoad(); | |
292 } | |
293 } | |
294 List<Sieve> accumulatedSieves = new ArrayList<Sieve>(diameters.size()); | |
295 for (Map.Entry<Double, double []> entry: diameters.entrySet()) { | |
296 accumulatedSieves.add( | |
297 new Sieve(entry.getKey(), | |
298 entry.getValue()[0]/N)); | |
299 } | |
300 | |
301 Map<String, Object> data = | |
302 new HashMap<String, Object>(measuments.get(0).getData()); | |
303 | |
304 return new Measurement(data, accumulatedSieves); | |
263 } | 305 } |
264 | 306 |
265 public static Measurements getMeasurements( | 307 public static Measurements getMeasurements( |
266 String river, | 308 String river, |
267 double location, | 309 double location, |