changeset 6941:d322da01d862

(issue1451) Round Q's in the way it is done for AT's and localize KM
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 29 Aug 2013 11:28:55 +0200
parents 274948f91dd6
children b77a1e804c0a
files artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java
diffstat 2 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java	Thu Aug 29 11:33:30 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java	Thu Aug 29 11:28:55 2013 +0200
@@ -150,7 +150,7 @@
 
         super.init(request, out, context);
 
-        this.data = new ArrayList<WQKms[]>();
+        data = new ArrayList<WQKms[]>();
     }
 
 
@@ -594,12 +594,11 @@
         writer.writeNext(new String[] {
             kmf.format(wqkm[2]),
             wf.format(wqkm[0]),
-            qf.format(wqkm[1]),
+            qf.format(RiverUtils.roundQ(wqkm[1])),
             RiverUtils.getLocationDescription(flys, wqkm[2])
         });
     }
 
-
     /** Write an csv-row at gauge location. */
     private void writeRow6(CSVWriter writer, double wqkm[], String wOrQDesc,
         D4EArtifact flys, String gaugeName) {
@@ -610,7 +609,7 @@
         writer.writeNext(new String[] {
             kmf.format(wqkm[2]),
             wf.format(wqkm[0]),
-            qf.format(wqkm[1]),
+            qf.format(RiverUtils.roundQ(wqkm[1])),
             wOrQDesc,
             RiverUtils.getLocationDescription(flys, wqkm[2]),
             gaugeName
@@ -913,12 +912,14 @@
 
         Locale locale = Resources.getLocale(meta);
         DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
+        NumberFormat kmf = getKmFormatter();
 
         source.addMetaData("date", df.format(new Date()));
 
         RangeAccess rangeAccess = new RangeAccess(flys);
         double[] kms = rangeAccess.getKmRange();
-        source.addMetaData("range", kms[0] + " - " + kms[kms.length-1]);
+        source.addMetaData("range",
+                kmf.format(kms[0]) + " - " + kmf.format(kms[kms.length-1]));
 
         source.addMetaData("gauge", RiverUtils.getGaugename(flys));
 
@@ -969,7 +970,7 @@
                 source.addData(new String[] {
                     kmf.format(result[2]),
                     wf.format(result[0]),
-                    qf.format(result[1]),
+                    qf.format(RiverUtils.roundQ(result[1])),
                     desc,
                     RiverUtils.getLocationDescription(flys, result[2]),
                     result[2] >= a && result[2] <= b
@@ -981,7 +982,7 @@
                 source.addData(new String[] {
                     kmf.format(result[2]),
                     wf.format(result[0]),
-                    qf.format(result[1]),
+                    qf.format(RiverUtils.roundQ(result[1])),
                     desc,
                     RiverUtils.getLocationDescription(flys, result[2]),
                     result[2] >= a && result[2] <= b
--- a/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Thu Aug 29 11:33:30 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Thu Aug 29 11:28:55 2013 +0200
@@ -929,5 +929,14 @@
 
         return river.determineGauges(dist[0], dist[1]);
     }
+
+    /** Round a Q in the AT format style **/
+    public static double roundQ(double q) {
+        if (q < 10d) q = Math.rint((q*1000d)) / 1000d;
+        else if (q < 100d) q = Math.rint((q*100d)) / 100d;
+        else if (q < 1000d) q = Math.rint((q*10d)) / 10d;
+        else if (q >= 1000d) q = Math.rint(q);
+        return q;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org