comparison 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
comparison
equal deleted inserted replaced
9116:edc3958b3ed2 9117:623b51bf03d7
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 *
6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details.
9 */
10
11 package org.dive4elements.river.model.sinfo;
12
13 import java.io.Serializable;
14 import java.util.ArrayList;
15 import java.util.Date;
16 import java.util.List;
17
18 import org.dive4elements.river.backend.SessionHolder;
19 import org.hibernate.SQLQuery;
20 import org.hibernate.Session;
21 import org.hibernate.type.StandardBasicTypes;
22
23
24 /**
25 * Aggregation of collision_values
26 *
27 * @author Matthias Schäfer
28 *
29 */
30 public class CollisionAggregateValue implements Serializable {
31
32 /***** FIELDS *****/
33
34 private static final long serialVersionUID = 1;
35
36 private Collision parent;
37
38 private double station;
39
40 // private CollisionType collisionType;
41
42 private Date minDate;
43
44 private Date maxDate;
45
46 private int count;
47
48 private double gaugeW;
49
50
51 /***** CONSTRUCTORS *****/
52
53 public CollisionAggregateValue() {
54 }
55
56 public CollisionAggregateValue(final Collision collision, final double station, final Date minDate, final Date maxDate, final int count,
57 final double gaugeW) {
58 this.parent = collision;
59 this.station = station;
60 // this.collisionType = collisionType;
61 this.minDate = minDate;
62 this.maxDate = maxDate;
63 this.count = count;
64 this.gaugeW = gaugeW;
65 }
66
67
68 /***** METHODS *****/
69
70 public int getCount() {
71 return this.count;
72 }
73
74 public Collision getCollision() {
75 return this.parent;
76 }
77
78 public double getStation() {
79 return this.station;
80 }
81
82 // public CollisionType getCollisionType() {
83 // return this.collisionType;
84 // }
85
86 public Date getMinDate() {
87 return this.minDate;
88 }
89
90 public Date getMaxDate() {
91 return this.maxDate;
92 }
93
94 public Double getGaugeW() {
95 return this.gaugeW;
96 }
97
98 /**
99 * Selects the collision aggregate values of a data series in a km range from the database
100 */
101 public static List<CollisionAggregateValue> getValuesByKm(final Collision parent, final double kmLo, final double kmHi) {
102 final Session session = SessionHolder.HOLDER.get();
103 final SQLQuery query = session.createSQLQuery("SELECT FLOOR(station+0.4999) AS station, COUNT(*) AS count,"
104 + " MIN(event_date) AS date_min, MAX(event_date) AS date_max,"
105 + " AVG(gauge_w) AS gauge_w"
106 + " FROM collision_values v INNER JOIN collision s ON v.collision_id=s.id"
107 + " WHERE (collision_id=:parent)"
108 + " AND (station BETWEEN (:kmLo - 0.0001) AND (:kmHi + 0.0001))"
109 + " GROUP BY FLOOR(station+0.4999);").addScalar("station", StandardBasicTypes.DOUBLE)
110 .addScalar("count", StandardBasicTypes.INTEGER).addScalar("date_min", StandardBasicTypes.DATE)
111 .addScalar("date_max", StandardBasicTypes.DATE).addScalar("gauge_w", StandardBasicTypes.DOUBLE);
112 query.setInteger("parent", parent.getId());
113 query.setDouble("kmLo", new Double(kmLo));
114 query.setDouble("kmHi", new Double(kmHi));
115 final List<CollisionAggregateValue> values = new ArrayList();
116 final List<Object[]> rows = query.list();
117 if (rows != null) {
118 for (int i = 0; i <= rows.size() - 1; i++) {
119 values.add(new CollisionAggregateValue(parent, (double) rows.get(i)[0], (Date) rows.get(i)[2], (Date) rows.get(i)[3],
120 (int) rows.get(i)[1], (double) rows.get(i)[4]));
121 }
122 }
123 return values;
124 }
125 }

http://dive4elements.wald.intevation.org