Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeTimerangeState.java @ 5395:5a55c5372fe1
Added new state for outlier test method. Methods are 'grubbs' or 'std-dev'.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 25 Mar 2013 12:35:08 +0100 |
parents | f6c73ee1b7f1 |
children | 12766ab27a36 |
rev | line source |
---|---|
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.states; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.Calendar; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
3745
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
7 import org.hibernate.SQLQuery; |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.hibernate.Session; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.hibernate.type.StandardBasicTypes; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
3745
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
11 import de.intevation.flys.artifacts.FLYSArtifact; |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.flys.backend.SessionHolder; |
3745
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
13 import de.intevation.flys.model.Gauge; |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.utils.FLYSUtils; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 /** |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 */ |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 public class GaugeTimerangeState extends IntRangeState { |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 private static final Logger logger = |
3745
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
23 Logger.getLogger(GaugeTimerangeState.class); |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
4132
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
26 protected long[] getLowerUpper(FLYSArtifact flys) { |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 Gauge gauge = FLYSUtils.getReferenceGauge(flys); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 if (gauge == null) { |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 logger.warn("No reference gauge specified!"); |
4132
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
31 return new long[] { 0, 0 }; |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 } |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 Session session = SessionHolder.HOLDER.get(); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 SQLQuery query = session.createSQLQuery( |
3745
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
37 "SELECT min(start_time) as min, max(stop_time) as max " + |
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
38 "FROM time_intervals WHERE id in " + |
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
39 "(SELECT time_interval_id FROM discharge_tables " + |
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
40 "WHERE gauge_id =:gid)"); |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 query.addScalar("min", StandardBasicTypes.CALENDAR); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 query.addScalar("max", StandardBasicTypes.CALENDAR); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 query.setInteger("gid", gauge.getId()); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 |
3745
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
47 List<?> results = query.list(); |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 if (results != null) { |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 Object[] res = (Object[]) results.get(0); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 Calendar lo = (Calendar) res[0]; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 Calendar up = (Calendar) res[1]; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 |
3745
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
55 if (lo != null && up != null) { |
4132
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
56 return new long[] { lo.getTimeInMillis(), up.getTimeInMillis() }; |
3745
e86cd5176678
Check to prevent NPE
Christian Lins <christian.lins@intevation.de>
parents:
2276
diff
changeset
|
57 } |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 } |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 logger.warn("Could not determine time range for gauge: " + gauge); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 return null; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 } |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 @Override |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 protected Object getLower(FLYSArtifact flys) { |
4132
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
68 long[] lowerUpper = getLowerUpper(flys); |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 return lowerUpper != null ? lowerUpper[0] : 0; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 } |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 @Override |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 protected Object getUpper(FLYSArtifact flys) { |
4132
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
76 long[] lowerUpper = getLowerUpper(flys); |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 return lowerUpper != null ? lowerUpper[1] : 0; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 } |
2276
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2191
diff
changeset
|
80 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2191
diff
changeset
|
81 |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2191
diff
changeset
|
82 @Override |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2191
diff
changeset
|
83 protected String getUIProvider() { |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2191
diff
changeset
|
84 return "gaugetimerange"; |
2966787b5188
Added service for discharge infos at a specific gauge.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
2191
diff
changeset
|
85 } |
4132
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
86 |
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
87 @Override |
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
88 protected String getType() { |
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
89 return "longrange"; |
f6c73ee1b7f1
#543 Validate date range in client gauge time range selection state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3745
diff
changeset
|
90 } |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 } |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |