changeset 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 8124e5de18b6
children 77cd3a2bc381
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java
diffstat 4 files changed, 233 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Wed Dec 16 23:07:47 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Thu Dec 17 10:20:05 2009 +0000
@@ -1,3 +1,10 @@
+009-12-17  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java,
+	  src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java,
+	  src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java:
+	  Added column labels for csv export.
+
 2009-12-17  Hans Plum <hans@intevation.de>
 
 	Issue 129: Release 0.2: Verbesserung der Übersetzungen
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java	Wed Dec 16 23:07:47 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java	Thu Dec 17 10:20:05 2009 +0000
@@ -23,6 +23,10 @@
 import de.intevation.gnv.chart.Chart;
 import de.intevation.gnv.chart.ChartLabels;
 import de.intevation.gnv.chart.HorizontalProfileChart;
+import de.intevation.gnv.exports.DefaultExport;
+import de.intevation.gnv.exports.ShapeDataCollector;
+import de.intevation.gnv.exports.DefaultProfile;
+import de.intevation.gnv.exports.Export.Profile;
 import de.intevation.gnv.geobackend.base.Result;
 import de.intevation.gnv.state.describedata.KeyValueDescibeData;
 import de.intevation.gnv.state.exception.StateException;
@@ -30,17 +34,37 @@
 import de.intevation.gnv.statistics.HorizontalProfileStatistics;
 import de.intevation.gnv.statistics.Statistics;
 
-import de.intevation.gnv.exports.DefaultExport;
-import de.intevation.gnv.exports.ShapeDataCollector;
-import de.intevation.gnv.exports.DefaultProfile;
-import de.intevation.gnv.exports.Export.Profile;
-
 /**
  * @author Tim Englich <tim.englich@intevation.de>
  * 
  */
-public class HorizontalProfileOutputState extends
-                                              TimeSeriesOutputState {
+public class HorizontalProfileOutputState
+extends      TimeSeriesOutputState
+{    
+    public static final String [] HORIZONTAL_PROFILE_COLUMNS = {
+        "SHAPE",
+        "YORDINATE",
+        "GROUP1"
+        // "GROUP2",
+    };
+
+
+    public static final String [] HORIZONTAL_MESH_CSV_COLUMN_LABEL = {
+        "Longitude",
+        "Latitude",
+        "Value",
+        "ParameterID",
+        //"MeshID"
+    };
+
+
+    public static final String [] HORIZONTAL_MEASUREMENT_CSV_COLUMN_LABEL = {
+        "Longitude",
+        "Latitude",
+        "Value",
+        "ParameterID",
+        //"SurveyID"
+    };
     /**
      * The UID of this class
      */
@@ -145,18 +169,46 @@
         return new HorizontalProfileStatistics();
     }
 
+
     @Override
-    protected void createCSV(OutputStream outputStream,
-                             Collection<Result> chartResult)
-                                                            throws UnsupportedEncodingException,
-                                                            IOException,
-                                                            StateException {
-       
-        log.debug("createCSV for HorizontalProfileOutputState.");
+    protected void createCSV(OutputStream out, Collection<Result> results)
+    throws UnsupportedEncodingException, IOException, StateException
+    {
+        log.debug("Create csv export for horizontal profiles.");
+        Iterator iter = results.iterator();
+        Result   res  = iter.hasNext() ? (Result) iter.next() : null;
+
+        if (res == null)
+            return;
+
+        Profile profile = null;
+        int     dataid  = res.getInteger("DATAID").intValue();
+
+        // on meshes
+        if (dataid == 2) {
+            profile =  new DefaultProfile(
+                HORIZONTAL_MESH_CSV_COLUMN_LABEL,
+                ',',
+                '"',
+                '"',
+                "CSV",
+                "ISO-8859-1");
+        }
+
+        // on measurements
+        else {
+            profile =  new DefaultProfile(
+                HORIZONTAL_MEASUREMENT_CSV_COLUMN_LABEL,
+                ',',
+                '"',
+                '"',
+                "CSV",
+                "ISO-8859-1");
+        }
+
         DefaultExport export = new DefaultExport(
-            new ShapeDataCollector(TIMESERIES_CSV_PROFILE_NAMES));
-
-        export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult);
+            new ShapeDataCollector(HORIZONTAL_PROFILE_COLUMNS));
+        export.create(profile, out, results);
     }
 
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java	Wed Dec 16 23:07:47 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java	Thu Dec 17 10:20:05 2009 +0000
@@ -3,7 +3,11 @@
  */
 package de.intevation.gnv.state.profile.vertical;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.Locale;
 
 import org.apache.log4j.Logger;
@@ -13,6 +17,12 @@
 import de.intevation.gnv.chart.Chart;
 import de.intevation.gnv.chart.ChartLabels;
 import de.intevation.gnv.chart.VerticalProfileChart;
+import de.intevation.gnv.exports.DefaultExport;
+import de.intevation.gnv.exports.DefaultDataCollector;
+import de.intevation.gnv.exports.DefaultProfile;
+import de.intevation.gnv.exports.Export.Profile;
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.state.exception.StateException;
 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState;
 import de.intevation.gnv.statistics.Statistics;
 import de.intevation.gnv.statistics.VerticalProfileStatistics;
@@ -22,6 +32,43 @@
  * 
  */
 public class VerticalProfileOutputState extends TimeSeriesOutputState {
+
+    public static final String [] VERTICAL_PROFILE_COLUMNS = {
+        "XORDINATE", // not quite sure if this is depth
+        "YORDINATE",
+        "GROUP1"
+        // "GROUP2",
+        // "GROUP3"
+    };
+
+
+    public static final String [] VERTICAL_MESH_CSV_COLUMN_LABEL = {
+        "CentralDepth",
+        "Value",
+        "ParameterID"
+        // TODO "FeatureID",
+        // TODO "MeshID"
+    };
+
+
+    public static final String [] VERTICAL_TIMESERIES_CSV_COLUMN_LABEL = {
+        "Depth",
+        "Value",
+        "ParameterID"
+        // TODO FeatureID missing
+        // TODO TimeseriesID missing
+    };
+
+
+    public static final String [] VERTICAL_MEASUREMENT_CSV_COLUMN_LABEL = {
+        "Depth",
+        "Value",
+        "ParameterID"
+        // TODO FeatureID missing
+        // TODO SeriesID missing
+    };
+
+
     /**
      * The UID of this class
      */
@@ -38,7 +85,7 @@
         super.domainLable = "chart.verticalprofile.title.xaxis";
     }
 
-    
+
     @Override
     protected Chart getChart(
         ChartLabels chartLables,
@@ -86,6 +133,58 @@
     }
 
 
+    @Override
+    protected void createCSV(OutputStream out, Collection<Result> results)
+    throws UnsupportedEncodingException, IOException, StateException
+    {
+        Iterator iter = results.iterator();
+        Result   res  = iter.hasNext() ? (Result) iter.next() : null;
+
+        if (res == null)
+            return;
+
+        Profile profile = null;
+        int     dataid  = res.getInteger("DATAID").intValue();
+
+        // on meshes
+        if (dataid == 2) {
+            profile =  new DefaultProfile(
+                VERTICAL_MESH_CSV_COLUMN_LABEL,
+                ',',
+                '"',
+                '"',
+                "CSV",
+                "ISO-8859-1");
+        }
+
+        // on timeseries
+        else if (dataid == 1) {
+            profile =  new DefaultProfile(
+                VERTICAL_TIMESERIES_CSV_COLUMN_LABEL,
+                ',',
+                '"',
+                '"',
+                "CSV",
+                "ISO-8859-1");
+        }
+
+        // on measurements
+        else {
+            profile =  new DefaultProfile(
+                VERTICAL_MEASUREMENT_CSV_COLUMN_LABEL,
+                ',',
+                '"',
+                '"',
+                "CSV",
+                "ISO-8859-1");
+        }
+
+        DefaultExport export = new DefaultExport(
+            new DefaultDataCollector(VERTICAL_PROFILE_COLUMNS));
+        export.create(profile, out, results);
+    }
+
+
     protected String createChartSubtitle(Locale locale, String uuid) {
         return getSelectedFeatureName(uuid);
     }
--- 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