diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java @ 3992:a9c93b7c9da1

Simpify the S(Q) fraction sieving stuff.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 30 Sep 2012 21:15:23 +0200
parents a4930c43b806
children ab3a4ad82ae1
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java	Sun Sep 30 19:03:26 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java	Sun Sep 30 21:15:23 2012 +0200
@@ -1,5 +1,6 @@
 package de.intevation.flys.artifacts.model.sq;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import de.intevation.flys.artifacts.model.DateRange;
@@ -35,6 +36,27 @@
                "gp.MENGE       AS MENGE," +
                "gp.GTRIEB      AS GTRIEB," +
                "m.TGESCHIEBE   AS TGESCHIEBE," +
+               "sie.SIEB01     AS SIEB01," +
+               "sie.SIEB02     AS SIEB02," +
+               "sie.SIEB03     AS SIEB03," +
+               "sie.SIEB04     AS SIEB04," +
+               "sie.SIEB05     AS SIEB05," +
+               "sie.SIEB06     AS SIEB06," +
+               "sie.SIEB07     AS SIEB07," +
+               "sie.SIEB08     AS SIEB08," +
+               "sie.SIEB09     AS SIEB09," +
+               "sie.SIEB10     AS SIEB10," +
+               "sie.SIEB11     AS SIEB11," +
+               "sie.SIEB12     AS SIEB12," +
+               "sie.SIEB13     AS SIEB13," +
+               "sie.SIEB14     AS SIEB14," +
+               "sie.SIEB15     AS SIEB15," +
+               "sie.SIEB16     AS SIEB16," +
+               "sie.SIEB17     AS SIEB17," +
+               "sie.SIEB18     AS SIEB18," +
+               "sie.SIEB19     AS SIEB19," +
+               "sie.SIEB20     AS SIEB20," +
+               "sie.SIEB21     AS SIEB21," +
                "gs.RSIEB01     AS RSIEB01," +
                "gs.RSIEB02     AS RSIEB02," +
                "gs.RSIEB03     AS RSIEB03," +
@@ -56,28 +78,7 @@
                "gs.RSIEB19     AS RSIEB19," +
                "gs.RSIEB20     AS RSIEB20," +
                "gs.RSIEB21     AS RSIEB21," +
-               "gs.REST        AS REST, " +
-               "COALESCE(sie.SIEB01, 0) AS SIEB01, " +
-               "COALESCE(sie.SIEB02, 0) AS SIEB02, " +
-               "COALESCE(sie.SIEB03, 0) AS SIEB03, " +
-               "COALESCE(sie.SIEB04, 0) AS SIEB04, " +
-               "COALESCE(sie.SIEB05, 0) AS SIEB05, " +
-               "COALESCE(sie.SIEB06, 0) AS SIEB06, " +
-               "COALESCE(sie.SIEB07, 0) AS SIEB07, " +
-               "COALESCE(sie.SIEB08, 0) AS SIEB08, " +
-               "COALESCE(sie.SIEB09, 0) AS SIEB09, " +
-               "COALESCE(sie.SIEB10, 0) AS SIEB10, " +
-               "COALESCE(sie.SIEB11, 0) AS SIEB11, " +
-               "COALESCE(sie.SIEB12, 0) AS SIEB12, " +
-               "COALESCE(sie.SIEB13, 0) AS SIEB13, " +
-               "COALESCE(sie.SIEB14, 0) AS SIEB14, " +
-               "COALESCE(sie.SIEB15, 0) AS SIEB15, " +
-               "COALESCE(sie.SIEB16, 0) AS SIEB16, " +
-               "COALESCE(sie.SIEB17, 0) AS SIEB17, " +
-               "COALESCE(sie.SIEB18, 0) AS SIEB18, " +
-               "COALESCE(sie.SIEB19, 0) AS SIEB19, " +
-               "COALESCE(sie.SIEB20, 0) AS SIEB20, " +
-               "COALESCE(sie.SIEB21, 0) AS SIEB21 " +
+               "gs.REST        AS REST " +
         "FROM MESSUNG m " +
             "JOIN STATION    s ON m.STATIONID    = s.STATIONID " +
             "JOIN glotrechte g ON m.MESSUNGID    = g.MESSUNGID " +
@@ -112,15 +113,45 @@
         public MeasurementResultTransformer() {
         }
 
+        private static final int index(String s) {
+            return Integer.parseInt(s.substring(s.length()-2))-1;
+        }
+
         @Override
         public Object transformTuple(Object [] tuple, String [] aliases) {
             Map<String, Object> map = new HashMap<String, Object>();
+
+            Sieve [] sieves = new Sieve[20];
+
+            List<Sieve> validSieves = new ArrayList<Sieve>(20);
+
             for (int i = 0; i < tuple.length; ++i) {
-                if (tuple[i] != null) {
-                    map.put(aliases[i], tuple[i]);
+                Object value = tuple[i];
+                if (value == null) {
+                    continue;
+                }
+                String alias = aliases[i];
+                if (alias.startsWith("SIEB")) {
+                    Sieve s = new Sieve((Double)value, 0d);
+                    sieves[index(alias)] = s;
+                }
+                else if (alias.startsWith("RSIEB")) {
+                    Sieve s = sieves[index(alias)];
+                    if (s != null) {
+                        s.setLoad((Double)value);
+                        validSieves.add(s);
+                    }
+                }
+                else if (alias.equals("REST")) {
+                    Sieve s = new Sieve(0d, (Double)value);
+                    validSieves.add(s);
+                }
+                else {
+                    map.put(alias, value);
                 }
             }
-            return new Measurement(map);
+
+            return new Measurement(map, validSieves);
         }
     } // class BasicTransformerAdapter
 

http://dive4elements.wald.intevation.org