Mercurial > dive4elements > river
changeset 3755:9c555ce5ca50
Data objects and factory for minfo bedquality calculation.
flys-artifacts/trunk@5450 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 13 Sep 2012 10:34:51 +0000 |
parents | a93b79cca2ca |
children | 912a398968b6 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurement.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurementFactory.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/QualityMeasurements.java |
diffstat | 4 files changed, 236 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 <raimund.renkert@intevation.de> + + 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 <felix.wolfsteller@intevation.de> Added missing images for datacage config manual doc.
--- /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<String, Double> charDiameter; + + public QualityMeasurement() { + + } + + public QualityMeasurement( + double km, + Date date, + Map<String, Double> 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<String, Double> getAllDiameter() { + return charDiameter; + } + + public void setDiameter(Map<String, Double> charDiameter) { + this.charDiameter = charDiameter; + } + + public double getDiameter(String key) { + return charDiameter.get(key); + } + + public void setDiameter(String key, double value) { + charDiameter.put(key, value); + } +}
--- /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<String, Double> map = new HashMap<String, Double>(); + 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
--- /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<QualityMeasurement> measurements; + + public QualityMeasurements() { + } + + public QualityMeasurements(List<QualityMeasurement> list) { + measurements = list; + } + + public List<QualityMeasurement> getMeasurements() { + return measurements; + } + + public List<QualityMeasurement> getMeasurements(double km) { + List<QualityMeasurement> res = new LinkedList<QualityMeasurement>(); + for (QualityMeasurement qm: measurements) { + if (qm.getKm() == km) { + res.add(qm); + } + } + return res; + } + + public void setMeasurements(List<QualityMeasurement> list) { + this.measurements = list; + } + + public void addMeasurement(QualityMeasurement qm) { + this.measurements.add(qm); + } +}