# HG changeset patch # User Bjoern Ricks # Date 1347265250 0 # Node ID 9f92c42b7a813db0963fd60998af078e97b07ad5 # Parent 71834666447da386bb6c79ede8654cc3239797ef 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 diff -r 71834666447d -r 9f92c42b7a81 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Sat Sep 08 13:31:03 2012 +0000 +++ b/flys-backend/ChangeLog Mon Sep 10 08:20:50 2012 +0000 @@ -1,3 +1,10 @@ +2012-09-10 Björn Ricks + + * src/main/java/de/intevation/flys/model/MinMaxWQ.java, + src/main/java/de/intevation/flys/model/Gauge.java: + Add method fetchMinMaxWQ to Gauge. This mehtod returns a new MinMaxWQ + instance that contains the fetched values for the gauge overview info. + 2012-09-09 Sascha L. Teichmann * src/main/java/de/intevation/flys/model/Gauge.java: diff -r 71834666447d -r 9f92c42b7a81 flys-backend/src/main/java/de/intevation/flys/model/Gauge.java --- 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 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()? */ diff -r 71834666447d -r 9f92c42b7a81 flys-backend/src/main/java/de/intevation/flys/model/MinMaxWQ.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/MinMaxWQ.java Mon Sep 10 08:20:50 2012 +0000 @@ -0,0 +1,58 @@ +package de.intevation.flys.model; + +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * Represents minmimum and maximum values for W and Q + */ +public class MinMaxWQ implements Serializable { + + private BigDecimal minw; + private BigDecimal maxw; + private BigDecimal minq; + private BigDecimal maxq; + + /** + * Default constuctor to indecate that no min and max w and q values + * are available + */ + public MinMaxWQ() { + } + + /** + * Constructor for a new MinMaxWQ value + * + * @param minw Mimimim W + * @param maxw Maximum W + * @param minq Mimimim Q + * @param maxq Maximum Q + */ + public MinMaxWQ( + BigDecimal minw, + BigDecimal maxw, + BigDecimal minq, + BigDecimal maxq) + { + this.minw = minw; + this.maxw = maxw; + this.minq = minq; + this.maxq = maxq; + } + + public BigDecimal getMinW() { + return this.minw; + } + + public BigDecimal getMaxW() { + return this.maxw; + } + + public BigDecimal getMinQ() { + return this.minq; + } + + public BigDecimal getMaxQ() { + return this.maxq; + } +}