Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java @ 4066:f02aa4ff3c0f
S/Q relation: Fixed problem with loosing meassurement points.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 09 Oct 2012 19:02:39 +0200 |
parents | 60d88ec49c3b |
children | 0df2247d98e1 |
comparison
equal
deleted
inserted
replaced
4065:9d404069f361 | 4066:f02aa4ff3c0f |
---|---|
7 import java.util.HashMap; | 7 import java.util.HashMap; |
8 import java.util.List; | 8 import java.util.List; |
9 import java.util.Map; | 9 import java.util.Map; |
10 import java.util.TreeMap; | 10 import java.util.TreeMap; |
11 | 11 |
12 import org.apache.log4j.Logger; | |
13 | |
12 import org.hibernate.SQLQuery; | 14 import org.hibernate.SQLQuery; |
13 import org.hibernate.Session; | 15 import org.hibernate.Session; |
14 | 16 |
15 import org.hibernate.transform.BasicTransformerAdapter; | 17 import org.hibernate.transform.BasicTransformerAdapter; |
16 | 18 |
20 | 22 |
21 import de.intevation.flys.backend.SedDBSessionHolder; | 23 import de.intevation.flys.backend.SedDBSessionHolder; |
22 | 24 |
23 public class MeasurementFactory | 25 public class MeasurementFactory |
24 { | 26 { |
27 private static final Logger log = | |
28 Logger.getLogger(MeasurementFactory.class); | |
29 | |
25 public static final String SQL_TOTALS = | 30 public static final String SQL_TOTALS = |
26 "SELECT " + | 31 "SELECT " + |
27 "m.Q_BPEGEL AS Q_BPEGEL,"+ | 32 "m.Q_BPEGEL AS Q_BPEGEL,"+ |
28 "m.TSCHWEB AS TSCHWEB," + | 33 "m.TSCHWEB AS TSCHWEB," + |
29 "m.TSAND AS TSAND " + | 34 "m.TSAND AS TSAND " + |
213 Session session, | 218 Session session, |
214 String river, | 219 String river, |
215 double location, | 220 double location, |
216 DateRange dateRange | 221 DateRange dateRange |
217 ) { | 222 ) { |
223 boolean debug = log.isDebugEnabled(); | |
224 | |
218 SQLQuery query = session.createSQLQuery(SQL_FACTIONS) | 225 SQLQuery query = session.createSQLQuery(SQL_FACTIONS) |
219 .addScalar("Q_BPEGEL", StandardBasicTypes.DOUBLE) | 226 .addScalar("Q_BPEGEL", StandardBasicTypes.DOUBLE) |
220 .addScalar("DATUM", StandardBasicTypes.DATE) | 227 .addScalar("DATUM", StandardBasicTypes.DATE) |
221 .addScalar("GLOTRECHTEID", StandardBasicTypes.INTEGER) | 228 .addScalar("GLOTRECHTEID", StandardBasicTypes.INTEGER) |
222 .addScalar("LFDNR", StandardBasicTypes.INTEGER) | 229 .addScalar("LFDNR", StandardBasicTypes.INTEGER) |
278 query.setResultTransformer(FRACTIONS_TRANSFORMER); | 285 query.setResultTransformer(FRACTIONS_TRANSFORMER); |
279 | 286 |
280 @SuppressWarnings("unchecked") | 287 @SuppressWarnings("unchecked") |
281 List<Measurement> measuments = (List<Measurement>)query.list(); | 288 List<Measurement> measuments = (List<Measurement>)query.list(); |
282 | 289 |
290 if (debug) { | |
291 log.debug("num fraction results: " + measuments.size()); | |
292 } | |
293 | |
283 List<Measurement> same = new ArrayList<Measurement>(); | 294 List<Measurement> same = new ArrayList<Measurement>(); |
284 | 295 |
285 Integer lastLR = null; | 296 Integer lastLR = null; |
286 | 297 |
287 List<Measurement> accumulated = new ArrayList<Measurement>(); | 298 List<Measurement> accumulated = new ArrayList<Measurement>(); |
296 if (newDS && !same.isEmpty()) { | 307 if (newDS && !same.isEmpty()) { |
297 accumulated.add(accumulate(same)); | 308 accumulated.add(accumulate(same)); |
298 same.clear(); | 309 same.clear(); |
299 } | 310 } |
300 | 311 |
312 same.add(m); | |
313 | |
301 lastLR = currentLR; | 314 lastLR = currentLR; |
302 } | 315 } |
303 | 316 |
304 if (!same.isEmpty()) { | 317 if (!same.isEmpty()) { |
305 accumulated.add(accumulate(same)); | 318 accumulated.add(accumulate(same)); |
307 | 320 |
308 for (Measurement m: accumulated) { | 321 for (Measurement m: accumulated) { |
309 m.adjustSieves(); | 322 m.adjustSieves(); |
310 } | 323 } |
311 | 324 |
312 return separateByDate(accumulated); | 325 if (debug) { |
326 log.debug("Before date separation: " + accumulated.size()); | |
327 } | |
328 | |
329 accumulated = separateByDate(accumulated); | |
330 | |
331 if (debug) { | |
332 log.debug("After date separation: " + accumulated.size()); | |
333 } | |
334 | |
335 return accumulated; | |
313 } | 336 } |
314 | 337 |
315 protected static List<Measurement> separateByDate(List<Measurement> measurements) { | 338 protected static List<Measurement> separateByDate(List<Measurement> measurements) { |
316 | 339 |
317 List<Measurement> result = new ArrayList<Measurement>(); | 340 List<Measurement> result = new ArrayList<Measurement>(); |