Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java @ 6606:b4fcc9308d00
Factor out description getting code from csv export and reuse for pdf
Fixes issue1388
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Thu, 18 Jul 2013 15:50:59 +0200 |
parents | ddef735db96a |
children | 85ff19b94ec5 |
comparison
equal
deleted
inserted
replaced
6605:ddef735db96a | 6606:b4fcc9308d00 |
---|---|
616 RiverUtils.getLocationDescription(flys, wqkm[2]), | 616 RiverUtils.getLocationDescription(flys, wqkm[2]), |
617 gaugeName | 617 gaugeName |
618 }); | 618 }); |
619 } | 619 } |
620 | 620 |
621 private String getDesc(WQKms wqkms, boolean isQ) | |
622 { | |
623 D4EArtifact flys = (D4EArtifact) master; | |
624 String colDesc = ""; | |
625 | |
626 if (flys instanceof WINFOArtifact && isQ) { | |
627 colDesc = getCSVRowTitle((WINFOArtifact)flys, wqkms); | |
628 } | |
629 else if (!isQ) { | |
630 Double value = RiverUtils.getValueFromWQ(wqkms); | |
631 colDesc = (value != null) ? | |
632 Formatter.getWaterlevelW(context).format(value) : null; | |
633 } | |
634 | |
635 if (flys instanceof WINFOArtifact) { | |
636 if (wqkms != null && wqkms.getRawValue() != null) { | |
637 WINFOArtifact winfo = (WINFOArtifact) flys; | |
638 colDesc = RiverUtils.getNamedMainValue(winfo, wqkms.getRawValue()); | |
639 // For 'W am Pegel' s | |
640 if (colDesc == null) { | |
641 colDesc = ((D4EArtifact)master).getDataAsString("wq_single"); | |
642 } | |
643 } | |
644 } | |
645 return colDesc == null ? "" : colDesc; | |
646 } | |
621 | 647 |
622 /** | 648 /** |
623 * Write "rows" of csv data from wqkms with writer. | 649 * Write "rows" of csv data from wqkms with writer. |
624 */ | 650 */ |
625 protected void wQKms2CSV( | 651 protected void wQKms2CSV( |
648 String gaugeName = gauge.getName(); | 674 String gaugeName = gauge.getName(); |
649 String desc = ""; | 675 String desc = ""; |
650 String notinrange = msg( | 676 String notinrange = msg( |
651 CSV_NOT_IN_GAUGE_RANGE, | 677 CSV_NOT_IN_GAUGE_RANGE, |
652 DEFAULT_CSV_NOT_IN_GAUGE_RANGE); | 678 DEFAULT_CSV_NOT_IN_GAUGE_RANGE); |
679 List<Segment> segments = null; | |
680 boolean isFixRealize = false; | |
653 | 681 |
654 double a = gauge.getRange().getA().doubleValue(); | 682 double a = gauge.getRange().getA().doubleValue(); |
655 double b = gauge.getRange().getB().doubleValue(); | 683 double b = gauge.getRange().getB().doubleValue(); |
656 | |
657 if (flys instanceof WINFOArtifact && isQ) { | |
658 desc = getCSVRowTitle((WINFOArtifact)flys, wqkms); | |
659 } | |
660 else if (!isQ) { | |
661 Double value = RiverUtils.getValueFromWQ(wqkms); | |
662 desc = value != null | |
663 ? Formatter.getWaterlevelW(context).format(value) : null; | |
664 } | |
665 | |
666 long startTime = System.currentTimeMillis(); | 684 long startTime = System.currentTimeMillis(); |
667 | 685 |
668 String colDesc = desc; | 686 desc = getDesc(wqkms, isQ); |
669 List<Segment> segments = null; | 687 |
670 boolean isFixRealize = false; | 688 if (flys instanceof FixationArtifact) { |
671 if (flys instanceof WINFOArtifact) { | |
672 if (wqkms != null && wqkms.getRawValue() != null) { | |
673 WINFOArtifact winfo = (WINFOArtifact) flys; | |
674 colDesc = RiverUtils.getNamedMainValue(winfo, wqkms.getRawValue()); | |
675 // For 'W am Pegel' s | |
676 if (colDesc == null) { | |
677 colDesc = ((D4EArtifact)master).getDataAsString("wq_single"); | |
678 } | |
679 } | |
680 } | |
681 else if (flys instanceof FixationArtifact) { | |
682 // Get W/Q input per gauge for this case. | 689 // Get W/Q input per gauge for this case. |
683 FixRealizingAccess fixAccess = new FixRealizingAccess(flys); | 690 FixRealizingAccess fixAccess = new FixRealizingAccess(flys); |
684 segments = fixAccess.getSegments(); | 691 segments = fixAccess.getSegments(); |
685 if (segments != null && !segments.isEmpty()) { | 692 if (segments != null && !segments.isEmpty()) { |
686 isFixRealize = true; | 693 isFixRealize = true; |
706 && lastSegment.inside(km) | 713 && lastSegment.inside(km) |
707 ? lastSegment | 714 ? lastSegment |
708 : findSegment(km, segments); | 715 : findSegment(km, segments); |
709 | 716 |
710 if (found != null) { | 717 if (found != null) { |
711 colDesc = nf.format(found.getValues()[0]); | 718 desc = nf.format(found.getValues()[0]); |
712 } | 719 } |
713 lastSegment = found; | 720 lastSegment = found; |
714 } | 721 } |
715 | 722 |
716 String gaugeN; | 723 String gaugeN; |
727 // TODO issue1114: Take correct gauge | 734 // TODO issue1114: Take correct gauge |
728 gaugeN = km >= a && km <= b | 735 gaugeN = km >= a && km <= b |
729 ? gaugeName | 736 ? gaugeName |
730 : notinrange; | 737 : notinrange; |
731 } | 738 } |
732 writeRow6(writer, result, colDesc, flys, gaugeN); | 739 writeRow6(writer, result, desc, flys, gaugeN); |
733 } | 740 } |
734 } | 741 } |
735 else { // Not at gauge. | 742 else { // Not at gauge. |
736 for (int i = 0; i < size; ++i) { | 743 for (int i = 0; i < size; ++i) { |
737 result = wqkms.get(i, result); | 744 result = wqkms.get(i, result); |
917 DEFAULT_CSV_NOT_IN_GAUGE_RANGE); | 924 DEFAULT_CSV_NOT_IN_GAUGE_RANGE); |
918 | 925 |
919 double a = gauge.getRange().getA().doubleValue(); | 926 double a = gauge.getRange().getA().doubleValue(); |
920 double b = gauge.getRange().getB().doubleValue(); | 927 double b = gauge.getRange().getB().doubleValue(); |
921 | 928 |
922 if (flys instanceof WINFOArtifact && isQ) { | 929 desc = getDesc(wqkms, isQ); |
923 desc = getCSVRowTitle((WINFOArtifact)flys, wqkms); | |
924 } | |
925 else if (!isQ) { | |
926 Double value = RiverUtils.getValueFromWQ(wqkms); | |
927 desc = value != null | |
928 ? Formatter.getWaterlevelW(context).format(value) : null; | |
929 } | |
930 | |
931 long startTime = System.currentTimeMillis(); | 930 long startTime = System.currentTimeMillis(); |
932 | 931 |
933 for (int i = 0; i < size; i ++) { | 932 for (int i = 0; i < size; i ++) { |
934 result = wqkms.get(i, result); | 933 result = wqkms.get(i, result); |
935 | 934 |