Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixRealizingCalculation.java @ 4357:11cf29eb002c
FacetTypes: New type: exreme_wq_curve_base (for the Stuetz-Q-Poits).
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 02 Nov 2012 11:58:11 +0100 |
parents | d2ae58f6730d |
children | d76705b68e73 |
line wrap: on
line source
package de.intevation.flys.artifacts.model.fixings; import de.intevation.flys.artifacts.access.FixRealizingAccess; import de.intevation.flys.artifacts.math.fitting.Function; 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; import org.apache.log4j.Logger; public class FixRealizingCalculation extends FixCalculation { private static Logger log = Logger.getLogger(FixRealizingCalculation.class); protected boolean isQ; protected List<Segment> segments; public FixRealizingCalculation() { } public FixRealizingCalculation(FixRealizingAccess access) { super(access); Boolean isQ = access.isQ(); List<Segment> segments = access.getSegments(); if (isQ == null) { // TODO: i18n addProblem("fix.realize.missing.is.q"); } if (segments == null || segments.isEmpty()) { // TODO: i18n 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); } } @Override protected CalculationResult innerCalculate( FixingsOverview overview, Function func ) { ColumnCache cc = new ColumnCache(); FitResult fitResult = doFitting(overview, cc, 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)); } FixRealizingResult frr = new FixRealizingResult( parameters, fitResult.getReferenced(), fitResult.getOutliers(), results); return new CalculationResult(frr, 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 :