comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java @ 4837:9e25c7523485

Fixed calculation of effective width in MINFO SQ relation. * Get all (including empty datasets) from db. * Filter empty datasets when processing data of the same date. * Added debug outputs.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 23 Jan 2013 11:14:41 +0100
parents bf2fd9c58ac4
children ac9a3d9576b4
comparison
equal deleted inserted replaced
4814:47c529e2be26 4837:9e25c7523485
100 "COALESCE(gs.RSIEB11, 0) + COALESCE(gs.RSIEB12, 0) +" + 100 "COALESCE(gs.RSIEB11, 0) + COALESCE(gs.RSIEB12, 0) +" +
101 "COALESCE(gs.RSIEB13, 0) + COALESCE(gs.RSIEB14, 0) +" + 101 "COALESCE(gs.RSIEB13, 0) + COALESCE(gs.RSIEB14, 0) +" +
102 "COALESCE(gs.RSIEB15, 0) + COALESCE(gs.RSIEB16, 0) +" + 102 "COALESCE(gs.RSIEB15, 0) + COALESCE(gs.RSIEB16, 0) +" +
103 "COALESCE(gs.RSIEB17, 0) + COALESCE(gs.RSIEB18, 0) +" + 103 "COALESCE(gs.RSIEB17, 0) + COALESCE(gs.RSIEB18, 0) +" +
104 "COALESCE(gs.RSIEB19, 0) + COALESCE(gs.RSIEB20, 0) +" + 104 "COALESCE(gs.RSIEB19, 0) + COALESCE(gs.RSIEB20, 0) +" +
105 "COALESCE(gs.RSIEB21, 0) + COALESCE(gs.REST, 0)) > 0 " + 105 "COALESCE(gs.RSIEB21, 0) + COALESCE(gs.REST, 0)) >= 0 " +
106 "ORDER BY " + 106 "ORDER BY " +
107 "m.DATUM, g.UFERABST, g.GLOTRECHTEID, gp.LFDNR"; 107 "m.DATUM, g.UFERABST, g.GLOTRECHTEID, gp.LFDNR";
108 108
109 public static final BasicTransformerAdapter TOTALS_TRANSFORMER = 109 public static final BasicTransformerAdapter TOTALS_TRANSFORMER =
110 new BasicTransformerAdapter() { 110 new BasicTransformerAdapter() {
307 Integer lastLR = null; 307 Integer lastLR = null;
308 308
309 List<Measurement> accumulated = new ArrayList<Measurement>(); 309 List<Measurement> accumulated = new ArrayList<Measurement>();
310 310
311 for (Measurement m: measuments) { 311 for (Measurement m: measuments) {
312
313 Integer currentLR = (Integer)m.getData("GLOTRECHTEID"); 312 Integer currentLR = (Integer)m.getData("GLOTRECHTEID");
314 313
315 boolean newDS = lastLR == null 314 boolean newDS = lastLR == null
316 || (currentLR != null && !lastLR.equals(currentLR)); 315 || (currentLR != null && !lastLR.equals(currentLR));
317 316
371 } 370 }
372 371
373 372
374 protected static Measurement processSameDate(List<Measurement> measurements) { 373 protected static Measurement processSameDate(List<Measurement> measurements) {
375 int N = measurements.size(); 374 int N = measurements.size();
375 if (N > 0) {
376 log.debug("process same date for Q: " + measurements.get(0).Q());
377 }
376 if (N == 1) { 378 if (N == 1) {
377 Measurement current = measurements.get(0); 379 Measurement current = measurements.get(0);
378 double left = current.get("UFERABLINKS"); 380 double left = current.get("UFERABLINKS");
379 double right = current.get("UFERABST"); 381 double right = current.get("UFERABST");
380 current.set("EFFWIDTH", left + right); 382 current.set("EFFWIDTH", left + right);
400 Measurement next = measurements.get(i+1); 402 Measurement next = measurements.get(i+1);
401 double distPrev = prev.get("UFERABST"); 403 double distPrev = prev.get("UFERABST");
402 double distNext = next.get("UFERABST"); 404 double distNext = next.get("UFERABST");
403 current.set("EFFWIDTH", 0.5*(distNext - distPrev)); 405 current.set("EFFWIDTH", 0.5*(distNext - distPrev));
404 } 406 }
407 log.debug("effective width: " + current.get("EFFWIDTH"));
405 } 408 }
406 } 409 }
407 410
408 double sumSandF = 0d; 411 double sumSandF = 0d;
409 double sumCoarseF = 0d; 412 double sumCoarseF = 0d;
410 double sumGravelF = 0d; 413 double sumGravelF = 0d;
411 double sumNorm = 0d; 414 double sumNorm = 0d;
412 415
413 for (Measurement m: measurements) { 416 for (Measurement m: measurements) {
414 SieveArray sa = m.getSieveArray(); 417 SieveArray sa = m.getSieveArray();
418 if (sa.totalLoad() < SieveArray.EPSILON) {
419 continue;
420 }
415 double sandF = sa.sandNormFraction(); 421 double sandF = sa.sandNormFraction();
416 double coarseF = sa.coarseNormFraction(); 422 double coarseF = sa.coarseNormFraction();
417 double gravelF = sa.gravelNormFraction(); 423 double gravelF = sa.gravelNormFraction();
418 double effWidth = m.get("EFFWIDTH"); 424 double effWidth = m.get("EFFWIDTH");
419 double gt = m.get("GTRIEB"); 425 double gt = m.get("GTRIEB");
420 double scale = effWidth*gt; 426 double scale = effWidth*gt;
421 sumSandF += scale*sandF; 427 sumSandF += scale*sandF;
422 sumCoarseF += scale*coarseF; 428 sumCoarseF += scale*coarseF;
423 sumGravelF += scale*gravelF; 429 sumGravelF += scale*gravelF;
424 sumNorm += scale; 430 sumNorm += scale;
431 log.debug("fractions - s: " +
432 sandF + " c: " +
433 coarseF + " g: " +
434 gravelF);
435 log.debug("scale: " + scale + " = " + effWidth + " * " + gt);
425 } 436 }
426 437
427 Map<String, Object> data = 438 Map<String, Object> data =
428 new HashMap<String, Object>(measurements.get(0).getData()); 439 new HashMap<String, Object>(measurements.get(0).getData());
429 440
432 sumNorm = 1d/sumNorm; 443 sumNorm = 1d/sumNorm;
433 444
434 m.set("BL_S", sumNorm*sumSandF); 445 m.set("BL_S", sumNorm*sumSandF);
435 m.set("BL_G", sumNorm*sumGravelF); 446 m.set("BL_G", sumNorm*sumGravelF);
436 m.set("BL_C", sumNorm*sumCoarseF); 447 m.set("BL_C", sumNorm*sumCoarseF);
437 448 log.debug("BL_S: " + m.get("BL_S") + " BL_G: " + m.get("BL_G") + " BL_C: " + m.get("BL_C"));
438 return m; 449 return m;
439 } 450 }
440 451
441 452
442 private static final boolean equalDate(Date a, Date b) { 453 private static final boolean equalDate(Date a, Date b) {
481 } 492 }
482 Map<String, Object> data = 493 Map<String, Object> data =
483 new HashMap<String, Object>(measuments.get(0).getData()); 494 new HashMap<String, Object>(measuments.get(0).getData());
484 495
485 data.put("GTRIEB", sumGTrieb/N); 496 data.put("GTRIEB", sumGTrieb/N);
497
486 return new Measurement(data, accumulatedSieves); 498 return new Measurement(data, accumulatedSieves);
487 } 499 }
488 } 500 }
489 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 501 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org