Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java @ 2992:0abdede5a0b8
FixA: Added facet to return delta w/t as CSV
flys-artifacts/trunk@4543 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 28 May 2012 18:35:01 +0000 |
parents | 063b784b60b4 |
children | 70469e3d34b9 |
comparison
equal
deleted
inserted
replaced
2991:fcb2166b8e0d | 2992:0abdede5a0b8 |
---|---|
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 public CalculationResult calculate() { | 126 public CalculationResult calculate() { |
127 | 127 |
128 boolean debug = log.isDebugEnabled(); | |
129 | |
128 FixingsOverview overview = | 130 FixingsOverview overview = |
129 FixingsOverviewFactory.getOverview(river); | 131 FixingsOverviewFactory.getOverview(river); |
130 | 132 |
131 if (overview == null) { | 133 if (overview == null) { |
132 addProblem("fix.no.overview.available"); | 134 addProblem("fix.no.overview.available"); |
171 // TODO: i18n | 173 // TODO: i18n |
172 addProblem("fix.too.less.data.columns"); | 174 addProblem("fix.too.less.data.columns"); |
173 return new CalculationResult(this); | 175 return new CalculationResult(this); |
174 } | 176 } |
175 | 177 |
176 double [] kms = DoubleUtil.explode(from, to, step); | 178 double [] kms = DoubleUtil.explode(from, to, step / 1000.0); |
177 | 179 |
178 double [] ws = new double[dataColumns.size()]; | 180 double [] ws = new double[dataColumns.size()]; |
179 double [] qs = new double[ws.length]; | 181 double [] qs = new double[ws.length]; |
180 | 182 |
181 String [] parameterNames = func.getParameterNames(); | 183 String [] parameterNames = func.getParameterNames(); |
182 | 184 |
183 Parameters results = | 185 Parameters results = |
184 new Parameters(createColumnNames(parameterNames)); | 186 new Parameters(createColumnNames(parameterNames)); |
185 | 187 |
186 boolean invalid = false; | 188 boolean invalid = false; |
189 | |
190 if (debug) { | |
191 log.debug("number of kms: " + kms.length); | |
192 } | |
193 | |
194 int numFailed = 0; | |
187 | 195 |
188 for (int i = 0; i < kms.length; ++i) { | 196 for (int i = 0; i < kms.length; ++i) { |
189 double km = kms[i]; | 197 double km = kms[i]; |
190 | 198 |
191 for (int j = 0; j < ws.length; ++j) { | 199 for (int j = 0; j < ws.length; ++j) { |
196 } | 204 } |
197 | 205 |
198 // TODO: Do preprocessing here! | 206 // TODO: Do preprocessing here! |
199 double [] parameters = fit(func, km, ws, qs); | 207 double [] parameters = fit(func, km, ws, qs); |
200 if (parameters == null) { // Problems are reported already. | 208 if (parameters == null) { // Problems are reported already. |
209 ++numFailed; | |
201 continue; | 210 continue; |
202 } | 211 } |
203 | 212 |
204 int row = results.newRow(); | 213 int row = results.newRow(); |
205 | 214 |
211 else { | 220 else { |
212 results.set(row, parameterNames[j], parameters[j]); | 221 results.set(row, parameterNames[j], parameters[j]); |
213 } | 222 } |
214 } | 223 } |
215 // TODO: Calculate statistics, too! | 224 // TODO: Calculate statistics, too! |
225 } | |
226 | |
227 if (debug) { | |
228 log.debug("success: " + (kms.length - numFailed)); | |
229 log.debug("failed: " + numFailed); | |
216 } | 230 } |
217 | 231 |
218 if (invalid) { | 232 if (invalid) { |
219 // TODO: i18n | 233 // TODO: i18n |
220 addProblem("fix.invalid.values"); | 234 addProblem("fix.invalid.values"); |
406 | 420 |
407 try { | 421 try { |
408 return cf.fit(function, function.getInitialGuess()); | 422 return cf.fit(function, function.getInitialGuess()); |
409 } | 423 } |
410 catch (MathException me) { | 424 catch (MathException me) { |
425 log.warn(me, me); | |
411 addProblem(km, "fix.fitting.failed"); | 426 addProblem(km, "fix.fitting.failed"); |
412 } | 427 } |
413 | 428 |
414 return null; | 429 return null; |
415 } | 430 } |