changeset 765:f28a7eac542a

Integrated valid ODV-Export to the GNV-Artifacts gnv-artifacts/trunk@821 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 23 Mar 2010 14:09:03 +0000
parents afc639e55261
children a23ce49423d5
files gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/queries.properties gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultExport.java gnv-artifacts/src/main/java/de/intevation/gnv/exports/ODVExport.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java
diffstat 5 files changed, 203 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Mon Mar 22 12:54:04 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Mar 23 14:09:03 2010 +0000
@@ -1,3 +1,27 @@
+2010-03-23  Tim Englich  <tim.englich@intevation.de>
+
+	* src/main/java/de/intevation/gnv/exports/ODVExport.java: 
+	  Added new Export-Class which will generate the special ODV-Format.
+	  This one is required because we have to switch the Format from a Rowbased
+	  Representation to a Columnbased.
+	  This meas that for each Parameter which was requested two additonal Columns,
+	  one for the Parametervalue and one for the Quality, has to be added to the 
+	  Export. This differs to the "normal" CSV-Export.
+	
+	* src/main/java/de/intevation/gnv/exports/DefaultExport.java (collector): 
+	  Switched Member from private to protected to make it available from 
+	  extending Classes.
+
+	* src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java: 
+	  Modified the Colums and the Column-headers and Columns-names for the ODV-Export
+	  that all required Data is put into the Document in the right order and the 
+	  right nameing.
+	  Switche to the NEW ODVExport-Class to use it for all ODV-Exports.
+
+	* doc/conf/queries.properties: 
+	  Modified the Queries for the ODV-Export that all required Informations are 
+	  fetched from the Database.
+
 2010-03-22  Tim Englich  <tim.englich@intevation.de>
 
 	* src/test/ressources/horizontalProfile_mesh/horizontalprofile_step_11_feed.xml,
--- a/gnv-artifacts/doc/conf/queries.properties	Mon Mar 22 12:54:04 2010 +0000
+++ b/gnv-artifacts/doc/conf/queries.properties	Tue Mar 23 14:09:03 2010 +0000
@@ -105,7 +105,8 @@
             TSV.DATAVALUE, \
             TS.PARAMETERID PARAMETER, \
             TSV.MEASUREMENTID, \
-            TSV.TIMESERIESID \
+            TSV.TIMESERIESID, \
+            '1' QF \
      FROM MEDIAN.TIMESERIESPOINT, \
           MEDIAN.TIMESERIESVALUE TSV, \
           MEDIAN.TIMESERIES TS, \
@@ -119,10 +120,11 @@
            TSV.MEASUREMENTID IN ( ? ) AND \
            TSV.TIMEVALUE >= ? AND \
            TSV.TIMEVALUE <= ? \
-     ORDER BY TSV.MEASUREMENTID, \
+     ORDER BY TS.PARAMETERID, \
+              TSV.MEASUREMENTID, \
               TSV.TIMESERIESID, \
-              TS.PARAMETERID, \
               TSV.TIMEVALUE
+              
 
 #############################################
 #############################################
@@ -211,7 +213,8 @@
         (((ML.UPPERZLOCATION + ML.LOWERZLOCATION) / 2)*-1) DEPTH, \
         msv.TIMEVALUE, \
         msv.DATAVALUE, \
-        msv.PARAMETERID PARAMETER \
+        msv.PARAMETERID PARAMETER, \
+        '1' QF \
     from MEDIAN.MESHSCALARVALUE msv, \
          MEDIAN.MESHPOINT, \
          MEDIAN.MESH m, \
@@ -230,8 +233,8 @@
           msv.TIMEVALUE <= ? \
     order by MEDIAN.MESHPOINT.FEATUREID, \
              msv.FEATUREID, \
-             msv.PARAMETERID, \
-             msv.TIMEVALUE
+             msv.TIMEVALUE, \
+             msv.PARAMETERID
 
 
 #############################################
@@ -332,7 +335,8 @@
             TSV.DATAVALUE, \
             TS.PARAMETERID PARAMETER, \
             TSV.MEASUREMENTID, \
-            TSV.TIMESERIESID \
+            TSV.TIMESERIESID, \
+            '1' QF \
      FROM MEDIAN.TIMESERIESPOINT, \
           MEDIAN.TIMESERIESVALUE TSV, \
           MEDIAN.TIMESERIES TS, \
@@ -349,8 +353,9 @@
            M.ZLOCATION <= ? \
      ORDER BY TSV.MEASUREMENTID, \
               TSV.TIMESERIESID, \
-              TS.PARAMETERID, \
-              TSV.TIMEVALUE
+              TSV.TIMEVALUE, \
+              TS.PARAMETERID
+              
              
 #############################################
 #############################################
@@ -504,7 +509,8 @@
         (((ML.UPPERZLOCATION + ML.LOWERZLOCATION) / 2)*-1) DEPTH, \
         msv.DATAVALUE, \
         msv.PARAMETERID PARAMETER, \
-        msv.TIMEVALUE \
+        msv.TIMEVALUE , \
+        '1' QF \
     from MEDIAN.MESHLAYER ml, \
          MEDIAN.MESHPOINT, \
          MEDIAN.MESH m, \
@@ -530,9 +536,9 @@
                                   JPOSITION = (select JPOSITION from MEDIAN.MESHPOINT where FEATUREID = ?)) AND \
           MEDIAN.MESHPOINT.KPOSITION <= ? AND \
           MEDIAN.MESHPOINT.KPOSITION >= ? \
-    order by msv.PARAMETERID, \
-             msv.TIMEVALUE, \
-             ml.UPPERZLOCATION
+    order by msv.TIMEVALUE, \
+             ml.UPPERZLOCATION, \
+             msv.PARAMETERID
             
 #############################################
 #############################################
@@ -637,7 +643,8 @@
         (M.ZLOCATION * -1) DEPTH, \
         MSV.DATAVALUE, \
         MSV.PARAMETERID PARAMETER, \
-        MEDIAN.INSTANTANEOUSPOINT.TIMEVALUE \
+        MEDIAN.INSTANTANEOUSPOINT.TIMEVALUE , \
+        '1' QF \
     FROM MEDIAN.SERIES S, \
          MEDIAN.INSTANTANEOUSPOINT, \
          MEDIAN.MEASUREMENT M, \
@@ -650,8 +657,8 @@
           M.ZLOCATION >= ? AND \
           M.ZLOCATION <= ? \
     ORDER BY MEDIAN.INSTANTANEOUSPOINT.TIMEVALUE, \
-          MSV.PARAMETERID, \
-          M.ZLOCATION
+          M.ZLOCATION, \
+          MSV.PARAMETERID
           
 #############################################
 #############################################
@@ -884,7 +891,8 @@
         ST_ASTEXT(SHAPE), \
         MEDIAN.INSTANTANEOUSPOINT.TIMEVALUE, \
         MSV.DATAVALUE, \
-        MSV.PARAMETERID PARAMETER \
+        MSV.PARAMETERID PARAMETER , \
+        '1' QF \
     FROM MEDIAN.INSTANTANEOUSPOINT, \
          MEDIAN.VEHICLE V, \
          MEDIAN.CRUISE C, \
@@ -973,7 +981,8 @@
           msv.PARAMETERID PARAMETER, \
           msv.TIMEVALUE, \
           MEDIAN.MESHPOINT.JPOSITION, \
-          MEDIAN.MESHPOINT.IPOSITION \
+          MEDIAN.MESHPOINT.IPOSITION , \
+          '1' QF \
     from MEDIAN.MESHLAYER ml, \
          MEDIAN.MESHPOINT, \
          MEDIAN.MESH m, \
@@ -999,9 +1008,9 @@
                     ? = (select ? from MEDIAN.MESHPOINT where FEATUREID = ?)) \
    order by msv.TIMEVALUE, \
             MEDIAN.MESHPOINT.KPOSITION, \
-            msv.PARAMETERID, \
             MEDIAN.MESHPOINT.JPOSITION, \
-            MEDIAN.MESHPOINT.IPOSITION
+            MEDIAN.MESHPOINT.IPOSITION, \
+            msv.PARAMETERID
             
 #############################################
 #############################################
@@ -1136,7 +1145,8 @@
            MEDIAN.MESHPOINT.JPOSITION, \
            MEDIAN.MESHPOINT.IPOSITION, \
            MEDIAN.MESHPOINT.KPOSITION, \
-           2 DATAID \
+           2 DATAID , \
+           '1' QF \
     from MEDIAN.MESHLAYER ml, \
          MEDIAN.MESHPOINT, \
          MEDIAN.MESH m, \
@@ -1160,10 +1170,10 @@
                     mp.MESHID = m.MESHID  AND \
                     ? = (select ? from MEDIAN.MESHPOINT where FEATUREID = ?)) \
     order by msv.TIMEVALUE, \
-             msv.PARAMETERID, \
              MEDIAN.MESHPOINT.JPOSITION, \
              MEDIAN.MESHPOINT.IPOSITION, \
-             MEDIAN.MESHPOINT.KPOSITION
+             MEDIAN.MESHPOINT.KPOSITION, \
+             msv.PARAMETERID
              
 #############################################
 #############################################
@@ -1256,7 +1266,8 @@
           M.OBJECTID = ? AND \
           MEDIAN.MESHPOINT.KPOSITION = ? \
     order by MEDIAN.MESHPOINT.JPOSITION, \
-             MEDIAN.MESHPOINT.IPOSITION
+             MEDIAN.MESHPOINT.IPOSITION, \
+             MSV.PARAMETERID
              
 area_filter = SELECT DISTINCT \
        FEATUREID KEY ,\
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultExport.java	Mon Mar 22 12:54:04 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultExport.java	Tue Mar 23 14:09:03 2010 +0000
@@ -1,19 +1,16 @@
 package de.intevation.gnv.exports;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+import java.util.Iterator;
+
 import org.apache.log4j.Logger;
 
 import au.com.bytecode.opencsv.CSVWriter;
-
-import java.util.Iterator;
-import java.util.Collection;
-
-import java.io.UnsupportedEncodingException;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.OutputStream;
-
 import de.intevation.gnv.geobackend.base.Result;
-
 import de.intevation.gnv.state.exception.StateException;
 
 /**
@@ -25,7 +22,7 @@
 {
     private static Logger log = Logger.getLogger(DefaultExport.class);
 
-    private Export.DataCollector collector;
+    protected Export.DataCollector collector;
 
     public DefaultExport(Export.DataCollector collector) {
         this.collector = collector;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ODVExport.java	Tue Mar 23 14:09:03 2010 +0000
@@ -0,0 +1,121 @@
+/**
+ *
+ */
+package de.intevation.gnv.exports;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import au.com.bytecode.opencsv.CSVWriter;
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.state.describedata.KeyValueDescibeData;
+import de.intevation.gnv.state.exception.StateException;
+
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class ODVExport extends DefaultExport {
+
+    private static Logger log = Logger.getLogger(ODVExport.class);
+    
+    private Collection parameters = null;
+    
+    /**
+     * Constructor
+     * @param collector
+     */
+    public ODVExport(DataCollector collector, Collection parameters) {
+        super(collector);
+        this.parameters = parameters;
+    }
+
+    @Override
+    protected void writeData(Profile profile, Collection result,
+                             CSVWriter writer) throws StateException {
+        Iterator<Result> it = result.iterator();
+
+        String[] header = profile.getHeader();
+        ArrayList<String> headerList = new ArrayList<String>();
+        for (int i= 0; i < header.length; i++){
+            headerList.add(header[i]);
+        }
+        ArrayList<String> paramids = new ArrayList<String>();
+        
+        Map<String[], Map<String,String>> aggregatedRows = new HashMap<String[],  Map<String,String>>();
+        
+        String currentParameterID = "N/N";
+        
+        while (it.hasNext()) {
+            Result res = it.next();
+
+            String[] key = collector.getData(res);
+            String parameterValue = res.getString("DATAVALUE");
+            String parameterID = res.getString("PARAMETER");
+            
+            if (!currentParameterID.equals(parameterID)){
+                paramids.add(parameterID);
+                headerList.add(this.findParamTitle(parameters, parameterID));
+                headerList.add("QF");
+                currentParameterID = parameterID;
+            }
+            
+            Map<String,String> aggregatedRow = aggregatedRows.get(key);
+            if (aggregatedRow!= null){
+                aggregatedRow.put(parameterID, parameterValue);
+            }else{
+                Map<String,String> params = new HashMap<String, String>();
+                params.put(parameterID, parameterValue);
+                aggregatedRows.put(key, params);
+            }
+        }
+        
+        if (header != null){
+            writer.writeNext(headerList.toArray(header));
+        }
+
+        Iterator<String[]> rows = aggregatedRows.keySet().iterator();
+        while (rows.hasNext()){
+            String[] row = rows.next();
+            Map<String,String> params = aggregatedRows.get(row);
+            ArrayList<String> rowList = new ArrayList<String>();
+            for (int i= 0; i < row.length; i++){
+                rowList.add(row[i]);
+            }
+            for (int i = 0; i < paramids.size();i++){
+                String key = paramids.get(i);
+                String value = params.get(key);
+                if (value == null){
+                    value = "";
+                }
+                rowList.add(value);
+                rowList.add("1");
+            }
+            writer.writeNext(rowList.toArray(row));
+        }
+    }
+    
+    protected String findParamTitle(Collection values, String id) {
+        log.debug("find description of dataset");
+
+        if (values != null){
+            Iterator it = values.iterator();
+            while (it.hasNext()) {
+                KeyValueDescibeData data = (KeyValueDescibeData) it.next();
+
+                if (id.equals(data.getKey()))
+                    return data.getValue();
+            }
+        }
+        return "";
+    }
+    
+
+}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Mon Mar 22 12:54:04 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Tue Mar 23 14:09:03 2010 +0000
@@ -37,6 +37,8 @@
 import de.intevation.gnv.exports.DefaultDataCollector;
 import de.intevation.gnv.exports.DefaultExport;
 import de.intevation.gnv.exports.DefaultProfile;
+import de.intevation.gnv.exports.Export;
+import de.intevation.gnv.exports.ODVExport;
 import de.intevation.gnv.exports.SimpleOdvDataCollector;
 import de.intevation.gnv.exports.Export.Profile;
 import de.intevation.gnv.geobackend.base.Result;
@@ -122,12 +124,11 @@
           "CRUISE",
           "STATION",
           "TYPE",
+          "TIMEVALUE",
           "SHAPE",
           "BOTDEPTH",
           "DEPTH",
-          "TIMEVALUE",
-          "DATAVALUE",
-          "PARAMETER"
+          "QF"
     };
 
 
@@ -135,13 +136,12 @@
         "Cruise",
         "Station",
         "Type",
-        "Longitude [deegrees_east]",
-        "Latitude [deegrees_north]",
+        "yyyy-mm-dd hh:mm",
+        "Lon (°E)",
+        "Lat (°N)",
         "Bot. Depth [m]",
         "Depth [m]",
-        "Date/Time",
-        "Value",
-        "Parameterid"
+        "QF"
     };
 
     /**
@@ -401,7 +401,7 @@
             }
             else if (outputMode.equalsIgnoreCase("odv")) {
                 Collection<Result> odvResult = this.getODVResult(uuid);
-                this.createODV(outputStream, odvResult);
+                this.createODV(outputStream, odvResult,uuid);
             }
         } catch (IOException e) {
             log.error(e, e);
@@ -488,11 +488,14 @@
     /**
      * TODO Result is not used at the moment. Change result with correct data.
      */
-    protected void createODV(OutputStream outputStream, Collection result)
+    protected void createODV(OutputStream outputStream, 
+                             Collection result,
+                             String uuid)
     throws IOException, StateException {
 
-        DefaultExport export = new DefaultExport(new SimpleOdvDataCollector(
-            TIMESERIES_ODV_PROFILE_NAMES));
+        Export export = new ODVExport(new SimpleOdvDataCollector(
+            TIMESERIES_ODV_PROFILE_NAMES),
+            this.getParameters(uuid));
 
         if (result == null)
             log.error("#################### RESULT == NULL #################");

http://dive4elements.wald.intevation.org