changeset 8539:84929f882fa2

(issue1753) Carry measurement date through SQ values
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 13 Feb 2015 12:34:06 +0100
parents c25a8066d99f
children 422a78fbb4df
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/LogSQ.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurement.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/MeasurementFactory.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurements.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQ.java
diffstat 5 files changed, 40 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/LogSQ.java	Fri Feb 13 12:31:59 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/LogSQ.java	Fri Feb 13 12:34:06 2015 +0100
@@ -8,6 +8,8 @@
 
 package org.dive4elements.river.artifacts.model.sq;
 
+import java.util.Date;
+
 public class LogSQ extends SQ {
 
     public static final View LOG_SQ_VIEW = new View() {
@@ -20,12 +22,17 @@
         public double getQ(SQ sq) {
             return ((LogSQ)sq).getLogQ();
         }
+
+        @Override
+        public Date getDate(SQ sq) {
+            return sq.getDate();
+        }
     };
 
     public static final Factory LOG_SQ_FACTORY = new Factory() {
         @Override
-        public SQ createSQ(double s, double q) {
-            return new LogSQ(s, q);
+        public SQ createSQ(double s, double q, Date d) {
+            return new LogSQ(s, q, d);
         }
     };
 
@@ -37,8 +44,8 @@
     public LogSQ() {
     }
 
-    public LogSQ(double s, double q) {
-        super(s, q);
+    public LogSQ(double s, double q, Date d) {
+        super(s, q, d);
     }
 
     /** important: We cannot process negative s/q. */
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurement.java	Fri Feb 13 12:31:59 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurement.java	Fri Feb 13 12:34:06 2015 +0100
@@ -10,6 +10,7 @@
 
 import java.util.List;
 import java.util.Map;
+import java.util.Date;
 
 import org.apache.log4j.Logger;
 
@@ -109,6 +110,10 @@
         return S_SS() + S_BL_S() + S_BL_FG() + S_BL_CG();
     }
 
+    public Date getDate() {
+        return  (Date)data.get("DATUM");
+    }
+
     @Override
     public String toString() {
         return "Measurement: " + data;
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/MeasurementFactory.java	Fri Feb 13 12:31:59 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/MeasurementFactory.java	Fri Feb 13 12:34:06 2015 +0100
@@ -46,7 +46,8 @@
         "SELECT " +
             "m.Q_BPEGEL AS Q_BPEGEL,"+
             "m.TSCHWEB  AS TSCHWEB," +
-            "m.TSAND    AS TSAND " +
+            "m.TSAND    AS TSAND, " +
+            "m.DATUM    AS DATUM " +
         "FROM MESSUNG m " +
             "JOIN STATION   s ON m.STATIONID   = s.STATIONID " +
             "JOIN GEWAESSER r ON s.GEWAESSERID = r.GEWAESSERID " +
@@ -281,7 +282,8 @@
         SQLQuery query = session.createSQLQuery(SQL_TOTALS)
             .addScalar("Q_BPEGEL", StandardBasicTypes.DOUBLE)
             .addScalar("TSCHWEB",  StandardBasicTypes.DOUBLE)
-            .addScalar("TSAND",    StandardBasicTypes.DOUBLE);
+            .addScalar("TSAND",    StandardBasicTypes.DOUBLE)
+            .addScalar("DATUM",    StandardBasicTypes.DATE);
 
         query.setString("river_name", river);
         query.setDouble("location", location);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurements.java	Fri Feb 13 12:31:59 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurements.java	Fri Feb 13 12:34:06 2015 +0100
@@ -99,7 +99,8 @@
         List<SQ> result = new ArrayList<SQ>(measuments.size());
         int invalid = 0;
         for (Measurement measument: measuments) {
-            SQ sq = sqFactory.createSQ(extractor.getS(measument), measument.Q());
+            SQ sq = sqFactory.createSQ(extractor.getS(measument), measument.Q(),
+                    measument.getDate());
             if (sq.isValid()) {
                 result.add(sq);
             }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQ.java	Fri Feb 13 12:31:59 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQ.java	Fri Feb 13 12:34:06 2015 +0100
@@ -10,24 +10,27 @@
 
 import java.io.Serializable;
 
+import java.util.Date;
+
 
 /** Represents S/Q pairs. They are immutable! */
 public class SQ implements Serializable {
 
     public interface Factory {
-        SQ createSQ(double s, double q);
+        SQ createSQ(double s, double q, Date d);
     }
 
     public static final Factory SQ_FACTORY = new Factory() {
         @Override
-        public SQ createSQ(double s, double q) {
-            return new SQ(s, q);
+        public SQ createSQ(double s, double q, Date d) {
+            return new SQ(s, q, d);
         }
     };
 
     public interface View {
         double getS(SQ sq);
         double getQ(SQ sq);
+        Date getDate(SQ sq);
     }
 
     public static final View SQ_VIEW = new View() {
@@ -40,17 +43,24 @@
         public double getQ(SQ sq) {
             return sq.getQ();
         }
+
+        @Override
+        public Date getDate(SQ sq) {
+            return sq.getDate();
+        }
     };
 
     protected double s;
     protected double q;
+    protected Date d;
 
     public SQ() {
     }
 
-    public SQ(double s, double q) {
+    public SQ(double s, double q, Date d) {
         this.s = s;
         this.q = q;
+        this.d = d;
     }
 
 
@@ -62,6 +72,10 @@
         return q;
     }
 
+    public Date getDate() {
+        return d;
+    }
+
     public boolean isValid() {
         return !Double.isNaN(s) && !Double.isNaN(q);
     }

http://dive4elements.wald.intevation.org