Mercurial > dive4elements > river
changeset 3686:c959444ff395
Add getDurationCurveData method to Gauge class
Move static getDurationCurveData method from flys-artifacts WINFOArtifact
class to a instance method in Gauge class.
flys-backend/trunk@5366 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Thu, 06 Sep 2012 12:06:57 +0000 (2012-09-06) |
parents | f3686b443d1e |
children | 69aa82ebff25 |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/model/Gauge.java |
diffstat | 2 files changed, 49 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Thu Aug 30 13:19:13 2012 +0000 +++ b/flys-backend/ChangeLog Thu Sep 06 12:06:57 2012 +0000 @@ -1,3 +1,9 @@ +2012-09-06 Björn Ricks <bjoern.ricks@intevation.de> + + * src/main/java/de/intevation/flys/model/Gauge.java: + Move static getDurationCurveData method from flys-artifacts WINFOArtifact + class to a instance method in Gauge class. + 2012-08-30 Felix Wolfsteller <felix.wolfsteller@intevation.de> Attempt fix for issue821 (cross sections just till +/-500m).
--- a/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java Thu Aug 30 13:19:13 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java Thu Sep 06 12:06:57 2012 +0000 @@ -241,5 +241,48 @@ return null; } + + /** + * Returns an array of [days, qs] necessary to create duration curves. + * + * @return a 2dim array of [days, qs] where days is an int[] and qs is + * an double[]. + */ + public Object[] getDurationCurveData() { + 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", 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) { + } + } + + return new Object[] { days, qs }; + } + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :