[Dive4elements-commits] [PATCH] Add special case handling for Fixing AT export at a gauge

Wald Commits scm-commit at wald.intevation.org
Thu Jun 13 11:43:05 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1371116582 -7200
# Node ID ee701de9c875b8abc25968b692f7453cf7b22d0a
# Parent  3cf9e82b9c7577a55c86fca8a6cd4ea33ea31f5a
Add special case handling for Fixing AT export at a gauge

diff -r 3cf9e82b9c75 -r ee701de9c875 artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATExport.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATExport.java	Thu Jun 13 10:01:01 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATExport.java	Thu Jun 13 11:43:02 2013 +0200
@@ -16,6 +16,8 @@
 
 import org.dive4elements.river.artifacts.access.FixAccess;
 
+import org.dive4elements.river.utils.RiverUtils;
+
 import org.dive4elements.river.artifacts.math.fitting.Function;
 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory;
 
@@ -26,6 +28,8 @@
 
 import org.dive4elements.river.exports.AbstractExporter;
 
+import org.dive4elements.river.model.River;
+
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
@@ -80,12 +84,11 @@
 
         Writer writer = new OutputStreamWriter(out, DEFAULT_CSV_CHARSET);
 
-        FixAccess access = new FixAccess((D4EArtifact)this.master);
         FixATWriter atWriter = new FixATWriter(this.function, this.parameters);
         NodeList nodes = request.getElementsByTagName("km");
         String km = nodes.item(0).getTextContent();
         double dkm = Double.parseDouble(km);
-        String river = access.getRiver();
+        River river = RiverUtils.getRiver((D4EArtifact)master);
         atWriter.write(writer, context.getMeta(), river, dkm);
         writer.close();
     }
diff -r 3cf9e82b9c75 -r ee701de9c875 artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATWriter.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATWriter.java	Thu Jun 13 10:01:01 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixATWriter.java	Thu Jun 13 11:43:02 2013 +0200
@@ -18,6 +18,9 @@
 
 import org.dive4elements.river.exports.ATWriter;
 
+import org.dive4elements.river.model.Gauge;
+import org.dive4elements.river.model.River;
+
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.Writer;
@@ -35,9 +38,15 @@
     public static final String I18N_HEADER_KEY =
         "fix.export.at.header";
 
+    public static final String I18N_GAUGE_HEADER_KEY =
+        "fix.export.at.gauge.header";
+
     public static final String I18N_HEADER_DEFAULT =
         "Exported fixings discharge curve for {0} {0}-km: {1}";
 
+    public static final String I18N_GAUGE_HEADER_DEFAULT =
+        "Exported fixings discharge curve for {0}, gauge: {1} datum[{3}] = {2}";
+
     public static final String [] Q_MAX_COLUMN = new String [] { "max_q" };
 
     private static final int    MAX_ITERATIONS = 10000;
@@ -58,12 +67,21 @@
     public void write(
         Writer   writer,
         CallMeta meta,
-        String   river,
+        River    river,
         double   km
     )
     throws IOException {
         PrintWriter out = new PrintWriter(writer);
-        printHeader(out, meta, river, km);
+
+        int subtractPNP = 0;
+        // Special case handling for at's at gauges
+        Gauge gauge = river.determineGaugeByPosition(km);
+        if (Math.abs(km - gauge.getStation().doubleValue()) < 1e-4) {
+            printGaugeHeader(out, meta, river, gauge);
+            subtractPNP = (int)Math.round(gauge.getDatum().doubleValue() * 100);
+        } else {
+            printHeader(out, meta, river.getName(), km);
+        }
 
         double [] coeffs = parameters.interpolate(
             "km", km, function.getParameterNames());
@@ -116,7 +134,7 @@
             log.debug("wcm: " + wcm);
         }
 
-        out.printf(Locale.US, "%8d", wRow);
+        out.printf(Locale.US, "%8d", wRow - subtractPNP);
 
         for (int i = 0; i < wcm; i++) {
             out.print(ATWriter.EMPTY);
@@ -140,7 +158,7 @@
             if (w > wMax) {
                 break;
             }
-            out.printf(Locale.US, "%8d", wRow += 10);
+            out.printf(Locale.US, "%8d", (wRow += 10) - subtractPNP);
             wcm = 0;
         }
 
@@ -160,6 +178,20 @@
             river, km));
     }
 
+    protected void printGaugeHeader(
+        PrintWriter out,
+        CallMeta    meta,
+        River       river,
+        Gauge       gauge
+    ) {
+        out.println("*" + Resources.format(
+            meta,
+            I18N_GAUGE_HEADER_KEY,
+            I18N_GAUGE_HEADER_DEFAULT,
+            new Object[] { river.getName(), gauge.getName(),
+                gauge.getDatum(), river.getWstUnit().getName() }));
+    }
+
     private static double minW(
         org.dive4elements.river.artifacts.math.Function function,
         double maxW,
diff -r 3cf9e82b9c75 -r ee701de9c875 artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties	Thu Jun 13 10:01:01 2013 +0200
+++ b/artifacts/src/main/resources/messages.properties	Thu Jun 13 11:43:02 2013 +0200
@@ -606,6 +606,7 @@
 fix.km.chart.interpolated=interpolated
 
 fix.export.at.header = Exported fixings discharge curve for {0} {0}-km: {1}
+fix.export.at.gauge.header = Exported fixings discharge curve for {0}, gauge: {1} datum[{3}] = {2}
 sq.km.chart.label = Measuring Points
 sq.km.chart.title = Measuring Points
 sq.km.chart.km.axis = km
diff -r 3cf9e82b9c75 -r ee701de9c875 artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties	Thu Jun 13 10:01:01 2013 +0200
+++ b/artifacts/src/main/resources/messages_de.properties	Thu Jun 13 11:43:02 2013 +0200
@@ -608,7 +608,8 @@
 fix.km.chart.measured=gemessen
 fix.km.chart.interpolated=interpoliert
 
-fix.export.at.header =  Abflusskurve aus der Fixierungsanalyse f\u00fcr {0} {0}-km: {1}
+fix.export.at.header = Abflusskurve aus der Fixierungsanalyse f\u00fcr {0} {0}-km: {1}
+fix.export.at.gauge.header = Abflusstafel aus der Fixierungsanalyse f\u00fcr {0}, Pegel: {1} PNP[{3}] = {2}
 sq.km.chart.label = Feststoffdaten
 sq.km.chart.title = Feststoffdatenbestand SedDB
 sq.km.chart.km.axis = km
diff -r 3cf9e82b9c75 -r ee701de9c875 artifacts/src/main/resources/messages_de_DE.properties
--- a/artifacts/src/main/resources/messages_de_DE.properties	Thu Jun 13 10:01:01 2013 +0200
+++ b/artifacts/src/main/resources/messages_de_DE.properties	Thu Jun 13 11:43:02 2013 +0200
@@ -606,7 +606,8 @@
 fix.km.chart.measured=gemessen
 fix.km.chart.interpolated=interpoliert
 
-fix.export.at.header =  Abflusskurve aus der Fixierungsanalyse f\u00fcr {0} {0}-km: {1}
+fix.export.at.header = Abflusstafel aus der Fixierungsanalyse f\u00fcr {0} {0}-km: {1}
+fix.export.at.gauge.header = Abflusstafel aus der Fixierungsanalyse f\u00fcr {0}, Pegel: {1} PNP[{3}] = {2}
 sq.km.chart.label = Feststoffdaten
 sq.km.chart.title = Feststoffdatenbestand SedDB
 sq.km.chart.km.axis = km
diff -r 3cf9e82b9c75 -r ee701de9c875 artifacts/src/main/resources/messages_en.properties
--- a/artifacts/src/main/resources/messages_en.properties	Thu Jun 13 10:01:01 2013 +0200
+++ b/artifacts/src/main/resources/messages_en.properties	Thu Jun 13 11:43:02 2013 +0200
@@ -340,9 +340,9 @@
 export.discharge.longitudinal.section.csv.header.w = W [NN + m]
 export.discharge.longitudinal.section.csv.header.cw = W corr. [NN + m]
 export.discharge.longitudinal.section.csv.header.q = Q [m\u00b3/s]
-export.discharge.curve.at.header = Computed Discharge Curve for {0} {0}-km: {1}
-export.discharge.curve.at.gauge.header = Dischargetable for {1}/{0} since {2} Datum[{4}] = {3}
-export.discharge.curve.at.gauge.calc.header = Computed Discharge Curve for {0}, Gauge: {1} Datum[{3}] = {2}
+export.discharge.curve.at.header = Computed discharge curve for {0} {0}-km: {1}
+export.discharge.curve.at.gauge.header = Dischargetable for {1}/{0} since {2} datum[{4}] = {3}
+export.discharge.curve.at.gauge.calc.header = Computed discharge curve for {0}, gauge: {1} datum[{3}] = {2}
 export.historical.discharge.csv.header.timerange = Timerange
 export.historical.discharge.csv.header.waterlevel = Waterlevel [cm]
 export.historical.discharge.csv.header.discharge = Discharge [m\u00b3/s]
@@ -607,6 +607,7 @@
 fix.km.chart.interpolated=interpolated
 
 fix.export.at.header = Exported fixings discharge curve for {0} {0}-km: {1}
+fix.export.at.gauge.header = Exported fixings discharge curve for {0}, gauge: {1} datum[{3}] = {2}
 sq.km.chart.label = Measuring Points
 sq.km.chart.title = Measuring Points
 sq.km.chart.km.axis = km


More information about the Dive4elements-commits mailing list