diff flys-backend/src/main/java/de/intevation/flys/model/Gauge.java @ 3789:9f92c42b7a81

Add method fetchMinMaxWQ to Gauge fetchMinMaxWQ returns a MinMaxWQ object instance that represents the gauge overview info. flys-backend/trunk@5415 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Mon, 10 Sep 2012 08:20:50 +0000
parents 71834666447d
children 6546c0bbc6f9
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java	Sat Sep 08 13:31:03 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java	Mon Sep 10 08:20:50 2012 +0000
@@ -284,6 +284,48 @@
         return new Object[] { days, qs };
     }
 
+    /**
+     * Calculates the maximum and minimum W and Q values
+     *
+     * @return the MaxMinWQ object representing the calculated values
+     */
+    public MinMaxWQ fetchMaxMinWQ() {
+        Session session = SessionHolder.HOLDER.get();
+
+        Query query = session.createQuery(
+            "select max(mv.value) as max, min(mv.value) as min " +
+            "from MainValue as mv " +
+            "join mv.mainValue as nmv " +
+            "join nmv.type mvt " +
+            "where mvt.name = 'W' and mv.gauge.id = :gauge_id " +
+            "group by mvt.name order by mvt.name"
+            );
+
+        query.setParameter("gauge_id", getId());
+
+        List<Object> results = query.list();
+        if (results.size() == 0) {
+            // No values found
+            return new MinMaxWQ();
+        }
+
+        BigDecimal maxw;
+        BigDecimal minw;
+        BigDecimal maxq = null;
+        BigDecimal minq = null;
+
+        Object[] arr = (Object[]) results.get(0);
+        maxw = (BigDecimal)arr[0];
+        minw = (BigDecimal)arr[1];
+
+        if (results.size() > 1) {
+            arr = (Object[]) results.get(1);
+            maxq = (BigDecimal)arr[0];
+            minq = (BigDecimal)arr[1];
+        }
+
+        return new MinMaxWQ(minw, maxw, minq, maxq);
+    }
 
     /** XXX: Can some one (ingo) tell me, what's the difference
              to simple call of  getMainValues()? */

http://dive4elements.wald.intevation.org