diff backend/src/main/java/org/dive4elements/river/model/sinfo/CollisionAggregateValue.java @ 9117:623b51bf03d7

Added datacage select and chart display for river bed collision counts loaded from database
author mschaefer
date Mon, 04 Jun 2018 17:31:51 +0200
parents
children 8d4e7e08dbc0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/CollisionAggregateValue.java	Mon Jun 04 17:31:51 2018 +0200
@@ -0,0 +1,125 @@
+/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.model.sinfo;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.dive4elements.river.backend.SessionHolder;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.type.StandardBasicTypes;
+
+
+/**
+ * Aggregation of collision_values
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class CollisionAggregateValue implements Serializable {
+
+    /***** FIELDS *****/
+
+    private static final long serialVersionUID = 1;
+
+    private Collision parent;
+
+    private double station;
+
+    // private CollisionType collisionType;
+
+    private Date minDate;
+
+    private Date maxDate;
+
+    private int count;
+
+    private double gaugeW;
+
+
+    /***** CONSTRUCTORS *****/
+
+    public CollisionAggregateValue() {
+    }
+
+    public CollisionAggregateValue(final Collision collision, final double station, final Date minDate, final Date maxDate, final int count,
+            final double gaugeW) {
+        this.parent = collision;
+        this.station = station;
+        // this.collisionType = collisionType;
+        this.minDate = minDate;
+        this.maxDate = maxDate;
+        this.count = count;
+        this.gaugeW = gaugeW;
+    }
+
+
+    /***** METHODS *****/
+
+    public int getCount() {
+        return this.count;
+    }
+
+    public Collision getCollision() {
+        return this.parent;
+    }
+
+    public double getStation() {
+        return this.station;
+    }
+
+    // public CollisionType getCollisionType() {
+    // return this.collisionType;
+    // }
+
+    public Date getMinDate() {
+        return this.minDate;
+    }
+
+    public Date getMaxDate() {
+        return this.maxDate;
+    }
+
+    public Double getGaugeW() {
+        return this.gaugeW;
+    }
+
+    /**
+     * Selects the collision aggregate values of a data series in a km range from the database
+     */
+    public static List<CollisionAggregateValue> getValuesByKm(final Collision parent, final double kmLo, final double kmHi) {
+        final Session session = SessionHolder.HOLDER.get();
+        final SQLQuery query = session.createSQLQuery("SELECT FLOOR(station+0.4999) AS station, COUNT(*) AS count,"
+                + " MIN(event_date) AS date_min, MAX(event_date) AS date_max,"
+                + "  AVG(gauge_w) AS gauge_w"
+                + " FROM collision_values v INNER JOIN collision s ON v.collision_id=s.id"
+                + " WHERE (collision_id=:parent)"
+                + " AND (station BETWEEN (:kmLo - 0.0001) AND (:kmHi + 0.0001))"
+                + " GROUP BY FLOOR(station+0.4999);").addScalar("station", StandardBasicTypes.DOUBLE)
+                .addScalar("count", StandardBasicTypes.INTEGER).addScalar("date_min", StandardBasicTypes.DATE)
+                .addScalar("date_max", StandardBasicTypes.DATE).addScalar("gauge_w", StandardBasicTypes.DOUBLE);
+        query.setInteger("parent", parent.getId());
+        query.setDouble("kmLo", new Double(kmLo));
+        query.setDouble("kmHi", new Double(kmHi));
+        final List<CollisionAggregateValue> values = new ArrayList();
+        final List<Object[]> rows = query.list();
+        if (rows != null) {
+            for (int i = 0; i <= rows.size() - 1; i++) {
+                values.add(new CollisionAggregateValue(parent, (double) rows.get(i)[0], (Date) rows.get(i)[2], (Date) rows.get(i)[3],
+                        (int) rows.get(i)[1], (double) rows.get(i)[4]));
+            }
+        }
+        return values;
+    }
+}

http://dive4elements.wald.intevation.org