Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java @ 6741:35f2d32b921d
issue1393: Survive when off-epochs no total data, but other.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 01 Aug 2013 12:08:46 +0200 |
parents | 68c7b5811c4f |
children | 91c43293e538 |
comparison
equal
deleted
inserted
replaced
6740:68c7b5811c4f | 6741:35f2d32b921d |
---|---|
409 getValues("susp_sand", sqlQuery, load, floatStations); | 409 getValues("susp_sand", sqlQuery, load, floatStations); |
410 | 410 |
411 return load; | 411 return load; |
412 } | 412 } |
413 else if (type.equals("off_epoch")) { | 413 else if (type.equals("off_epoch")) { |
414 // Set calendars to fetch the epochs by their start and end | |
415 // dates. | |
414 Calendar toStart = Calendar.getInstance(); | 416 Calendar toStart = Calendar.getInstance(); |
415 toStart.set(eyear - 1, 11, 31); | 417 toStart.set(eyear - 1, 11, 31); |
416 Calendar toEnd = Calendar.getInstance(); | 418 Calendar toEnd = Calendar.getInstance(); |
417 toEnd.set(eyear+1, 11, 31); | 419 toEnd.set(eyear+1, 00, 01); |
420 // Set query parameters. | |
418 sqlQuery = session.createSQLQuery(SQL_SELECT_EPOCHS_DATA) | 421 sqlQuery = session.createSQLQuery(SQL_SELECT_EPOCHS_DATA) |
419 .addScalar("description", StandardBasicTypes.STRING) | 422 .addScalar("description", StandardBasicTypes.STRING) |
420 .addScalar("startYear", StandardBasicTypes.DATE) | 423 .addScalar("startYear", StandardBasicTypes.DATE) |
421 .addScalar("load", StandardBasicTypes.DOUBLE) | 424 .addScalar("load", StandardBasicTypes.DOUBLE) |
422 .addScalar("km", StandardBasicTypes.DOUBLE) | 425 .addScalar("km", StandardBasicTypes.DOUBLE) |
425 sqlQuery.setString("name", river); | 428 sqlQuery.setString("name", river); |
426 sqlQuery.setDouble("startKm", startKm); | 429 sqlQuery.setDouble("startKm", startKm); |
427 sqlQuery.setDouble("endKm", endKm); | 430 sqlQuery.setDouble("endKm", endKm); |
428 sqlQuery.setDate("sbegin", start.getTime()); | 431 sqlQuery.setDate("sbegin", start.getTime()); |
429 sqlQuery.setDate("send", end.getTime()); | 432 sqlQuery.setDate("send", end.getTime()); |
430 sqlQuery.setDate("ebegin",toStart.getTime()); | 433 sqlQuery.setDate("ebegin", toStart.getTime()); |
431 sqlQuery.setDate("eend", toEnd.getTime()); | 434 sqlQuery.setDate("eend", toEnd.getTime()); |
432 sqlQuery.setString("grain", "total"); | 435 sqlQuery.setString("grain", "total"); |
433 | 436 |
434 List<Object[]> results = null; | 437 List<Object[]> results = null; |
435 results = sqlQuery.list(); | 438 results = sqlQuery.list(); |
436 | 439 |
437 SedimentLoad load = new SedimentLoad(); | 440 SedimentLoad load = null; |
438 if (results.isEmpty()) { | 441 if (results.isEmpty()) { |
439 log.warn("No results for off-epoch"); | 442 log.warn("No total results for off-epoch"); |
440 return new SedimentLoad(); | 443 } |
441 } | 444 else { |
442 Object[] row = results.get(0); | 445 Object[] row = results.get(0); |
443 load = new SedimentLoad( | 446 load = new SedimentLoad( |
444 (String) row[0], | 447 (String) row[0], |
445 (Date) row[1], | 448 (Date) row[1], |
446 (Date) row[4], | 449 (Date) row[4], |
447 true, | 450 true, |
448 (String)row[5]); | 451 (String)row[5]); |
449 TDoubleArrayList kms = new TDoubleArrayList(); | 452 TDoubleArrayList kms = new TDoubleArrayList(); |
450 for (int i = 0; i < results.size(); i++) { | 453 for (int i = 0; i < results.size(); i++) { |
451 row = results.get(i); | 454 row = results.get(i); |
452 kms.add((Double)row[3]); | 455 kms.add((Double)row[3]); |
453 load.setLoadTotal((Double)row[3], (Double)row[2]); | 456 load.setLoadTotal((Double)row[3], (Double)row[2]); |
454 } | 457 } |
455 getValues("coarse", sqlQuery, load, floatStations); | 458 } |
456 getValues("fine_middle", sqlQuery, load, floatStations); | 459 load = getValues("coarse", sqlQuery, load, floatStations); |
457 getValues("sand", sqlQuery, load, floatStations); | 460 load = getValues("fine_middle", sqlQuery, load, floatStations); |
458 getValues("suspended_sediment", sqlQuery, load, suspStations); | 461 load = getValues("sand", sqlQuery, load, floatStations); |
459 getValues("susp_sand_bed", sqlQuery, load, floatStations); | 462 load = getValues("suspended_sediment", sqlQuery, load, suspStations); |
460 getValues("susp_sand", sqlQuery, load, floatStations); | 463 load = getValues("susp_sand_bed", sqlQuery, load, floatStations); |
464 load = getValues("susp_sand", sqlQuery, load, floatStations); | |
461 return load; | 465 return load; |
462 } | 466 } |
463 return new SedimentLoad(); | 467 return new SedimentLoad(); |
464 } | 468 } |
465 | 469 |
466 | 470 |
467 /** | 471 /** |
468 * Run query with grain parameter set to fraction, feed result into | 472 * Run query with grain parameter set to fraction, feed result into |
469 * load. | 473 * load. Create load if null. |
474 * | |
470 * @param fraction value to set 'grain' parameter in query to. | 475 * @param fraction value to set 'grain' parameter in query to. |
471 * @param query query in which to set 'grain' parameter and run. | 476 * @param query query in which to set 'grain' parameter and run. |
472 * @param load[out] SedimentLoad which to populate with values. if null | 477 * @param load[out] SedimentLoad which to populate with values. if null |
473 * and values are found, return a new load. | 478 * and values are found, return a new load. |
479 * @return param load or new load if null. | |
474 */ | 480 */ |
475 protected static void getValues ( | 481 protected static SedimentLoad getValues ( |
476 String fraction, | 482 String fraction, |
477 SQLQuery query, | 483 SQLQuery query, |
478 SedimentLoad load, | 484 SedimentLoad load, |
479 TreeMap<Double, MeasurementStation> stations | 485 TreeMap<Double, MeasurementStation> stations |
480 ) { | 486 ) { |
481 query.setString("grain", fraction); | 487 query.setString("grain", fraction); |
482 List<Object[]> results = query.list(); | 488 List<Object[]> results = query.list(); |
489 | |
490 // We have the first results for this query, create new load. | |
491 if (!results.isEmpty() && load == null) { | |
492 Object[] row = results.get(0); | |
493 load = new SedimentLoad( | |
494 (String) row[0], | |
495 (Date) row[1], | |
496 (Date) row[4], | |
497 true, | |
498 (String)row[5]); | |
499 } | |
500 | |
483 for (int i = 0; i < results.size(); i++) { | 501 for (int i = 0; i < results.size(); i++) { |
484 Object[] row = results.get(i); | 502 Object[] row = results.get(i); |
485 double km = (Double)row[3]; | 503 double km = (Double)row[3]; |
486 MeasurementStation station = stations.get(km); | 504 MeasurementStation station = stations.get(km); |
487 MeasurementStation nextStation = null; | 505 MeasurementStation nextStation = null; |
524 } | 542 } |
525 else if (fraction.equals("susp_sand_bed")) { | 543 else if (fraction.equals("susp_sand_bed")) { |
526 load.setSuspSandBed(km, v, range); | 544 load.setSuspSandBed(km, v, range); |
527 } | 545 } |
528 } | 546 } |
547 | |
548 return load; | |
529 } | 549 } |
530 | 550 |
531 public static SedimentLoad getLoadUnknown( | 551 public static SedimentLoad getLoadUnknown( |
532 String river, | 552 String river, |
533 String description | 553 String description |