comparison artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java @ 9763:ce7c67445cbb 3.2.x

No more hacks for getting description in case of official lines In case the name contained one and only one number, that number had been returned as description because in that case, the name matched WQ.NUMBERS_PATTERN.
author Tom Gottfried <tom@intevation.de>
date Fri, 11 Nov 2022 18:12:26 +0100
parents d5d250ad3c78
children
comparison
equal deleted inserted replaced
9762:d5d250ad3c78 9763:ce7c67445cbb
336 Double first = Double.NaN; 336 Double first = Double.NaN;
337 Double last = Double.NaN; 337 Double last = Double.NaN;
338 338
339 for (WQKms[] tmp: data) { 339 for (WQKms[] tmp: data) {
340 for (WQKms wqkms: tmp) { 340 for (WQKms wqkms: tmp) {
341 wQKms2CSV(writer, wqkms, atGauge, isQ); 341 wQKms2CSV(writer, wqkms, atGauge, isQ, false);
342 double[] firstLast = wqkms.getFirstLastKM(); 342 double[] firstLast = wqkms.getFirstLastKM();
343 if (first.isNaN()) { 343 if (first.isNaN()) {
344 /* Initialize */ 344 /* Initialize */
345 first = firstLast[0]; 345 first = firstLast[0];
346 last = firstLast[1]; 346 last = firstLast[1];
359 } 359 }
360 } 360 }
361 } 361 }
362 /* Append the official fixing at the bottom */ 362 /* Append the official fixing at the bottom */
363 for (WQKms wqkms: officalFixings) { 363 for (WQKms wqkms: officalFixings) {
364 wQKms2CSV(writer, filterWQKms(wqkms, first, last), atGauge, isQ); 364 wQKms2CSV(
365 writer, filterWQKms(wqkms, first, last), atGauge, isQ, true);
365 } 366 }
366 } 367 }
367 368
368 369
369 /** Filter a wqkms object to a distance. 370 /** Filter a wqkms object to a distance.
615 RiverUtils.getLocationDescription(flys, wqkm[2]), 616 RiverUtils.getLocationDescription(flys, wqkm[2]),
616 gaugeName 617 gaugeName
617 }); 618 });
618 } 619 }
619 620
620 private String getDesc(WQKms wqkms, boolean isQ) 621 private String getDesc(WQKms wqkms, boolean isQ, boolean isOfficial) {
621 { 622 if (isOfficial) {
623 return wqkms.getName();
624 }
625
622 D4EArtifact flys = (D4EArtifact) master; 626 D4EArtifact flys = (D4EArtifact) master;
623 String colDesc = ""; 627 String colDesc = "";
624 628
625 Double value = wqkms.getRawValue(); 629 Double value = wqkms.getRawValue();
626 630
640 if (colDesc == null) { 644 if (colDesc == null) {
641 colDesc = Formatter.getWaterlevelW(context).format(value); 645 colDesc = Formatter.getWaterlevelW(context).format(value);
642 } 646 }
643 } 647 }
644 } 648 }
645 if (colDesc != null) {
646 /* Quick hack. Can be removed when database strings are
647 * adapted or left in here as it should never be harmful. */
648 colDesc = colDesc.replace("Amtl.Festlegung_", "Amtl. ");
649 }
650 649
651 return colDesc == null ? "" : colDesc; 650 return colDesc == null ? "" : colDesc;
652 } 651 }
653 652
654 /** 653 /**
656 */ 655 */
657 protected void wQKms2CSV( 656 protected void wQKms2CSV(
658 CSVWriter writer, 657 CSVWriter writer,
659 WQKms wqkms, 658 WQKms wqkms,
660 boolean atGauge, 659 boolean atGauge,
661 boolean isQ 660 boolean isQ,
661 boolean isOfficial
662 ) { 662 ) {
663 log.debug("WaterlevelExporter.wQKms2CSV"); 663 log.debug("WaterlevelExporter.wQKms2CSV");
664 664
665 // Skip constant data. 665 // Skip constant data.
666 if (wqkms instanceof ConstantWQKms) { 666 if (wqkms instanceof ConstantWQKms) {
692 692
693 double a = gauge.getRange().getA().doubleValue(); 693 double a = gauge.getRange().getA().doubleValue();
694 double b = gauge.getRange().getB().doubleValue(); 694 double b = gauge.getRange().getB().doubleValue();
695 long startTime = System.currentTimeMillis(); 695 long startTime = System.currentTimeMillis();
696 696
697 desc = getDesc(wqkms, isQ); 697 desc = getDesc(wqkms, isQ, isOfficial);
698 698
699 if (flys instanceof FixationArtifact) { 699 if (flys instanceof FixationArtifact) {
700 // Get W/Q input per gauge for this case. 700 // Get W/Q input per gauge for this case.
701 FixRealizingAccess fixAccess = new FixRealizingAccess(flys); 701 FixRealizingAccess fixAccess = new FixRealizingAccess(flys);
702 segments = fixAccess.getSegments(); 702 segments = fixAccess.getSegments();
819 // 819 //
820 // There was some confusion how to implement this. see flys/issue1620 820 // There was some confusion how to implement this. see flys/issue1620
821 // for details. 821 // for details.
822 for (WQKms wqkms: officalFixings) { 822 for (WQKms wqkms: officalFixings) {
823 // To add some spaces here or to add them in the writer,.. 823 // To add some spaces here or to add them in the writer,..
824 writer.addColumn(getDesc(wqkms, true)); 824 writer.addColumn(getDesc(wqkms, true, true));
825 825
826 // Get all lines from the calculation 826 // Get all lines from the calculation
827 Map <Double, WstLine> calcLines = writer.getLines(); 827 Map <Double, WstLine> calcLines = writer.getLines();
828 828
829 // All KM values where we have a point for 829 // All KM values where we have a point for
902 Double last = Double.NaN; 902 Double last = Double.NaN;
903 903
904 addMetaData(source); 904 addMetaData(source);
905 for (WQKms[] tmp: data) { 905 for (WQKms[] tmp: data) {
906 for (WQKms wqkms: tmp) { 906 for (WQKms wqkms: tmp) {
907 addWKmsData(wqkms, atGauge, isQ, source); 907 addWKmsData(source, wqkms, atGauge, isQ, false);
908 double[] firstLast = wqkms.getFirstLastKM(); 908 double[] firstLast = wqkms.getFirstLastKM();
909 if (first.isNaN()) { 909 if (first.isNaN()) {
910 /* Initialize */ 910 /* Initialize */
911 first = firstLast[0]; 911 first = firstLast[0];
912 last = firstLast[1]; 912 last = firstLast[1];
926 } 926 }
927 } 927 }
928 928
929 /* Append the official fixing at the bottom */ 929 /* Append the official fixing at the bottom */
930 for (WQKms wqkms: officalFixings) { 930 for (WQKms wqkms: officalFixings) {
931 addWKmsData(filterWQKms(wqkms, first, last), atGauge, isQ, source); 931 addWKmsData(
932 source, filterWQKms(wqkms, first, last), atGauge, isQ, true);
932 } 933 }
933 return source; 934 return source;
934 } 935 }
935 936
936 protected void addMetaData(WKmsJRDataSource source) { 937 protected void addMetaData(WKmsJRDataSource source) {
958 PDF_HEADER_MODE, 959 PDF_HEADER_MODE,
959 "Waterlevel")); 960 "Waterlevel"));
960 } 961 }
961 962
962 protected void addWKmsData( 963 protected void addWKmsData(
964 WKmsJRDataSource source,
963 WQKms wqkms, 965 WQKms wqkms,
964 boolean atGauge, 966 boolean atGauge,
965 boolean isQ, 967 boolean isQ,
966 WKmsJRDataSource source) 968 boolean isOfficial
967 { 969 ) {
968 log.debug("WaterlevelExporter.addWKmsData"); 970 log.debug("WaterlevelExporter.addWKmsData");
969 971
970 // Skip constant data. 972 // Skip constant data.
971 if (wqkms instanceof ConstantWQKms) { 973 if (wqkms instanceof ConstantWQKms) {
972 return; 974 return;
992 DEFAULT_CSV_NOT_IN_GAUGE_RANGE); 994 DEFAULT_CSV_NOT_IN_GAUGE_RANGE);
993 995
994 double a = gauge.getRange().getA().doubleValue(); 996 double a = gauge.getRange().getA().doubleValue();
995 double b = gauge.getRange().getB().doubleValue(); 997 double b = gauge.getRange().getB().doubleValue();
996 998
997 desc = getDesc(wqkms, isQ); 999 desc = getDesc(wqkms, isQ, isOfficial);
998 long startTime = System.currentTimeMillis(); 1000 long startTime = System.currentTimeMillis();
999 1001
1000 for (int i = 0; i < size; i ++) { 1002 for (int i = 0; i < size; i ++) {
1001 result = wqkms.get(i, result); 1003 result = wqkms.get(i, result);
1002 1004

http://dive4elements.wald.intevation.org