diff gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java @ 368:6491000407dd

Added column labels for csv export of timeseries, vertical and horizontal profiles. gnv-artifacts/trunk@444 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 17 Dec 2009 10:20:05 +0000
parents 2f7a28f211c7
children bed9735adf84
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Wed Dec 16 23:07:47 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Thu Dec 17 10:20:05 2009 +0000
@@ -102,15 +102,32 @@
     protected String parameterValuesName = "parameterid";
     protected String measuremenValueName = "measurementid";
     protected String dateValueName = "dateid";
-    
-    public static final String [] TIMESERIES_CSV_PROFILE_NAMES = {
+
+    public static final String [] TIMESERIES_CSV_PROFILE_COLUMNS = {
         "XORDINATE",
         "YORDINATE",
         "GROUP1",
         "GROUP2",
         "GROUP3"
     };
-    
+
+
+    public static final String [] TIMESERIES_TIMESERIES_CSV_COLUMN_LABEL = {
+        "Date/Time",
+        "Value",
+        "ParameterID",
+        "MeasurementID",
+        "TimeseriesID"
+    };
+
+    public static final String [] TIMESERIES_MESH_CSV_COLUMN_LABEL = {
+        "Date/Time",
+        "Value",
+        "ParameterID",
+        "FeatureID",
+        "MeshID"
+    };
+
     public static final String [] TIMESERIES_ODV_PROFILE_NAMES = {
           "CRUISE",
           "STATION",
@@ -138,18 +155,6 @@
     };
 
     /**
-     * Profile for exporting data to cvs
-     */
-    public static final Profile TIMESERIES_CSV_PROFILE =
-        new DefaultProfile(
-            null,
-            ',',
-            '"',
-            '"',
-            "CSV",
-            "ISO-8859-1");
-
-    /**
      * Profile for exporting data to odv
      * TODO Change TIMESERIES_PROFILE_NAMES, which belong to CSV exports
      */
@@ -414,24 +419,46 @@
     }
 
 
-    /**
-     * @param outputStream
-     * @param chartResult
-     * @throws UnsupportedEncodingException
-     * @throws IOException
-     * @throws StateException
-     */
-    protected void createCSV(OutputStream outputStream,
-                            Collection<Result> chartResult)
-                                                          throws UnsupportedEncodingException,
-                                                          IOException,
-                                                          StateException {
-        DefaultExport export = new DefaultExport(new DefaultDataCollector(
-            TIMESERIES_CSV_PROFILE_NAMES));
+    protected void createCSV(OutputStream out, Collection<Result> results)
+    throws UnsupportedEncodingException, IOException, StateException
+    {
+        Iterator iter = results.iterator();
+        Result   res  = iter.hasNext() ? (Result) iter.next() : null;
 
-        export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult);
+        if (res == null)
+            return;
+
+        Profile profile = null;
+        int     dataid  = res.getInteger("DATAID").intValue();
+
+        // on meshes
+        if (dataid == 2) {
+            profile =  new DefaultProfile(
+                TIMESERIES_MESH_CSV_COLUMN_LABEL,
+                ',',
+                '"',
+                '"',
+                "CSV",
+                "ISO-8859-1");
+        }
+
+        // on timeseries
+        else {
+            profile =  new DefaultProfile(
+                TIMESERIES_TIMESERIES_CSV_COLUMN_LABEL,
+                ',',
+                '"',
+                '"',
+                "CSV",
+                "ISO-8859-1");
+        }
+
+        DefaultExport export = new DefaultExport(
+            new DefaultDataCollector(TIMESERIES_CSV_PROFILE_COLUMNS));
+        export.create(profile, out, results);
     }
 
+
     /**
      * TODO Result is not used at the moment. Change result with correct data.
      */

http://dive4elements.wald.intevation.org