Mercurial > dive4elements > river
changeset 3449:fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
flys-artifacts/trunk@5112 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 23 Jul 2012 15:24:14 +0000 |
parents | 700d09ca5dc8 |
children | 22790758b132 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingCalculation.java |
diffstat | 4 files changed, 126 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Jul 23 15:15:31 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Jul 23 15:24:14 2012 +0000 @@ -1,3 +1,14 @@ +2012-07-23 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: + Broke over long line. + + * src/main/java/de/intevation/flys/artifacts/model/Segment.java: + Added some getters. + + * src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingCalculation.java: + Calculated the Q -> Ws. TODO: Produce result. + 2012-07-23 Felix Wolfsteller <felix.wolfsteller@intevation.de> * src/main/resources/messages.properties,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Mon Jul 23 15:15:31 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Mon Jul 23 15:24:14 2012 +0000 @@ -135,7 +135,9 @@ { logger.debug("WINFOArtifact.getWaterlevelData"); - if (getDataAsString("calculation_mode").equals("calc.discharge.longitudinal.section")) { + if (getDataAsString("calculation_mode") + .equals("calc.discharge.longitudinal.section") + ) { return getDischargeLongitudinalSectionData(); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java Mon Jul 23 15:15:31 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java Mon Jul 23 15:24:14 2012 +0000 @@ -55,6 +55,12 @@ return from < to; } + public boolean inside(double km) { + return from < to + ? km >= from && km <= to + : km >= to && km <= from; + } + @Override public String toString() { StringBuilder sb = new StringBuilder("Segment: ["); @@ -80,6 +86,10 @@ : null; } + public double [] getBackup() { + return backup; + } + public double getFrom() { return from; } @@ -100,6 +110,10 @@ return values; } + public int numValues() { + return values.length; + } + public void setReferencePoint(double referencePoint) { this.referencePoint = referencePoint; }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingCalculation.java Mon Jul 23 15:15:31 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingCalculation.java Mon Jul 23 15:24:14 2012 +0000 @@ -6,7 +6,12 @@ import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.FixingsOverview; +import de.intevation.flys.artifacts.model.RiverFactory; import de.intevation.flys.artifacts.model.Segment; +import de.intevation.flys.artifacts.model.WQKms; +import de.intevation.flys.artifacts.model.Parameters; + +import de.intevation.flys.model.River; import java.util.List; @@ -40,9 +45,19 @@ addProblem("fix.realize.missing.segments"); } + River r = RiverFactory.getRiver(river); + + if (r == null) { + // TODO: i18n + addProblem("fix.no.such.river"); + } + if (!hasProblems()) { this.isQ = isQ; this.segments = segments; + + // Convert from W to Q + Segment.setReferencePointConvertQ(segments, r, isQ, this); } } @@ -51,8 +66,90 @@ FixingsOverview overview, Function func ) { - // TODO: Implement me! + FitResult fitResult = doFitting(overview, func); + + if (fitResult == null) { + return new CalculationResult(this); + } + + Segment segment = segments.get(0); + int numResults = segment.numValues(); + + WQKms [] results = new WQKms[numResults]; + for (int i = 0; i < results.length; ++i) { + results[i] = new WQKms(); + } + + Parameters parameters = fitResult.getParameters(); + + int kmIndex = parameters.columnIndex("km"); + int [] parameterIndices = + parameters.columnIndices(func.getParameterNames()); + + double [] parameterValues = new double[parameterIndices.length]; + + for (int row = 0, R = parameters.size(); row < R; ++row) { + double km = parameters.get(row, kmIndex); + + if (!segment.inside(km)) { + Segment nextSeg = null; + for (Segment seg: segments) { + if (seg.inside(km)) { + nextSeg = seg; + break; + } + } + if (nextSeg == null) { + // TODO: i18n + addProblem(km, "fix.cannot.find.segment"); + continue; + } + segment = nextSeg; + } + + parameters.get(row, parameterIndices, parameterValues); + + de.intevation.flys.artifacts.math.Function instance = + func.instantiate(parameterValues); + + double [] values = segment.getValues(); + for (int i = 0; i < numResults; ++i) { + double q = values[i]; + double w = instance.value(q); + + if (Double.isNaN(w)) { + // TODO: i18n + addProblem(km, "fix.cannot.calculate.function", q); + } + else { + results[i].add(w, q, km); + } + } + } + + // name the curves + for (int i = 0; i < results.length; ++i) { + results[i].setName(createName(i)); + } + return new CalculationResult(this); } + + protected String createName(int index) { + // TODO: i18n + StringBuilder sb = new StringBuilder(isQ ? "Q" : "W"); + sb.append(" benutzerdefiniert ("); + for (int i = 0, N = segments.size(); i < N; ++i) { + if (i > 0) { + sb.append("; "); + } + Segment segment = segments.get(i); + double [] backup = segment.getBackup(); + double [] values = segment.getValues(); + sb.append((backup != null ? backup : values)[index]); + } + sb.append(')'); + return sb.toString(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :