comparison flys-backend/src/main/java/de/intevation/flys/model/Gauge.java @ 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
parents 8df746f374cc
children 8d38ee2de514
comparison
equal deleted inserted replaced
3685:f3686b443d1e 3686:c959444ff395
239 } 239 }
240 } 240 }
241 241
242 return null; 242 return null;
243 } 243 }
244
245 /**
246 * Returns an array of [days, qs] necessary to create duration curves.
247 *
248 * @return a 2dim array of [days, qs] where days is an int[] and qs is
249 * an double[].
250 */
251 public Object[] getDurationCurveData() {
252 Session session = SessionHolder.HOLDER.get();
253
254 Query query = session.createQuery(
255 "select cast(nmv.name as integer) as days, mv.value as q " +
256 "from MainValue as mv " +
257 "join mv.mainValue as nmv " +
258 "join nmv.type mvt " +
259 "where mvt.name = 'D' and mv.gauge.id = :gauge_id " +
260 "order by days");
261
262 query.setParameter("gauge_id", getId());
263
264 List<Object> results = query.list();
265 int[] days = new int[results.size()];
266 double[] qs = new double[results.size()];
267
268 int idx = 0;
269
270 for (Object obj: results) {
271 Object[] arr = (Object[]) obj;
272
273 try {
274 int day = ((Integer) arr[0]).intValue();
275 double q = ((BigDecimal) arr[1]).doubleValue();
276
277 days[idx] = day;
278 qs[idx++] = q;
279 }
280 catch (NumberFormatException nfe) {
281 }
282 }
283
284 return new Object[] { days, qs };
285 }
286
244 } 287 }
245 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 288 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org