Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java @ 3142:9aed2e4de3ca
FixA: Moved GaugeFinder into top level class.
flys-artifacts/trunk@4750 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 21 Jun 2012 15:50:58 +0000 |
parents | 3582e87e9171 |
children | 29022c93027d |
comparison
equal
deleted
inserted
replaced
3141:3582e87e9171 | 3142:9aed2e4de3ca |
---|---|
45 "FROM gauges g" + | 45 "FROM gauges g" + |
46 " JOIN ranges r ON g.range_id = r.id " + | 46 " JOIN ranges r ON g.range_id = r.id " + |
47 "WHERE" + | 47 "WHERE" + |
48 " g.river_id = :river_id " + | 48 " g.river_id = :river_id " + |
49 "ORDER BY r.a"; | 49 "ORDER BY r.a"; |
50 | |
51 public static final String SQL_DISCHARGE_SECTORS = | |
52 "SELECT" + | |
53 " g.id AS gauge_id," + | |
54 " nmv.name AS name," + | |
55 " CAST(mv.value AS NUMERIC(38,2)) AS value " + | |
56 "FROM gauges g" + | |
57 " JOIN main_values mv ON g.id = mv.gauge_id" + | |
58 " JOIN named_main_values nmv ON nmv.id = mv.named_value_id" + | |
59 " JOIN main_value_types mvt ON nmv.type_id = mvt.id " + | |
60 "WHERE" + | |
61 " mvt.name = 'Q' AND (" + | |
62 " nmv.name = 'MNQ' OR" + | |
63 " nmv.name LIKE 'MNQ(%' OR" + | |
64 " nmv.name = 'MQ' OR" + | |
65 " nmv.name LIKE 'MQ(%' OR" + | |
66 " nmv.name = 'MHQ' OR" + | |
67 " nmv.name LIKE 'MHQ(%' OR" + | |
68 " nmv.name = 'HQ5' OR" + | |
69 " nmv.name LIKE 'HQ5(%') AND" + | |
70 " g.river_id = :river_id " + | |
71 "ORDER BY" + | |
72 " g.id"; | |
73 | 50 |
74 public static final String SQL_FIXINGS = | 51 public static final String SQL_FIXINGS = |
75 "SELECT" + | 52 "SELECT" + |
76 " id AS wst_id," + | 53 " id AS wst_id," + |
77 " description " + | 54 " description " + |
110 " wst_column_values " + | 87 " wst_column_values " + |
111 "WHERE" + | 88 "WHERE" + |
112 " wst_column_id = :column_id"; | 89 " wst_column_id = :column_id"; |
113 | 90 |
114 | 91 |
115 public static class GaugeFinder { | |
116 | |
117 protected List<GaugeRange> gauges; | |
118 protected boolean isKmUp; | |
119 | |
120 public GaugeFinder(List<GaugeRange> gauges) { | |
121 this(gauges, true); | |
122 } | |
123 | |
124 public GaugeFinder( | |
125 List<GaugeRange> gauges, | |
126 boolean isKmUp | |
127 ) { | |
128 this.gauges = gauges; | |
129 this.isKmUp = isKmUp; | |
130 } | |
131 | |
132 public boolean getIsKmUp() { | |
133 return isKmUp; | |
134 } | |
135 | |
136 public void setIsKmUp(boolean isKmUp) { | |
137 this.isKmUp = isKmUp; | |
138 } | |
139 | |
140 public GaugeRange find(Range range) { | |
141 double km = isKmUp ? range.start : range.end; | |
142 for (GaugeRange gauge: gauges) { | |
143 if (gauge.inside(km)) { | |
144 return gauge; | |
145 } | |
146 } | |
147 return null; | |
148 } | |
149 | |
150 public GaugeRange find(int gaugeId) { | |
151 for (GaugeRange gauge: gauges) { | |
152 if (gauge.gaugeId == gaugeId) { | |
153 return gauge; | |
154 } | |
155 } | |
156 return null; | |
157 } | |
158 | |
159 public boolean loadDischargeSectors(Session session, int riverId) { | |
160 | |
161 SQLQuery query = session.createSQLQuery(SQL_DISCHARGE_SECTORS) | |
162 .addScalar("gauge_id", StandardBasicTypes.INTEGER) | |
163 .addScalar("name", StandardBasicTypes.STRING) | |
164 .addScalar("value", StandardBasicTypes.DOUBLE); | |
165 | |
166 query.setInteger("river_id", riverId); | |
167 | |
168 List<Object []> list = query.list(); | |
169 | |
170 if (list.isEmpty()) { | |
171 log.warn("River " + riverId + " has no discharge sectors."); | |
172 return false; | |
173 } | |
174 | |
175 GaugeRange gauge = null; | |
176 | |
177 for (Object [] row: list) { | |
178 int gaugeId = (Integer)row[0]; | |
179 String label = (String) row[1]; | |
180 Double value = (Double) row[2]; | |
181 | |
182 if (gauge == null || gauge.gaugeId != gaugeId) { | |
183 if ((gauge = find(gaugeId)) == null) { | |
184 log.warn("Cannot find gauge for id " + gaugeId + "."); | |
185 continue; | |
186 } | |
187 } | |
188 | |
189 gauge.addMainValue(label, value); | |
190 } | |
191 | |
192 for (GaugeRange g: gauges) { | |
193 g.buildClasses(); | |
194 } | |
195 | |
196 return true; | |
197 } | |
198 } // class GaugeFinder | |
199 | 92 |
200 public static class QRange extends Range { | 93 public static class QRange extends Range { |
201 | 94 |
202 protected double q; | 95 protected double q; |
203 | 96 |