[PATCH 2 of 2] issue1393: Survive when off-epochs no total data, but other
Wald Commits
scm-commit at wald.intevation.org
Thu Aug 1 11:58:57 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1375351726 -7200
# Node ID 35f2d32b921da9f5aa0c4e993d3160dab3796367
# Parent 68c7b5811c4fed94854bd06a2cde6975df09af72
issue1393: Survive when off-epochs no total data, but other.
diff -r 68c7b5811c4f -r 35f2d32b921d artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java Thu Aug 01 11:58:25 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java Thu Aug 01 12:08:46 2013 +0200
@@ -411,10 +411,13 @@
return load;
}
else if (type.equals("off_epoch")) {
+ // Set calendars to fetch the epochs by their start and end
+ // dates.
Calendar toStart = Calendar.getInstance();
toStart.set(eyear - 1, 11, 31);
Calendar toEnd = Calendar.getInstance();
- toEnd.set(eyear+1, 11, 31);
+ toEnd.set(eyear+1, 00, 01);
+ // Set query parameters.
sqlQuery = session.createSQLQuery(SQL_SELECT_EPOCHS_DATA)
.addScalar("description", StandardBasicTypes.STRING)
.addScalar("startYear", StandardBasicTypes.DATE)
@@ -427,37 +430,38 @@
sqlQuery.setDouble("endKm", endKm);
sqlQuery.setDate("sbegin", start.getTime());
sqlQuery.setDate("send", end.getTime());
- sqlQuery.setDate("ebegin",toStart.getTime());
+ sqlQuery.setDate("ebegin", toStart.getTime());
sqlQuery.setDate("eend", toEnd.getTime());
sqlQuery.setString("grain", "total");
List<Object[]> results = null;
results = sqlQuery.list();
- SedimentLoad load = new SedimentLoad();
+ SedimentLoad load = null;
if (results.isEmpty()) {
- log.warn("No results for off-epoch");
- return new SedimentLoad();
+ log.warn("No total results for off-epoch");
}
- Object[] row = results.get(0);
- load = new SedimentLoad(
- (String) row[0],
- (Date) row[1],
- (Date) row[4],
- true,
- (String)row[5]);
- TDoubleArrayList kms = new TDoubleArrayList();
- for (int i = 0; i < results.size(); i++) {
- row = results.get(i);
- kms.add((Double)row[3]);
- load.setLoadTotal((Double)row[3], (Double)row[2]);
+ else {
+ Object[] row = results.get(0);
+ load = new SedimentLoad(
+ (String) row[0],
+ (Date) row[1],
+ (Date) row[4],
+ true,
+ (String)row[5]);
+ TDoubleArrayList kms = new TDoubleArrayList();
+ for (int i = 0; i < results.size(); i++) {
+ row = results.get(i);
+ kms.add((Double)row[3]);
+ load.setLoadTotal((Double)row[3], (Double)row[2]);
+ }
}
- getValues("coarse", sqlQuery, load, floatStations);
- getValues("fine_middle", sqlQuery, load, floatStations);
- getValues("sand", sqlQuery, load, floatStations);
- getValues("suspended_sediment", sqlQuery, load, suspStations);
- getValues("susp_sand_bed", sqlQuery, load, floatStations);
- getValues("susp_sand", sqlQuery, load, floatStations);
+ load = getValues("coarse", sqlQuery, load, floatStations);
+ load = getValues("fine_middle", sqlQuery, load, floatStations);
+ load = getValues("sand", sqlQuery, load, floatStations);
+ load = getValues("suspended_sediment", sqlQuery, load, suspStations);
+ load = getValues("susp_sand_bed", sqlQuery, load, floatStations);
+ load = getValues("susp_sand", sqlQuery, load, floatStations);
return load;
}
return new SedimentLoad();
@@ -466,13 +470,15 @@
/**
* Run query with grain parameter set to fraction, feed result into
- * load.
+ * load. Create load if null.
+ *
* @param fraction value to set 'grain' parameter in query to.
* @param query query in which to set 'grain' parameter and run.
* @param load[out] SedimentLoad which to populate with values. if null
* and values are found, return a new load.
+ * @return param load or new load if null.
*/
- protected static void getValues (
+ protected static SedimentLoad getValues (
String fraction,
SQLQuery query,
SedimentLoad load,
@@ -480,6 +486,18 @@
) {
query.setString("grain", fraction);
List<Object[]> results = query.list();
+
+ // We have the first results for this query, create new load.
+ if (!results.isEmpty() && load == null) {
+ Object[] row = results.get(0);
+ load = new SedimentLoad(
+ (String) row[0],
+ (Date) row[1],
+ (Date) row[4],
+ true,
+ (String)row[5]);
+ }
+
for (int i = 0; i < results.size(); i++) {
Object[] row = results.get(i);
double km = (Double)row[3];
@@ -526,6 +544,8 @@
load.setSuspSandBed(km, v, range);
}
}
+
+ return load;
}
public static SedimentLoad getLoadUnknown(
More information about the Dive4elements-commits
mailing list