comparison flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java @ 5112:ae25e23a1546

WaterlevelExporter: Unpolished fix for flys/issue1131: gaugename in csv.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 27 Feb 2013 11:56:11 +0100
parents a929d9a9fa1e
children 42bae65c116b
comparison
equal deleted inserted replaced
5111:4898376c680b 5112:ae25e23a1546
447 }); 447 });
448 } 448 }
449 } 449 }
450 450
451 451
452 /** Linearly search for gauge which is valid at km. */
453 private Gauge findGauge(double km, List<Gauge> gauges) {
454 for (Gauge gauge: gauges) {
455 if (km >= gauge.getRange().getA().doubleValue()
456 && km <= gauge.getRange().getB().doubleValue()) {
457 return gauge;
458 }
459 }
460 return null;
461 }
462
463
464 private void writeRow4(CSVWriter writer, double wqkm[], FLYSArtifact flys) {
465 NumberFormat kmf = getKmFormatter();
466 NumberFormat wf = getWFormatter();
467 NumberFormat qf = getQFormatter();
468
469 writer.writeNext(new String[] {
470 kmf.format(wqkm[2]),
471 wf.format(wqkm[0]),
472 qf.format(wqkm[1]),
473 FLYSUtils.getLocationDescription(flys, wqkm[2])
474 });
475 }
476
477
478 /** Write an csv-row at gauge location. */
479 private void writeRow6(CSVWriter writer, double wqkm[], String wOrQDesc,
480 FLYSArtifact flys, String gaugeName) {
481 NumberFormat kmf = getKmFormatter();
482 NumberFormat wf = getWFormatter();
483 NumberFormat qf = getQFormatter();
484
485 writer.writeNext(new String[] {
486 kmf.format(wqkm[2]),
487 wf.format(wqkm[0]),
488 qf.format(wqkm[1]),
489 wOrQDesc,
490 FLYSUtils.getLocationDescription(flys, wqkm[2]),
491 gaugeName
492 });
493 }
494
495
452 /** 496 /**
453 * Write "rows" of csv data from wqkms with writer. 497 * Write "rows" of csv data from wqkms with writer.
454 */ 498 */
455 protected void wQKms2CSV( 499 protected void wQKms2CSV(
456 CSVWriter writer, 500 CSVWriter writer,
471 515
472 int size = wqkms.size(); 516 int size = wqkms.size();
473 double[] result = new double[3]; 517 double[] result = new double[3];
474 518
475 FLYSArtifact flys = (FLYSArtifact) master; 519 FLYSArtifact flys = (FLYSArtifact) master;
520 List<Gauge> gauges = FLYSUtils.getGauges(flys);
476 Gauge gauge = FLYSUtils.getGauge(flys); 521 Gauge gauge = FLYSUtils.getGauge(flys);
477 String gaugeName = gauge.getName(); 522 String gaugeName = gauge.getName();
478 String desc = ""; 523 String desc = "";
479 String notinrange = msg( 524 String notinrange = msg(
480 CSV_NOT_IN_GAUGE_RANGE, 525 CSV_NOT_IN_GAUGE_RANGE,
494 539
495 long startTime = System.currentTimeMillis(); 540 long startTime = System.currentTimeMillis();
496 541
497 String colDesc = desc; 542 String colDesc = desc;
498 List<Segment> segments = null; 543 List<Segment> segments = null;
544 boolean isFixRealize = false;
499 if (flys instanceof WINFOArtifact) { 545 if (flys instanceof WINFOArtifact) {
500 if (wqkms != null && wqkms.getRawValue() != null) { 546 if (wqkms != null && wqkms.getRawValue() != null) {
501 WINFOArtifact winfo = (WINFOArtifact) flys; 547 WINFOArtifact winfo = (WINFOArtifact) flys;
502 colDesc = FLYSUtils.getNamedMainValue(winfo, wqkms.getRawValue()); 548 colDesc = FLYSUtils.getNamedMainValue(winfo, wqkms.getRawValue());
503 } 549 }
504 } 550 }
505 else if (flys instanceof FixationArtifact) { 551 else if (flys instanceof FixationArtifact) {
506 // Get W/Q input per gauge for this case. 552 // Get W/Q input per gauge for this case.
507 FixRealizingAccess fixAccess = new FixRealizingAccess(flys, getCallContext()); 553 FixRealizingAccess fixAccess = new FixRealizingAccess(flys, getCallContext());
508 segments = fixAccess.getSegments(); 554 segments = fixAccess.getSegments();
555 if (segments != null && segments.size() > 0) {
556 isFixRealize = true;
557 }
509 } 558 }
510 559
511 for (int i = 0; i < size; i ++) { 560 for (int i = 0; i < size; i ++) {
512 result = wqkms.get(i, result); 561 result = wqkms.get(i, result);
513 562
519 } 568 }
520 } 569 }
521 } 570 }
522 571
523 if (atGauge) { 572 if (atGauge) {
524 writer.writeNext(new String[] { 573 String gaugeN;
525 kmf.format(result[2]), 574 // TODO issue1131, name gauge
526 wf.format(result[0]), 575 if (isFixRealize) {
527 qf.format(result[1]), 576 gaugeN = findGauge(result[2], gauges).getName();
528 colDesc, 577 }
529 FLYSUtils.getLocationDescription(flys, result[2]), 578 else {
530 // TODO issue1114: Take correct gauge 579 // TODO issue1114: Take correct gauge
531 result[2] >= a && result[2] <= b 580 gaugeN = result[2] >= a && result[2] <= b
532 ? gaugeName 581 ? gaugeName
533 : notinrange 582 : notinrange;
534 }); 583 }
584 writeRow6(writer, result, colDesc, flys, gaugeN);
535 } 585 }
536 else { 586 else {
537 writer.writeNext(new String[] { 587 writeRow4(writer, result, flys);
538 kmf.format(result[2]),
539 wf.format(result[0]),
540 qf.format(result[1]),
541 FLYSUtils.getLocationDescription(flys, result[2])
542 });
543 } 588 }
544 } 589 }
545 590
546 long stopTime = System.currentTimeMillis(); 591 long stopTime = System.currentTimeMillis();
547 592

http://dive4elements.wald.intevation.org