Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java @ 2230:59af81364eb1
Improved the 'historical discharge' calculation: implemented findValueForW().
flys-artifacts/trunk@3872 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 01 Feb 2012 15:41:11 +0000 |
parents | 6b0ae0f2cae6 |
children | 899ca89f497e |
comparison
equal
deleted
inserted
replaced
2229:9dc81827b187 | 2230:59af81364eb1 |
---|---|
122 } | 122 } |
123 | 123 |
124 // TODO: Filter by time interval | 124 // TODO: Filter by time interval |
125 DischargeTable table = tables.get(0); | 125 DischargeTable table = tables.get(0); |
126 | 126 |
127 List<DischargeTableValue> dtvs = | |
128 table.getDischargeTableValues(); | |
129 | |
130 final double [][] vs = new double[2][dtvs.size()]; | |
131 | |
132 boolean qSorted = true; | 127 boolean qSorted = true; |
133 | 128 |
134 double lastQ = -Double.MAX_VALUE; | 129 final double[][] vs = |
135 | 130 loadDischargeTableValues(table, scale, qSorted); |
136 int idx = 0; | |
137 for (DischargeTableValue dtv: dtvs) { | |
138 double q = dtv.getQ().doubleValue(); | |
139 vs[0][idx] = q * scale; | |
140 vs[1][idx] = dtv.getW().doubleValue() * scale; | |
141 ++idx; | |
142 | |
143 if (qSorted && lastQ > q) { | |
144 qSorted = false; | |
145 } | |
146 lastQ = q; | |
147 } | |
148 | 131 |
149 if (!qSorted) { | 132 if (!qSorted) { |
150 log.debug("need to sort by q values"); | 133 log.debug("need to sort by q values"); |
151 // TODO: Do this db level. | 134 // TODO: Do this db level. |
152 // XXX: This is so ugly :-( | 135 // XXX: This is so ugly :-( |
180 } | 163 } |
181 | 164 |
182 return values; | 165 return values; |
183 } | 166 } |
184 | 167 |
168 | |
169 /** | |
170 * @param table The discharge table | |
171 * @param scale The scale factor to adjust W and Q values. | |
172 * @param qSorted Boolean flag that is used to evaluate if the values should | |
173 * be sorted. | |
174 * | |
175 * @return the values of a discharge table. | |
176 */ | |
177 public static double[][] loadDischargeTableValues( | |
178 DischargeTable table, | |
179 double scale, | |
180 boolean qSorted | |
181 ) { | |
182 List<DischargeTableValue> dtvs = table.getDischargeTableValues(); | |
183 | |
184 final double [][] vs = new double[2][dtvs.size()]; | |
185 | |
186 double lastQ = -Double.MAX_VALUE; | |
187 | |
188 int idx = 0; | |
189 for (DischargeTableValue dtv: dtvs) { | |
190 double q = dtv.getQ().doubleValue(); | |
191 vs[0][idx] = q * scale; | |
192 vs[1][idx] = dtv.getW().doubleValue() * scale; | |
193 ++idx; | |
194 | |
195 if (qSorted && lastQ > q) { | |
196 qSorted = false; | |
197 } | |
198 lastQ = q; | |
199 } | |
200 | |
201 return vs; | |
202 } | |
203 | |
204 | |
185 public static double getQForW(double [][] values, double w) { | 205 public static double getQForW(double [][] values, double w) { |
186 | 206 |
187 boolean debug = log.isDebugEnabled(); | 207 boolean debug = log.isDebugEnabled(); |
188 | 208 |
189 if (debug) { | 209 if (debug) { |