comparison flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java @ 5587:7b1c5fe4ebf3

Simplified inner loop of water level exporter.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 07 Apr 2013 11:38:15 +0200
parents a137cbab32a8
children
comparison
equal deleted inserted replaced
5586:966237892c9b 5587:7b1c5fe4ebf3
451 } 451 }
452 } 452 }
453 453
454 454
455 /** Linearly search for gauge which is valid at km. */ 455 /** Linearly search for gauge which is valid at km. */
456 private Gauge findGauge(double km, List<Gauge> gauges) { 456 private static Gauge findGauge(double km, List<Gauge> gauges) {
457 for (Gauge gauge: gauges) { 457 for (Gauge gauge: gauges) {
458 if (km >= gauge.getRange().getA().doubleValue() 458 if (gauge.getRange().contains(km)) {
459 && km <= gauge.getRange().getB().doubleValue()) {
460 return gauge; 459 return gauge;
460 }
461 }
462 return null;
463 }
464
465 private static Segment findSegment(double km, List<Segment> segments) {
466 for (Segment segment: segments) {
467 if (segment.inside(km)) {
468 return segment;
461 } 469 }
462 } 470 }
463 return null; 471 return null;
464 } 472 }
465 473
553 } 561 }
554 else if (flys instanceof FixationArtifact) { 562 else if (flys instanceof FixationArtifact) {
555 // Get W/Q input per gauge for this case. 563 // Get W/Q input per gauge for this case.
556 FixRealizingAccess fixAccess = new FixRealizingAccess(flys, getCallContext()); 564 FixRealizingAccess fixAccess = new FixRealizingAccess(flys, getCallContext());
557 segments = fixAccess.getSegments(); 565 segments = fixAccess.getSegments();
558 if (segments != null && segments.size() > 0) { 566 if (segments != null && !segments.isEmpty()) {
559 isFixRealize = true; 567 isFixRealize = true;
560 } 568 }
561 } 569 }
562 570
563 for (int i = 0; i < size; i ++) { 571 if (atGauge) { // "At gauge" needs more output.
564 result = wqkms.get(i, result); 572
565 573 // Kms tend to be close together so caching the last sector
566 // Check if there has been W input per Gauge and use it. 574 // is a good time saving heuristic.
567 if (segments != null) { 575 Segment lastSegment = null;
568 for (Segment segment: segments) { 576 Gauge lastGauge = null;
569 if (segment.inside(result[2])) { 577
570 NumberFormat nf = 578 NumberFormat nf =
571 Formatter.getFormatter(context.getMeta() , 0, 0); 579 Formatter.getFormatter(context.getMeta(), 0, 0);
572 colDesc = nf.format(segment.getValues()[0]); 580
581 for (int i = 0; i < size; ++i) {
582 result = wqkms.get(i, result);
583 double km = result[2];
584
585 if (segments != null) {
586 Segment found = lastSegment != null
587 && lastSegment.inside(km)
588 ? lastSegment
589 : findSegment(km, segments);
590
591 if (found != null) {
592 colDesc = nf.format(found.getValues()[0]);
573 } 593 }
594 lastSegment = found;
574 } 595 }
575 } 596
576
577 if (atGauge) {
578 String gaugeN; 597 String gaugeN;
579 if (isFixRealize) { 598 if (isFixRealize) {
580 gaugeN = findGauge(result[2], gauges).getName(); 599 Gauge found = lastGauge != null
600 && lastGauge.getRange().contains(km)
601 ? lastGauge
602 : findGauge(km, gauges);
603
604 gaugeN = found != null ? found.getName() : notinrange;
605 lastGauge = found;
581 } 606 }
582 else { 607 else {
583 // TODO issue1114: Take correct gauge 608 // TODO issue1114: Take correct gauge
584 gaugeN = result[2] >= a && result[2] <= b 609 gaugeN = km >= a && km <= b
585 ? gaugeName 610 ? gaugeName
586 : notinrange; 611 : notinrange;
587 } 612 }
588 writeRow6(writer, result, colDesc, flys, gaugeN); 613 writeRow6(writer, result, colDesc, flys, gaugeN);
589 } 614 }
590 else { 615 }
616 else { // Not at gauge.
617 for (int i = 0; i < size; ++i) {
618 result = wqkms.get(i, result);
591 writeRow4(writer, result, flys); 619 writeRow4(writer, result, flys);
592 } 620 }
593 } 621 }
594 622
595 long stopTime = System.currentTimeMillis(); 623 long stopTime = System.currentTimeMillis();

http://dive4elements.wald.intevation.org