Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesFactory.java @ 385:478940d06876
Enabled the WINFO artifact to create duration curves - new OutGenerator, added methods for data computation.
flys-artifacts/trunk@1802 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 03 May 2011 12:05:32 +0000 |
parents | 4791fd92a208 |
children | 3e1149adc8b9 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesFactory.java Tue May 03 09:23:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesFactory.java Tue May 03 12:05:32 2011 +0000 @@ -1,7 +1,10 @@ package de.intevation.flys.artifacts.model; +import java.math.BigDecimal; import java.util.List; +import org.apache.log4j.Logger; + import org.hibernate.Session; import org.hibernate.Query; @@ -16,6 +19,8 @@ */ public class MainValuesFactory { + private static Logger logger = Logger.getLogger(MainValuesFactory.class); + public static List<MainValue> getMainValues(Gauge gauge) { Session session = SessionHolder.HOLDER.get(); @@ -25,5 +30,51 @@ return query.list(); } + + + /** + * Returns an array of [days, qs] necessary to create duration curves. + * + * @param gauge The selected gauge. + * + * @return a 2dim array of [days, qs] where days is an int[] and qs is + * an double[]. + */ + public static Object[] getDurationCurveData(Gauge gauge) { + 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", gauge.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) { + logger.warn(nfe, nfe); + } + } + + return new Object[] { days, qs }; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :