comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java @ 6948:d4108d6c4000

Cosmetics, docs.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 30 Aug 2013 09:47:15 +0200
parents 70b440dc5317
children 5a348e3df0f8
comparison
equal deleted inserted replaced
6947:51f28e5417ee 6948:d4108d6c4000
203 return values; 203 return values;
204 } 204 }
205 205
206 /** 206 /**
207 * Get a sedimentLoad filled with data from db (or cache). 207 * Get a sedimentLoad filled with data from db (or cache).
208 * @param type "epoch","off_epoch" or "single" 208 * @param type "epoch", "off_epoch" or "single"
209 */ 209 */
210 public static SedimentLoad getLoadWithData( 210 public static SedimentLoad getLoadWithData(
211 String river, 211 String river,
212 String type, 212 String type,
213 double startKm, 213 double startKm,
357 ) { 357 ) {
358 log.debug("SedimentLoadFactory.getSedimentLoadWithDataUncached"); 358 log.debug("SedimentLoadFactory.getSedimentLoadWithDataUncached");
359 Session session = SessionHolder.HOLDER.get(); 359 Session session = SessionHolder.HOLDER.get();
360 SQLQuery sqlQuery = null; 360 SQLQuery sqlQuery = null;
361 361
362 List<MeasurementStation> allStations = RiverFactory.getRiver(river).getMeasurementStations(); 362 // Measurement stations: all, for float-stuff, for suspended stuff.
363 TreeMap<Double,MeasurementStation> floatStations = new TreeMap<Double, MeasurementStation>(); 363 // Because they need fast sorted access, use TreeMaps.
364 TreeMap<Double,MeasurementStation> suspStations = new TreeMap<Double, MeasurementStation>(); 364 // They map the starting validity range km to the station itself.
365 List<MeasurementStation> allStations =
366 RiverFactory.getRiver(river).getMeasurementStations();
367 TreeMap<Double,MeasurementStation> floatStations =
368 new TreeMap<Double, MeasurementStation>();
369 TreeMap<Double,MeasurementStation> suspStations =
370 new TreeMap<Double, MeasurementStation>();
371
372 // From all stations, sort into the two kinds, skip undefined ones.
365 for (MeasurementStation measurementStation: allStations) { 373 for (MeasurementStation measurementStation: allStations) {
366 if (measurementStation.getMeasurementType() == null || 374 if (measurementStation.getMeasurementType() == null ||
367 measurementStation.getRange() == null) { 375 measurementStation.getRange() == null) {
368 continue; 376 continue;
369 } 377 }
370 if (measurementStation.getMeasurementType().equals("Schwebstoff")) { 378 if (measurementStation.getMeasurementType().equals("Schwebstoff")) {
371 suspStations.put(measurementStation.getRange().getA().doubleValue(), measurementStation); 379 suspStations.put(
380 measurementStation.getRange().getA().doubleValue(),
381 measurementStation);
372 } 382 }
373 else if (measurementStation.getMeasurementType().equals("Geschiebe")) { 383 else if (measurementStation.getMeasurementType().equals("Geschiebe")) {
374 floatStations.put(measurementStation.getRange().getA().doubleValue(), measurementStation); 384 floatStations.put(
375 } 385 measurementStation.getRange().getA().doubleValue(),
376 } 386 measurementStation);
377 387 }
388 }
389
390 // Construct date constraint.
378 Calendar start = Calendar.getInstance(); 391 Calendar start = Calendar.getInstance();
379 start.set(syear - 1, 11, 31); 392 start.set(syear - 1, 11, 31);
380 Calendar end = Calendar.getInstance(); 393 Calendar end = Calendar.getInstance();
381 end.set(syear, 11, 30); 394 end.set(syear, 11, 30);
382 395
399 log.warn("Empty result for year calculation."); 412 log.warn("Empty result for year calculation.");
400 } 413 }
401 else { 414 else {
402 Object[] row = results.get(0); 415 Object[] row = results.get(0);
403 load = new SedimentLoad( 416 load = new SedimentLoad(
404 (String) row[0], 417 (String) row[0], //description
405 (Date) row[1], 418 (Date) row[1], //start
406 null, 419 null, //end
407 false, 420 false, //isEpoch
408 (String) row[4]); 421 (String) row[4]); //unit
409 } 422 }
410 load = getValues("coarse", sqlQuery, load, floatStations); 423 load = getValues("coarse", sqlQuery, load, floatStations);
411 load = getValues("fine_middle", sqlQuery, load, floatStations); 424 load = getValues("fine_middle", sqlQuery, load, floatStations);
412 load = getValues("sand", sqlQuery, load, floatStations); 425 load = getValues("sand", sqlQuery, load, floatStations);
413 load = getValues("suspended_sediment", sqlQuery, load, suspStations); 426 load = getValues("suspended_sediment", sqlQuery, load, suspStations);

http://dive4elements.wald.intevation.org