[Dive4elements-commits] [PATCH 2 of 2] WaterlevelExporter: Unpolished fix for flys/issue1131: gaugename in csv

Wald Commits scm-commit at wald.intevation.org
Wed Feb 27 11:49:22 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1361962571 -3600
# Node ID ae25e23a1546cc40a0b3856eff0b2ceb8f484d82
# Parent  4898376c680b91d947c575f8b7ac9f124bec2028
WaterlevelExporter: Unpolished fix for flys/issue1131: gaugename in csv.

diff -r 4898376c680b -r ae25e23a1546 flys-artifacts/src/main/java/de/intevation/flys/exports/WaterlevelExporter.java
--- 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);
             }
         }
 


More information about the Dive4elements-commits mailing list