Mercurial > dive4elements > river
changeset 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 |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/model/Gauge.java flys-backend/src/main/java/de/intevation/flys/model/MinMaxWQ.java |
diffstat | 3 files changed, 107 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 <bjoern.ricks@intevation.de> + + * 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 <sascha.teichmann@intevation.de> * 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<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()? */
--- /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; + } +}