diff artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java @ 8179:705f8b92fd66

Complete CSV-export and correct headers.
author Tom Gottfried <tom@intevation.de>
date Wed, 03 Sep 2014 16:46:09 +0200
parents ce35bdf3d750
children e4606eae8ea5
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java	Wed Sep 03 10:24:39 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java	Wed Sep 03 16:46:09 2014 +0200
@@ -44,34 +44,38 @@
 
     // i18n keys.
     public static final String CSV_KM =
-        "export.sedimentload_ls.csv.header.km";
+        "export.csv.header.km";
 
     public static final String CSV_YEAR =
-        "export.sedimentload_ls.csv.header.year";
+        "export.csv.header.year";
 
     public static final String CSV_COARSE =
-        "export.sedimentload_ls.csv.header.coarse";
+        "export.sedimentload.csv.header.coarse";
 
     public static final String CSV_FINEMIDDLE =
-        "export.sedimentload_ls.csv.header.finemiddle";
+        "export.sedimentload.csv.header.fine_middle";
 
     public static final String CSV_SAND =
-        "export.sedimentload_ls.csv.header.sand";
+        "export.sedimentload.csv.header.sand";
 
     public static final String CSV_SUSP_SAND =
-        "export.sedimentload_ls.csv.header.suspsand";
+        "export.sedimentload.csv.header.susp_sand";
 
     public static final String CSV_SUSP_SAND_BB =
-        "export.sedimentload_ls.csv.header.suspsandbb";
+        "export.sedimentload.csv.header.susp_sand_bed";
 
     public static final String CSV_SUSP_SEDIMENT =
-        "export.sedimentload_ls.csv.header.suspsediment";
+        "export.sedimentload.csv.header.suspended_sediment";
+
+    public static final String CSV_BED_LOAD =
+        "export.sedimentload.csv.header.bed_load";
+
+    public static final String CSV_BED_LOAD_SUSP_SAND =
+        "export.sedimentload.csv.header.bed_load_susp_sand";
 
     public static final String CSV_TOTAL =
-        "export.sedimentload_ls.csv.header.total";
+        "export.sedimentload.csv.header.total";
 
-    /* Header is: suspended_sediment, susp_sand, susp_sand_bed, sand,
-     * fine_middle, coarse, total */
     private static final String[] FRACTION_ORDER = {
         "suspended_sediment",
         "susp_sand",
@@ -79,6 +83,8 @@
         "sand",
         "fine_middle",
         "coarse",
+        "bed_load",
+        "bed_load_susp_sand",
         "total"
     };
 
@@ -153,14 +159,6 @@
         return valf.format(val);
     }
 
-    /** Return space when val is NaN or zero, apply NumberFormat otherwise. */
-    private String nonZeroToString(NumberFormat valf, double val) {
-        if (Double.isNaN(val) || val == 0d) {
-            return " ";
-        }
-        return valf.format(val);
-    }
-
     /** Write a line. */
     private void writeRecord(
         CSVWriter writer,
@@ -168,20 +166,17 @@
         String years,
         Double[] fractions
     ) {
-        // year, total, susp sed, susp sandbed suspsand, sand, finemiddle, coarse
         NumberFormat kmf = Formatter.getCalculationKm(context.getMeta());
         NumberFormat valf = Formatter.getFormatter(context.getMeta(), 0, 2);
-        writer.writeNext(new String[] {
-            kmf.format(km),
-            years,
-            numberToString(valf,  fractions[0]),
-            numberToString(valf,  fractions[1]),
-            numberToString(valf,  fractions[2]),
-            numberToString(valf,  fractions[3]),
-            numberToString(valf,  fractions[4]),
-            numberToString(valf,  fractions[5]),
-            nonZeroToString(valf, fractions[6])
-        });
+
+        String[] record = new String[fractions.length+2];
+        record[0] = kmf.format(km);
+        record[1] = years;
+        for (int i = 0; i < fractions.length; ++i) {
+            record[i+2] = numberToString(valf,  fractions[i]);
+        }
+
+        writer.writeNext(record);
     }
 
     /** Writes i18ned header for csv file/stream. */
@@ -192,18 +187,23 @@
         SedimentLoadAccess access =
             new SedimentLoadAccess((D4EArtifact) master);
 
-        String unit = " [" + msg("state.minfo." +
-                access.getUnit(), "translation missing") + "]";
+        String unit = msg("state.minfo." + access.getUnit());
 
-        header.add(msg(CSV_KM,          "km"));
-        header.add(msg(CSV_YEAR,        "Jahr"));
-        header.add(msg(CSV_SUSP_SEDIMENT, "Schwebst.") + unit);
-        header.add(msg(CSV_SUSP_SAND,   "Susp.Sand") + unit);
-        header.add(msg(CSV_SUSP_SAND_BB, "Susp.Sand(BB)") + unit);
-        header.add(msg(CSV_SAND,        "Sand") + unit);
-        header.add(msg(CSV_FINEMIDDLE,  "Kies(f+m)") + unit);
-        header.add(msg(CSV_COARSE,      "Kies(g)") + unit);
-        header.add(msg(CSV_TOTAL,       "Gesamt") + unit);
+        header.add(msg(CSV_KM));
+        header.add(msg(CSV_YEAR));
+        for (String head: new String[] {
+                CSV_SUSP_SEDIMENT,
+                CSV_SUSP_SAND,
+                CSV_SUSP_SAND_BB,
+                CSV_SAND,
+                CSV_FINEMIDDLE,
+                CSV_COARSE,
+                CSV_BED_LOAD,
+                CSV_BED_LOAD_SUSP_SAND,
+                CSV_TOTAL
+            }) {
+            header.add(msg(head, new Object[] { unit }));
+        }
         writer.writeNext(header.toArray(new String[header.size()]));
     }
 

http://dive4elements.wald.intevation.org