Mercurial > dive4elements > river
changeset 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 (2013-02-27) |
parents | 4898376c680b |
children | 842026a5a12c |
files | flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java |
diffstat | 1 files changed, 60 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Wed Feb 27 11:50:32 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java Wed Feb 27 11:56:11 2013 +0100 @@ -449,6 +449,50 @@ } + /** Linearly search for gauge which is valid at km. */ + private Gauge findGauge(double km, List<Gauge> gauges) { + for (Gauge gauge: gauges) { + if (km >= gauge.getRange().getA().doubleValue() + && km <= gauge.getRange().getB().doubleValue()) { + return gauge; + } + } + return null; + } + + + private void writeRow4(CSVWriter writer, double wqkm[], FLYSArtifact flys) { + NumberFormat kmf = getKmFormatter(); + NumberFormat wf = getWFormatter(); + NumberFormat qf = getQFormatter(); + + writer.writeNext(new String[] { + kmf.format(wqkm[2]), + wf.format(wqkm[0]), + qf.format(wqkm[1]), + FLYSUtils.getLocationDescription(flys, wqkm[2]) + }); + } + + + /** Write an csv-row at gauge location. */ + private void writeRow6(CSVWriter writer, double wqkm[], String wOrQDesc, + FLYSArtifact flys, String gaugeName) { + NumberFormat kmf = getKmFormatter(); + NumberFormat wf = getWFormatter(); + NumberFormat qf = getQFormatter(); + + writer.writeNext(new String[] { + kmf.format(wqkm[2]), + wf.format(wqkm[0]), + qf.format(wqkm[1]), + wOrQDesc, + FLYSUtils.getLocationDescription(flys, wqkm[2]), + gaugeName + }); + } + + /** * Write "rows" of csv data from wqkms with writer. */ @@ -473,6 +517,7 @@ double[] result = new double[3]; FLYSArtifact flys = (FLYSArtifact) master; + List<Gauge> gauges = FLYSUtils.getGauges(flys); Gauge gauge = FLYSUtils.getGauge(flys); String gaugeName = gauge.getName(); String desc = ""; @@ -496,6 +541,7 @@ String colDesc = desc; List<Segment> segments = null; + boolean isFixRealize = false; if (flys instanceof WINFOArtifact) { if (wqkms != null && wqkms.getRawValue() != null) { WINFOArtifact winfo = (WINFOArtifact) flys; @@ -506,6 +552,9 @@ // Get W/Q input per gauge for this case. FixRealizingAccess fixAccess = new FixRealizingAccess(flys, getCallContext()); segments = fixAccess.getSegments(); + if (segments != null && segments.size() > 0) { + isFixRealize = true; + } } for (int i = 0; i < size; i ++) { @@ -521,25 +570,21 @@ } if (atGauge) { - writer.writeNext(new String[] { - kmf.format(result[2]), - wf.format(result[0]), - qf.format(result[1]), - colDesc, - FLYSUtils.getLocationDescription(flys, result[2]), + String gaugeN; + // TODO issue1131, name gauge + if (isFixRealize) { + gaugeN = findGauge(result[2], gauges).getName(); + } + else { // TODO issue1114: Take correct gauge - result[2] >= a && result[2] <= b + gaugeN = result[2] >= a && result[2] <= b ? gaugeName - : notinrange - }); + : notinrange; + } + writeRow6(writer, result, colDesc, flys, gaugeN); } else { - writer.writeNext(new String[] { - kmf.format(result[2]), - wf.format(result[0]), - qf.format(result[1]), - FLYSUtils.getLocationDescription(flys, result[2]) - }); + writeRow4(writer, result, flys); } }