comparison 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
comparison
equal deleted inserted replaced
3788:71834666447d 3789:9f92c42b7a81
282 } 282 }
283 283
284 return new Object[] { days, qs }; 284 return new Object[] { days, qs };
285 } 285 }
286 286
287 /**
288 * Calculates the maximum and minimum W and Q values
289 *
290 * @return the MaxMinWQ object representing the calculated values
291 */
292 public MinMaxWQ fetchMaxMinWQ() {
293 Session session = SessionHolder.HOLDER.get();
294
295 Query query = session.createQuery(
296 "select max(mv.value) as max, min(mv.value) as min " +
297 "from MainValue as mv " +
298 "join mv.mainValue as nmv " +
299 "join nmv.type mvt " +
300 "where mvt.name = 'W' and mv.gauge.id = :gauge_id " +
301 "group by mvt.name order by mvt.name"
302 );
303
304 query.setParameter("gauge_id", getId());
305
306 List<Object> results = query.list();
307 if (results.size() == 0) {
308 // No values found
309 return new MinMaxWQ();
310 }
311
312 BigDecimal maxw;
313 BigDecimal minw;
314 BigDecimal maxq = null;
315 BigDecimal minq = null;
316
317 Object[] arr = (Object[]) results.get(0);
318 maxw = (BigDecimal)arr[0];
319 minw = (BigDecimal)arr[1];
320
321 if (results.size() > 1) {
322 arr = (Object[]) results.get(1);
323 maxq = (BigDecimal)arr[0];
324 minq = (BigDecimal)arr[1];
325 }
326
327 return new MinMaxWQ(minw, maxw, minq, maxq);
328 }
287 329
288 /** XXX: Can some one (ingo) tell me, what's the difference 330 /** XXX: Can some one (ingo) tell me, what's the difference
289 to simple call of getMainValues()? */ 331 to simple call of getMainValues()? */
290 public List<MainValue> fetchMainValues() { 332 public List<MainValue> fetchMainValues() {
291 // TODO: Use getMainValues() instead. 333 // TODO: Use getMainValues() instead.

http://dive4elements.wald.intevation.org