diff flys-backend/src/main/java/de/intevation/flys/model/Gauge.java @ 3686:c959444ff395

Add getDurationCurveData method to Gauge class Move static getDurationCurveData method from flys-artifacts WINFOArtifact class to a instance method in Gauge class. flys-backend/trunk@5366 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Thu, 06 Sep 2012 12:06:57 +0000
parents 8df746f374cc
children 8d38ee2de514
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java	Thu Aug 30 13:19:13 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java	Thu Sep 06 12:06:57 2012 +0000
@@ -241,5 +241,48 @@
 
         return null;
     }
+
+    /**
+     * Returns an array of [days, qs] necessary to create duration curves.
+     *
+     * @return a 2dim array of [days, qs] where days is an int[] and qs is
+     * an double[].
+     */
+    public Object[] getDurationCurveData() {
+        Session session = SessionHolder.HOLDER.get();
+
+        Query query = session.createQuery(
+            "select cast(nmv.name as integer) as days, mv.value as q " +
+            "from MainValue as mv " +
+            "join mv.mainValue as nmv " +
+            "join nmv.type mvt " +
+            "where mvt.name = 'D' and mv.gauge.id = :gauge_id " +
+            "order by days");
+
+        query.setParameter("gauge_id", getId());
+
+        List<Object> results = query.list();
+        int[]        days    = new int[results.size()];
+        double[]     qs      = new double[results.size()];
+
+        int idx = 0;
+
+        for (Object obj: results) {
+            Object[] arr = (Object[]) obj;
+
+            try {
+                int  day = ((Integer)    arr[0]).intValue();
+                double q = ((BigDecimal) arr[1]).doubleValue();
+
+                days[idx] = day;
+                qs[idx++] = q;
+            }
+            catch (NumberFormatException nfe) {
+            }
+        }
+
+        return new Object[] { days, qs };
+    }
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org