# HG changeset patch # User Andre Heinecke # Date 1409912562 -7200 # Node ID 42ac86ec19c7d5a75dad9d85ecea489b9ff624c3 # Parent fdec8ab16fa77ecaaaaa10156eb9ce168e00bda6 (issue1448) Add sq time intervals to sediment load data model. diff -r fdec8ab16fa7 -r 42ac86ec19c7 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Fri Sep 05 12:19:13 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Fri Sep 05 12:22:42 2014 +0200 @@ -17,10 +17,14 @@ import java.util.TreeMap; import java.util.TreeSet; -import org.dive4elements.river.backend.utils.EpsilonComparator; +import org.apache.log4j.Logger; + +import org.dive4elements.river.utils.EpsilonComparator; public class SedimentLoadData implements Serializable { + private static Logger logger = Logger.getLogger(SedimentLoadData.class); + public static final int GF_UNKNOWN = -1; public static final int GF_COARSE = 0; public static final int GF_FINE_MIDDLE = 1; @@ -104,11 +108,14 @@ private int id; private int kind; + private int sqRelId; private String description; private Date startTime; private Date stopTime; + private Date sqStartTime; + private Date sqStopTime; public Load() { } @@ -118,19 +125,30 @@ int kind, String description, Date startTime, - Date stopTime + Date stopTime, + int sqRelId, + Date sqStartTime, + Date sqStopTime ) { this.id = id; this.kind = kind; this.description = description; this.startTime = startTime; this.stopTime = stopTime; + this.sqStartTime = sqStartTime; + this.sqStopTime = sqStopTime; + this.sqRelId = sqRelId; + logger.debug("Creating Load with sqrelid: " + sqRelId + " start: "+ sqStartTime); } public int getId() { return id; } + public int getSQRelationTimeIntervalId() { + return sqRelId; + } + public int getKind() { return kind; } @@ -147,6 +165,14 @@ return stopTime; } + public Date getSQStartTime() { + return startTime; + } + + public Date getSQStopTime() { + return stopTime; + } + public boolean isEpoch() { return startTime != null && stopTime != null; } @@ -414,6 +440,51 @@ } }; + public static final Comparator LOAD_SQ_TI_CMP = new Comparator() { + @Override + public int compare(Load a, Load b) { + return a.getSQRelationTimeIntervalId() - b.getSQRelationTimeIntervalId(); + } + }; + + public static final Comparator LOAD_ID_SQ_TI_CMP = new Comparator() { + @Override + public int compare(Load a, Load b) { + return LOAD_ID_CMP.compare(a, b) + LOAD_SQ_TI_CMP.compare(a,b); + } + }; + + /** Find all loads in the range a/b with the according sq_time_interval */ + public Collection findLoads(double a, double b, int sqRelationTimeInterval) { + final TreeSet loads = new TreeSet(LOAD_ID_SQ_TI_CMP); + + findStations(a, b, new Visitor() { + @Override + public void visit(Station station) { + station.allLoads(loads); + } + }); + + return loads; + } + + /** Get a list of loads with unique sq_time_intervals. + * + * This is mainly a convenience function for the SedimentLoadInfoService. + */ + public Collection findUniqueTimeIntervalLoads(double a, double b) { + final TreeSet loads = new TreeSet(LOAD_SQ_TI_CMP); + + findStations(a, b, new Visitor() { + @Override + public void visit(Station station) { + station.allLoads(loads); + } + }); + + return loads; + } + public Collection findLoads(double a, double b) { final TreeSet loads = new TreeSet(LOAD_ID_CMP); diff -r fdec8ab16fa7 -r 42ac86ec19c7 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java Fri Sep 05 12:19:13 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java Fri Sep 05 12:22:42 2014 +0200 @@ -37,6 +37,9 @@ "sl.description AS sl_description, " + "ti.start_time AS ti_start_time, " + "ti.stop_time AS ti_stop_time, " + + "sqti.start_time AS sq_start_time, " + + "sqti.stop_time AS sq_stop_time, " + + "sqti.id AS sq_ti_id, " + "slv.value AS slv_value, " + "gf.name AS gf_name, " + "ms.id AS ms_id, " + @@ -45,6 +48,7 @@ "FROM sediment_load_values slv " + "JOIN sediment_load sl ON slv.sediment_load_id = sl.id " + "JOIN time_intervals ti ON sl.time_interval_id = ti.id " + + "JOIN time_intervals sqti ON sl.sq_time_interval_id = sqti.id " + "JOIN grain_fraction gf ON sl.grain_fraction_id = gf.id " + "JOIN measurement_station ms ON slv.measurement_station_id = ms.id " + "JOIN rivers r ON ms.river_id = r.id " + @@ -107,6 +111,9 @@ .addScalar("sl_description", StandardBasicTypes.STRING) .addScalar("ti_start_time", StandardBasicTypes.TIMESTAMP) .addScalar("ti_stop_time", StandardBasicTypes.TIMESTAMP) + .addScalar("sq_start_time", StandardBasicTypes.TIMESTAMP) + .addScalar("sq_stop_time", StandardBasicTypes.TIMESTAMP) + .addScalar("sq_ti_id", StandardBasicTypes.INTEGER) .addScalar("slv_value", StandardBasicTypes.DOUBLE) .addScalar("gf_name", StandardBasicTypes.STRING) .addScalar("ms_id", StandardBasicTypes.INTEGER) @@ -130,16 +137,20 @@ String sl_description = (String)row[2]; Timestamp ti_start_time = (Timestamp)row[3]; Timestamp ti_stop_time = (Timestamp)row[4]; - Double slv_value = (Double)row[5]; - String gf_name = (String)row[6]; - Integer ms_id = (Integer)row[7]; - Double ms_station = (Double)row[8]; - String ms_type = (String)row[9]; + Timestamp sq_start_time = (Timestamp)row[5]; + Timestamp sq_stop_time = (Timestamp)row[6]; + Integer sq_id = (Integer)row[7]; + Double slv_value = (Double)row[8]; + String gf_name = (String)row[9]; + Integer ms_id = (Integer)row[10]; + Double ms_station = (Double)row[11]; + String ms_type = (String)row[12]; if (load == null || load.getId() != sl_id) { load = new SedimentLoadData.Load( sl_id, sl_kind, sl_description, - ti_start_time, ti_stop_time); + ti_start_time, ti_stop_time, sq_id, + sq_start_time, sq_stop_time); // Grain fractions only change when a new sediment load starts. grainFractionIndex =