# HG changeset patch # User Bjoern Ricks # Date 1346933217 0 # Node ID c959444ff3953c24bc761a5a0bc0dc6e3402f593 # Parent f3686b443d1e646eeca2bd7c4388366c66bf7711 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 diff -r f3686b443d1e -r c959444ff395 flys-backend/ChangeLog --- 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 + + * 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 Attempt fix for issue821 (cross sections just till +/-500m). diff -r f3686b443d1e -r c959444ff395 flys-backend/src/main/java/de/intevation/flys/model/Gauge.java --- 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 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 :