annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java @ 4006:d4e39cc5c10c

S(Q) relation: Removed unused field from SQL statement.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 01 Oct 2012 18:39:48 +0200
parents 22abdc45869c
children d4d272e56d3a
rev   line source
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model.sq;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
3992
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
3 import java.util.ArrayList;
4005
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
4 import java.util.Calendar;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
5 import java.util.Collections;
4004
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
6 import java.util.Date;
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
7 import java.util.List;
4001
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
8 import java.util.TreeMap;
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
9
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import de.intevation.flys.artifacts.model.DateRange;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import de.intevation.flys.backend.SedDBSessionHolder;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.util.HashMap;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.util.Map;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import org.apache.log4j.Logger;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import org.hibernate.SQLQuery;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import org.hibernate.Session;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 import org.hibernate.transform.BasicTransformerAdapter;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 import org.hibernate.type.StandardBasicTypes;
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 public class MeasurementFactory
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 {
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 private static final Logger log =
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 Logger.getLogger(MeasurementFactory.class);
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 public static final String SQL_MEASSURE =
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
32 "SELECT m.datum AS DATUM," +
3981
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
33 "g.GLOTRECHTEID AS GLOTRECHTEID," +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
34 "gp.LFDNR AS LFDNR," +
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
35 "g.UFERABST AS UFERABST," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
36 "g.UFERABLINKS AS UFERABLINKS," +
3929
f37323e86d59 S(Q) relation: Fixed SQL projection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3928
diff changeset
37 "m.TSCHWEB AS TSCHWEB," +
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
38 "m.TSAND AS TSAND," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
39 "gp.GTRIEB AS GTRIEB," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
40 "m.TGESCHIEBE AS TGESCHIEBE," +
3992
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
41 "sie.SIEB01 AS SIEB01," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
42 "sie.SIEB02 AS SIEB02," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
43 "sie.SIEB03 AS SIEB03," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
44 "sie.SIEB04 AS SIEB04," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
45 "sie.SIEB05 AS SIEB05," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
46 "sie.SIEB06 AS SIEB06," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
47 "sie.SIEB07 AS SIEB07," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
48 "sie.SIEB08 AS SIEB08," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
49 "sie.SIEB09 AS SIEB09," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
50 "sie.SIEB10 AS SIEB10," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
51 "sie.SIEB11 AS SIEB11," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
52 "sie.SIEB12 AS SIEB12," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
53 "sie.SIEB13 AS SIEB13," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
54 "sie.SIEB14 AS SIEB14," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
55 "sie.SIEB15 AS SIEB15," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
56 "sie.SIEB16 AS SIEB16," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
57 "sie.SIEB17 AS SIEB17," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
58 "sie.SIEB18 AS SIEB18," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
59 "sie.SIEB19 AS SIEB19," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
60 "sie.SIEB20 AS SIEB20," +
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
61 "sie.SIEB21 AS SIEB21," +
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
62 "gs.RSIEB01 AS RSIEB01," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
63 "gs.RSIEB02 AS RSIEB02," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
64 "gs.RSIEB03 AS RSIEB03," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
65 "gs.RSIEB04 AS RSIEB04," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
66 "gs.RSIEB05 AS RSIEB05," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
67 "gs.RSIEB06 AS RSIEB06," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
68 "gs.RSIEB07 AS RSIEB07," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
69 "gs.RSIEB08 AS RSIEB08," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
70 "gs.RSIEB09 AS RSIEB09," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
71 "gs.RSIEB10 AS RSIEB10," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
72 "gs.RSIEB11 AS RSIEB11," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
73 "gs.RSIEB12 AS RSIEB12," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
74 "gs.RSIEB13 AS RSIEB13," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
75 "gs.RSIEB14 AS RSIEB14," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
76 "gs.RSIEB15 AS RSIEB15," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
77 "gs.RSIEB16 AS RSIEB16," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
78 "gs.RSIEB17 AS RSIEB17," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
79 "gs.RSIEB18 AS RSIEB18," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
80 "gs.RSIEB19 AS RSIEB19," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
81 "gs.RSIEB20 AS RSIEB20," +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
82 "gs.RSIEB21 AS RSIEB21," +
3992
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
83 "gs.REST AS REST " +
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
84 "FROM MESSUNG m " +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
85 "JOIN STATION s ON m.STATIONID = s.STATIONID " +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
86 "JOIN glotrechte g ON m.MESSUNGID = g.MESSUNGID " +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
87 "JOIN gprobe gp ON g.GLOTRECHTEID = gp.GLOTRECHTEID " +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
88 "JOIN GSIEBUNG gs ON g.GLOTRECHTEID = gs.GLOTRECHTEID " +
3310
8af1111af180 SQ relation: More fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3308
diff changeset
89 "WHERE " +
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
90 "g.NAME = :river_name " +
3396
3bffbf670b49 Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3393
diff changeset
91 "AND m.Q_BPEGEL IS NOT NULL " +
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
92 "AND s.KM BETWEEN :location - 0.001 AND :location + 0.001 " +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
93 "AND m.DATUM BETWEEN :from AND :to " +
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
94 "AND m.TGESCHIEBE IS NOT NULL " +
4004
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
95 "AND m.DATUM IS NOT NULL " +
3981
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
96 "AND (" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
97 "COALESCE(gs.RSIEB01, 0) + COALESCE(gs.RSIEB02, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
98 "COALESCE(gs.RSIEB03, 0) + COALESCE(gs.RSIEB04, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
99 "COALESCE(gs.RSIEB05, 0) + COALESCE(gs.RSIEB06, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
100 "COALESCE(gs.RSIEB07, 0) + COALESCE(gs.RSIEB08, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
101 "COALESCE(gs.RSIEB09, 0) + COALESCE(gs.RSIEB10, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
102 "COALESCE(gs.RSIEB11, 0) + COALESCE(gs.RSIEB12, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
103 "COALESCE(gs.RSIEB13, 0) + COALESCE(gs.RSIEB14, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
104 "COALESCE(gs.RSIEB15, 0) + COALESCE(gs.RSIEB16, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
105 "COALESCE(gs.RSIEB17, 0) + COALESCE(gs.RSIEB18, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
106 "COALESCE(gs.RSIEB19, 0) + COALESCE(gs.RSIEB20, 0) +" +
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
107 "COALESCE(gs.RSIEB21, 0) + COALESCE(gs.REST, 0)) > 0 " +
4001
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
108 "ORDER BY m.DATUM, g.UFERABST, g.GLOTRECHTEID, gp.LFDNR";
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 public static final class MeasurementResultTransformer
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 extends BasicTransformerAdapter
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 {
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 public static MeasurementResultTransformer INSTANCE =
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 new MeasurementResultTransformer();
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 public MeasurementResultTransformer() {
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 }
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118
3992
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
119 private static final int index(String s) {
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
120 return Integer.parseInt(s.substring(s.length()-2))-1;
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
121 }
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
122
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 @Override
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 public Object transformTuple(Object [] tuple, String [] aliases) {
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 Map<String, Object> map = new HashMap<String, Object>();
3992
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
126
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
127 Sieve [] sieves = new Sieve[20];
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
128
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
129 List<Sieve> validSieves = new ArrayList<Sieve>(20);
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
130
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 for (int i = 0; i < tuple.length; ++i) {
3992
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
132 Object value = tuple[i];
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
133 if (value == null) {
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
134 continue;
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
135 }
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
136 String alias = aliases[i];
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
137 if (alias.startsWith("SIEB")) {
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
138 Sieve s = new Sieve((Double)value, 0d);
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
139 sieves[index(alias)] = s;
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
140 }
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
141 else if (alias.startsWith("RSIEB")) {
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
142 Sieve s = sieves[index(alias)];
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
143 if (s != null) {
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
144 s.setLoad((Double)value);
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
145 validSieves.add(s);
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
146 }
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
147 }
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
148 else if (alias.equals("REST")) {
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
149 Sieve s = new Sieve(0d, (Double)value);
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
150 validSieves.add(s);
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
151 }
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
152 else {
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
153 map.put(alias, value);
3291
b52c4b34ec1b SQ relation: Do not store null values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3290
diff changeset
154 }
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 }
3992
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
156
a9c93b7c9da1 Simpify the S(Q) fraction sieving stuff.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
157 return new Measurement(map, validSieves);
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 }
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 } // class BasicTransformerAdapter
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 private MeasurementFactory() {
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 }
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163
3290
36f3b53d5cfc SQ relation: Added infrastructure to extract fractions from measurments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3289
diff changeset
164 protected static Measurements load(
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 Session session,
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 String river,
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 double location,
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 DateRange dateRange
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 ) {
3308
5ccd51ca11ce SQ relation: Fixed problem with string operation precedence.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3292
diff changeset
170 boolean debug = log.isDebugEnabled();
5ccd51ca11ce SQ relation: Fixed problem with string operation precedence.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3292
diff changeset
171
5ccd51ca11ce SQ relation: Fixed problem with string operation precedence.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3292
diff changeset
172 if (debug) {
5ccd51ca11ce SQ relation: Fixed problem with string operation precedence.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3292
diff changeset
173 log.debug(SQL_MEASSURE);
5ccd51ca11ce SQ relation: Fixed problem with string operation precedence.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3292
diff changeset
174 }
5ccd51ca11ce SQ relation: Fixed problem with string operation precedence.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3292
diff changeset
175
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 SQLQuery query = session.createSQLQuery(SQL_MEASSURE)
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
177 .addScalar("Q_BPEGEL", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
178 .addScalar("DATUM", StandardBasicTypes.DATE)
3981
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
179 .addScalar("GLOTRECHTEID", StandardBasicTypes.INTEGER)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
180 .addScalar("LFDNR", StandardBasicTypes.INTEGER)
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
181 .addScalar("UFERABST", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
182 .addScalar("UFERABLINKS", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
183 .addScalar("TSCHWEB", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
184 .addScalar("TSAND", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
185 .addScalar("GTRIEB", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
186 .addScalar("TGESCHIEBE", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
187 .addScalar("RSIEB01", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
188 .addScalar("RSIEB02", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
189 .addScalar("RSIEB03", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
190 .addScalar("RSIEB04", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
191 .addScalar("RSIEB05", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
192 .addScalar("RSIEB06", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
193 .addScalar("RSIEB07", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
194 .addScalar("RSIEB08", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
195 .addScalar("RSIEB09", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
196 .addScalar("RSIEB10", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
197 .addScalar("RSIEB11", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
198 .addScalar("RSIEB12", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
199 .addScalar("RSIEB13", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
200 .addScalar("RSIEB14", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
201 .addScalar("RSIEB15", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
202 .addScalar("RSIEB16", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
203 .addScalar("RSIEB17", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
204 .addScalar("RSIEB18", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
205 .addScalar("RSIEB19", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
206 .addScalar("RSIEB20", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
207 .addScalar("RSIEB21", StandardBasicTypes.DOUBLE)
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
208 .addScalar("REST", StandardBasicTypes.DOUBLE)
3981
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
209 .addScalar("SIEB01", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
210 .addScalar("SIEB02", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
211 .addScalar("SIEB03", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
212 .addScalar("SIEB04", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
213 .addScalar("SIEB05", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
214 .addScalar("SIEB06", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
215 .addScalar("SIEB07", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
216 .addScalar("SIEB08", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
217 .addScalar("SIEB09", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
218 .addScalar("SIEB10", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
219 .addScalar("SIEB11", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
220 .addScalar("SIEB12", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
221 .addScalar("SIEB13", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
222 .addScalar("SIEB14", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
223 .addScalar("SIEB15", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
224 .addScalar("SIEB16", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
225 .addScalar("SIEB17", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
226 .addScalar("SIEB18", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
227 .addScalar("SIEB19", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
228 .addScalar("SIEB20", StandardBasicTypes.DOUBLE)
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
229 .addScalar("SIEB21", StandardBasicTypes.DOUBLE);
3292
e06036fdf0c7 SQ relation: add left joins to GSIEBSATZ and SSIEBUNG
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3291
diff changeset
230
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231 query.setString("river_name", river);
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232 query.setDouble("location", location);
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233 query.setDate("from", dateRange.getFrom());
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
234 query.setDate("to", dateRange.getTo());
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 query.setResultTransformer(MeasurementResultTransformer.INSTANCE);
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
238 @SuppressWarnings("unchecked")
4006
d4e39cc5c10c S(Q) relation: Removed unused field from SQL statement.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4005
diff changeset
239 List<Measurement> measuments = (List<Measurement>)query.list();
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
240
4001
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
241 List<Measurement> same = new ArrayList<Measurement>();
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
242
3981
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
243 Integer lastLR = null;
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
244
4001
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
245 List<Measurement> accumulated = new ArrayList<Measurement>();
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
246
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
247 for (Measurement m: measuments) {
3981
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
248
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
249 Integer currentLR = (Integer)m.getData("GLOTRECHTEID");
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
250
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
251 boolean newDS = lastLR == null
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
252 || (currentLR != null && !lastLR.equals(currentLR));
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
253
4001
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
254 if (newDS && !same.isEmpty()) {
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
255 accumulated.add(accumulate(same));
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
256 same.clear();
3981
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
257 }
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
258
6bcc50e2cc7d More code for S(Q) relation.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3929
diff changeset
259 lastLR = currentLR;
3928
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
260 }
d3e2080d3ada S(Q) relation. Extract more values from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3922
diff changeset
261
4001
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
262 if (!same.isEmpty()) {
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
263 accumulated.add(accumulate(same));
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
264 }
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
265
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
266 for (Measurement m: accumulated) {
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
267 m.adjustSieves();
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
268 }
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
269
4005
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
270 return new Measurements(measuments, separateByDate(accumulated));
4001
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
271 }
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
272
4004
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
273 protected static List<Measurement> separateByDate(List<Measurement> measurements) {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
274
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
275 List<Measurement> result = new ArrayList<Measurement>();
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
276
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
277 List<Measurement> same = new ArrayList<Measurement>();
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
278
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
279 Date lastDate = null;
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
280
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
281 for (Measurement m: measurements) {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
282 Date currentDate = (Date)m.getData("DATUM");
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
283 if ((lastDate == null
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
284 || !equalDate(currentDate, lastDate))
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
285 && !same.isEmpty()
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
286 ) {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
287 result.add(processSameDate(same));
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
288 same.clear();
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
289 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
290 same.add(m);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
291 lastDate = currentDate;
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
292 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
293
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
294 if (!same.isEmpty()) {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
295 result.add(processSameDate(same));
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
296 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
297
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
298 return result;
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
299 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
300
4005
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
301
4004
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
302 protected static Measurement processSameDate(List<Measurement> measurements) {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
303 int N = measurements.size();
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
304 if (N == 1) {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
305 Measurement current = measurements.get(0);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
306 double left = current.get("UFERABLINKS");
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
307 double right = current.get("UFERABST");
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
308 current.set("EFFWIDTH", left + right);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
309 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
310 else {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
311 for (int i = 0; i < N; ++i) {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
312 Measurement current = measurements.get(i);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
313
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
314 if (i == 0) {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
315 Measurement next = measurements.get(i+1);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
316 double distCurrent = current.get("UFERABST");
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
317 double distNext = next.get("UFERABST");
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
318 current.set("EFFWIDTH", distNext - distCurrent);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
319 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
320 else if (i == N-1) {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
321 Measurement prev = measurements.get(i-1);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
322 double distCurrent = current.get("UFERABST");
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
323 double distPrev = prev.get("UFERABST");
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
324 current.set("EFFWIDTH", distCurrent - distPrev);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
325 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
326 else {
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
327 Measurement prev = measurements.get(i-1);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
328 Measurement next = measurements.get(i+1);
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
329 double distPrev = prev.get("UFERABST");
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
330 double distNext = next.get("UFERABST");
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
331 current.set("EFFWIDTH", 0.5*(distNext - distPrev));
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
332 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
333 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
334 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
335
4005
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
336 double sumSandF = 0d;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
337 double sumCoarseF = 0d;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
338 double sumGravelF = 0d;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
339 double sumNorm = 0d;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
340
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
341 for (Measurement m: measurements) {
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
342 SieveArray sa = m.getSieveArray();
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
343 double sandF = sa.sandNormFraction();
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
344 double coarseF = sa.coarseNormFraction();
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
345 double gravelF = sa.gravelNormFraction();
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
346 double effWidth = m.get("EFFWIDTH");
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
347 double gt = m.get("GTRIEB");
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
348 double scale = effWidth*gt;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
349 sumSandF += scale*sandF;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
350 sumCoarseF += scale*coarseF;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
351 sumGravelF += scale*gravelF;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
352 sumNorm += scale;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
353 }
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
354
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
355 Map<String, Object> data =
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
356 new HashMap<String, Object>(measurements.get(0).getData());
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
357
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
358 Measurement m = new Measurement(data, Collections.<Sieve>emptyList());
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
359
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
360 sumNorm = 1d/sumNorm;
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
361
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
362 m.set("BL_S", sumNorm*sumSandF);
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
363 m.set("BL_G", sumNorm*sumGravelF);
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
364 m.set("BL_C", sumNorm*sumCoarseF);
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
365
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
366 return m;
4004
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
367 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
368
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
369
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
370 private static final boolean equalDate(Date a, Date b) {
4005
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
371 Calendar ca = Calendar.getInstance();
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
372 Calendar cb = Calendar.getInstance();
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
373 ca.setTime(a);
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
374 cb.setTime(b);
4006
d4e39cc5c10c S(Q) relation: Removed unused field from SQL statement.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4005
diff changeset
375 return ca.get(Calendar.YEAR) == cb.get(Calendar.YEAR)
d4e39cc5c10c S(Q) relation: Removed unused field from SQL statement.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4005
diff changeset
376 && ca.get(Calendar.MONTH) == cb.get(Calendar.MONTH)
4005
22abdc45869c Calculate S(Q) fractions
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4004
diff changeset
377 && ca.get(Calendar.DAY_OF_MONTH) == cb.get(Calendar.DAY_OF_MONTH);
4004
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
378 }
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
379
3b79e8afca7e S(Q) calculate effective width
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4001
diff changeset
380
4001
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
381 protected static Measurement accumulate(List<Measurement> measuments) {
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
382
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
383 int N = measuments.size();
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
384 if (N == 1) {
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
385 return measuments.get(0);
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
386 }
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
387
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
388 TreeMap<Double, double []> diameters =
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
389 new TreeMap<Double, double []>(Sieve.DIAMETER_CMP);
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
390
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
391 for (Measurement m: measuments) {
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
392 for (Sieve s: m.getSieves()) {
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
393 Double key = s.getDiameter();
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
394 double [] sum = diameters.get(key);
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
395 if (sum == null) {
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
396 sum = new double[1];
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
397 diameters.put(key, sum);
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
398 }
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
399 sum[0] += s.getLoad();
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
400 }
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
401 }
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
402 List<Sieve> accumulatedSieves = new ArrayList<Sieve>(diameters.size());
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
403 for (Map.Entry<Double, double []> entry: diameters.entrySet()) {
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
404 accumulatedSieves.add(
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
405 new Sieve(entry.getKey(),
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
406 entry.getValue()[0]/N));
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
407 }
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
408
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
409 Map<String, Object> data =
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
410 new HashMap<String, Object>(measuments.get(0).getData());
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
411
ab3a4ad82ae1 S(Q) accumulated same diameter meassurements per bank distance.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3992
diff changeset
412 return new Measurement(data, accumulatedSieves);
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
413 }
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
414
3290
36f3b53d5cfc SQ relation: Added infrastructure to extract fractions from measurments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3289
diff changeset
415 public static Measurements getMeasurements(
3289
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
416 String river,
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
417 double location,
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
418 DateRange dateRange
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
419 ) {
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
420 Session session = SedDBSessionHolder.HOLDER.get();
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
421 try {
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
422 return load(session, river, location, dateRange);
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
423 }
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
424 finally {
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
425 session.close();
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
426 }
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
427 }
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
428 }
ec9aab93f292 SQ: First peek into fetching relevant data from SedDB
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
429 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org