# HG changeset patch # User Sascha L. Teichmann # Date 1307697567 0 # Node ID d5f9ba1d055ffca05990ab0c4dc2665b21915005 # Parent b22f21b173a704ca767c0b854ab2390bfb2ba199 Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism. flys-artifacts/trunk@2098 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b22f21b173a7 -r d5f9ba1d055f flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Jun 09 10:48:13 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Jun 10 09:19:27 2011 +0000 @@ -1,3 +1,16 @@ +2011-06-10 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/model/Calculation.java: + New. Base class for calculations. Used to collect problems occuring + during calculation. + + * src/main/java/de/intevation/flys/artifacts/model/Calculation4.java: + Extends Calculation now. Looped through the problem reports to + base class. + + * src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java: + Looped through the problem reports. + 2011-06-09 Ingo Weinzierl * src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java: diff -r b22f21b173a7 -r d5f9ba1d055f flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java Thu Jun 09 10:48:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java Fri Jun 10 09:19:27 2011 +0000 @@ -15,6 +15,8 @@ import org.apache.log4j.Logger; +import de.intevation.flys.artifacts.model.Calculation; + public class BackJumpCorrector implements Serializable { @@ -40,8 +42,11 @@ return corrected; } - public boolean doCorrection(double [] km, double [] ws) { - + public boolean doCorrection( + double [] km, + double [] ws, + Calculation errors + ) { boolean wsUp = isIncreasing(ws); if (wsUp) { @@ -62,7 +67,7 @@ log.debug("BackJumpCorrector.doCorrection ------- leave"); } - boolean hasBackJumps = doCorrectionClean(km, ws); + boolean hasBackJumps = doCorrectionClean(km, ws, errors); if (hasBackJumps && wsUp) { // mirror back @@ -72,7 +77,11 @@ return hasBackJumps; } - protected boolean doCorrectionClean(double [] km, double [] ws) { + protected boolean doCorrectionClean( + double [] km, + double [] ws, + Calculation errors + ) { int N = km.length; if (N != ws.length) { @@ -201,6 +210,8 @@ spline = interpolator.interpolate(x, y); } catch (MathIllegalArgumentException miae) { + // TODO: I18N + errors.addProblem("creating spline interpolation failed."); log.error(miae); continue; } @@ -226,6 +237,8 @@ } } catch (ArgumentOutsideDomainException aode) { + // TODO: I18N + errors.addProblem("spline interpolation failed."); log.error("spline interpolation failed", aode); } } // for all km diff -r b22f21b173a7 -r d5f9ba1d055f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation.java Fri Jun 10 09:19:27 2011 +0000 @@ -0,0 +1,79 @@ +package de.intevation.flys.artifacts.model; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import java.util.List; +import java.util.ArrayList; + +public class Calculation +{ + public static class Problem { + + protected Double km; + protected String msg; + + public Problem() { + } + + public Problem(String msg) { + this.msg = msg; + } + + public Problem(double km, String msg) { + this.km = km; + this.msg = msg; + } + + public Element toXML(Document document) { + Element problem = document.createElement("problem"); + if (km != null) { + problem.setAttribute("km", String.valueOf(km)); + } + problem.setTextContent(msg); + return problem; + } + } // class Problem + + protected List problems; + + public Calculation() { + } + + protected List checkProblems() { + if (problems == null) { + problems = new ArrayList(); + } + return problems; + } + + public void addProblem(String msg) { + checkProblems().add(new Problem(msg)); + } + + public void addProblem(double km, String msg) { + checkProblems().add(new Problem(km, msg)); + } + + public boolean hasProblems() { + return problems != null && !problems.isEmpty(); + } + + public List getProblems() { + return problems; + } + + public void toXML(Document document) { + + Element root = document.createElement("problems"); + + if (hasProblems()) { + for (Problem problem: problems) { + root.appendChild(problem.toXML(document)); + } + } + + document.appendChild(root); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r b22f21b173a7 -r d5f9ba1d055f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java Thu Jun 09 10:48:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java Fri Jun 10 09:19:27 2011 +0000 @@ -20,6 +20,7 @@ import org.apache.log4j.Logger; public class Calculation4 +extends Calculation { private static Logger logger = Logger.getLogger(Calculation4.class); @@ -100,6 +101,8 @@ if (segments.isEmpty()) { logger.debug("no segments found"); + // TODO: I18N + addProblem("no segments found"); return new WQKms[0]; } @@ -107,6 +110,8 @@ if (numResults < 1) { logger.debug("no values given"); + // TODO: I18N + addProblem("no values given"); return new WQKms[0]; } @@ -213,7 +218,8 @@ anchor.values[i]); if ((qPositions[i] = qi) == null) { - // TODO: error report + // TODO: I18N + addProblem(pos, "cannot find q = " + anchor.values[i]); functions[i] = Identity.IDENTITY; } else { @@ -249,7 +255,8 @@ results[i].add(out[0], out[1], pos); } else { - // TODO: error report + // TODO: I18N + addProblem(pos, "cannot interpolate w/q"); } } } @@ -261,10 +268,9 @@ double [] ws = results[i].getWs(); double [] kms = results[i].getKms(); - if (bjc.doCorrection(kms, ws)) { + if (bjc.doCorrection(kms, ws, this)) { results[i] = new WQCKms(results[i], bjc.getCorrected()); } - // TODO: error report } // name the curves @@ -276,7 +282,7 @@ } protected String createName(int index) { - // TODO: i18n + // TODO: I18N StringBuilder sb = new StringBuilder(isQ ? "Q" : "W"); sb.append(" benutzerdefiniert ("); for (int i = 0, N = segments.size(); i < N; ++i) {