# HG changeset patch # User Raimund Renkert # Date 1347532491 0 # Node ID 9c555ce5ca504d756cacf65600bbef75156ecc83 # Parent a93b79cca2ca74936471e6a7f457e754b69d045e Data objects and factory for minfo bedquality calculation. flys-artifacts/trunk@5450 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a93b79cca2ca -r 9c555ce5ca50 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Sep 13 09:44:32 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Sep 13 10:34:51 2012 +0000 @@ -1,3 +1,12 @@ +2012-09-12 Raimund Renkert + + Objects and factory for minfo bedquality calculation data. + + * src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurementFactory.java, + src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurements.java, + src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurement.java: + New. Data objects and factory for minfo bed quality calculation. + 2012-09-13 Felix Wolfsteller Added missing images for datacage config manual doc. diff -r a93b79cca2ca -r 9c555ce5ca50 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurement.java Thu Sep 13 10:34:51 2012 +0000 @@ -0,0 +1,57 @@ +package de.intevation.flys.artifacts.model.minfo; + +import java.util.Date; +import java.util.Map; + +public class QualityMeasurement { + + private double km; + private Date date; + private Map charDiameter; + + public QualityMeasurement() { + + } + + public QualityMeasurement( + double km, + Date date, + Map diameter) + { + this.setKm(km); + this.setDate(date); + this.setDiameter(diameter); + } + + public double getKm() { + return km; + } + + public void setKm(double km) { + this.km = km; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public Map getAllDiameter() { + return charDiameter; + } + + public void setDiameter(Map charDiameter) { + this.charDiameter = charDiameter; + } + + public double getDiameter(String key) { + return charDiameter.get(key); + } + + public void setDiameter(String key, double value) { + charDiameter.put(key, value); + } +} diff -r a93b79cca2ca -r 9c555ce5ca50 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurementFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurementFactory.java Thu Sep 13 10:34:51 2012 +0000 @@ -0,0 +1,132 @@ +package de.intevation.flys.artifacts.model.minfo; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.hibernate.SQLQuery; +import org.hibernate.Session; +import org.hibernate.transform.BasicTransformerAdapter; +import org.hibernate.type.StandardBasicTypes; + +import de.intevation.flys.backend.SedDBSessionHolder; + +public class QualityMeasurementFactory { + + private static final String SQL_MEASUREMENT = + "SELECT st.km as km," + + " st.datum as date,"+ + " sa.d10 as d10," + + " sa.d16 as d16," + + " sa.d20 as d20," + + " sa.d25 as d25," + + " sa.d30 as d30," + + " sa.d40 as d40," + + " sa.d50 as d50," + + " sa.d60 as d60," + + " sa.d70 as d70," + + " sa.d75 as d75," + + " sa.d80 as d80," + + " sa.d84 as d84," + + " sa.d90 as d90," + + " sa.dmin as dmin," + + " sa.dmax as dmax " + + "FROM sohltest st" + + " JOIN station sn ON sn.stationid = st.stationid" + + " JOIN gewaesser gw ON gw.gewaesserid = sn.gewaesserid" + + " JOIN sohlprobe sp ON sp.sohltestid = st.sohltestid" + + " JOIN siebanalyse sa ON sa.sohlprobeid = sp.sohlprobeid" + + "WHERE gw.name = :name AND " + + " st.km IS NOT NULL AND " + + " st.km BETWEEN :from - 0.001 AND :to + 0.001 AND" + + " st.datum BETWEEN :start AND :end"; + + public static final class QualityMeasurementResultTransformer + extends BasicTransformerAdapter + { + public static QualityMeasurementResultTransformer INSTANCE = + new QualityMeasurementResultTransformer(); + + public QualityMeasurementResultTransformer() { + } + + @Override + public Object transformTuple(Object [] tuple, String [] aliases) { + Map map = new HashMap(); + double km = 0; + Date d = null; + for (int i = 0; i < tuple.length; ++i) { + if (tuple[i] != null) { + if (aliases[i].equals("km")) { + km = ((Number)tuple[i]).doubleValue(); + } + else if (aliases[i].equals("date")) { + d = (Date)tuple[i]; + } + else { + map.put(aliases[i], (Double)tuple[i]); + } + } + } + return new QualityMeasurement(km, d, map); + } + } // class BasicTransformerAdapter + + private QualityMeasurementFactory() { + } + + protected static QualityMeasurements load( + Session session, + String river, + double from, + double to, + Date start, + Date end + ) { + SQLQuery query = session.createSQLQuery(SQL_MEASUREMENT) + .addScalar("km", StandardBasicTypes.DOUBLE) + .addScalar("date", StandardBasicTypes.DATE) + .addScalar("d10", StandardBasicTypes.DOUBLE) + .addScalar("d16", StandardBasicTypes.DOUBLE) + .addScalar("d20", StandardBasicTypes.DOUBLE) + .addScalar("d25", StandardBasicTypes.DOUBLE) + .addScalar("d30", StandardBasicTypes.DOUBLE) + .addScalar("d40", StandardBasicTypes.DOUBLE) + .addScalar("d50", StandardBasicTypes.DOUBLE) + .addScalar("d60", StandardBasicTypes.DOUBLE) + .addScalar("d70", StandardBasicTypes.DOUBLE) + .addScalar("d75", StandardBasicTypes.DOUBLE) + .addScalar("d80", StandardBasicTypes.DOUBLE) + .addScalar("d84", StandardBasicTypes.DOUBLE) + .addScalar("d90", StandardBasicTypes.DOUBLE) + .addScalar("dmin", StandardBasicTypes.DOUBLE) + .addScalar("dmax", StandardBasicTypes.DOUBLE); + + query.setString("name", river); + query.setDouble("from", from); + query.setDouble("to", to); + query.setDate("start", start); + query.setDate("end", end); + + query.setResultTransformer( + QualityMeasurementResultTransformer.INSTANCE); + + return new QualityMeasurements(query.list()); + } + + public static QualityMeasurements getMeasurements( + String river, + double from, + double to, + Date start, + Date end + ) { + Session session = SedDBSessionHolder.HOLDER.get(); + try { + return load(session, river, from, to, start, end); + } + finally { + session.close(); + } + } +} \ No newline at end of file diff -r a93b79cca2ca -r 9c555ce5ca50 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurements.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurements.java Thu Sep 13 10:34:51 2012 +0000 @@ -0,0 +1,38 @@ +package de.intevation.flys.artifacts.model.minfo; + +import java.util.LinkedList; +import java.util.List; + +public class QualityMeasurements { + + private List measurements; + + public QualityMeasurements() { + } + + public QualityMeasurements(List list) { + measurements = list; + } + + public List getMeasurements() { + return measurements; + } + + public List getMeasurements(double km) { + List res = new LinkedList(); + for (QualityMeasurement qm: measurements) { + if (qm.getKm() == km) { + res.add(qm); + } + } + return res; + } + + public void setMeasurements(List list) { + this.measurements = list; + } + + public void addMeasurement(QualityMeasurement qm) { + this.measurements.add(qm); + } +}