# HG changeset patch # User gernotbelger # Date 1528287388 -7200 # Node ID f61bc0c63188ba5ce2ce5467d56f7810b1efbeac # Parent 28eec75415d88b7edd2caa79f96db77248f8f762 WQSelect can now handle distance-only data diff -r 28eec75415d8 -r f61bc0c63188 artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java Wed Jun 06 14:15:58 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java Wed Jun 06 14:16:28 2018 +0200 @@ -20,6 +20,7 @@ import org.dive4elements.river.artifacts.access.Calculation4Access; import org.dive4elements.river.artifacts.access.RangeAccess; +import org.dive4elements.river.artifacts.access.RiverAccess; import org.dive4elements.river.artifacts.access.ComputationRangeAccess; import org.dive4elements.river.artifacts.geom.Lines; @@ -42,8 +43,6 @@ import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; -import org.dive4elements.river.artifacts.states.LocationDistanceSelect; - import org.dive4elements.river.model.DischargeTable; import org.dive4elements.river.model.FastCrossSectionLine; import org.dive4elements.river.model.Gauge; @@ -174,7 +173,7 @@ return this.getWaterlevelData(null); } - protected CalculationResult getDischargeLongitudinalSectionData() { + private CalculationResult getDischargeLongitudinalSectionData() { // TODO: This caluclation should be cached as it is quite expensive. return new Calculation4(new Calculation4Access(this)).calculate(); } @@ -191,44 +190,51 @@ String calculationMode = getDataAsString("calculation_mode"); // If this WINFO-Artifact has a calculation trait. - if (calculationMode != null) { - if (calculationMode.equals("calc.discharge.longitudinal.section") - ) { + if (calculationMode != null) + { + if (calculationMode.equals("calc.discharge.longitudinal.section")) return getDischargeLongitudinalSectionData(); - } - else if (calculationMode.equals("calc.extreme.curve")) { - return (CalculationResult) - this.compute(context, ComputeType.ADVANCE, false); - } - else if (calculationMode.equals("calc.w.differences")) { - return (CalculationResult) - this.compute(context, ComputeType.ADVANCE, true); - } - else { - log.warn("Unhandled calculation_mode " + calculationMode); - } + + if (calculationMode.equals("calc.extreme.curve")) + return (CalculationResult)this.compute(context, ComputeType.ADVANCE, false); + + if (calculationMode.equals("calc.w.differences")) + return (CalculationResult)this.compute(context, ComputeType.ADVANCE, true); + + log.warn("Unhandled calculation_mode " + calculationMode); } - + // Otherwise get it from parameterization. - River river = RiverUtils.getRiver(this); - if (river == null) { + // TODO: wrong comment: now always a waterlevle computation is executed; actually there is a calc_mode for that, why dont check? + return computeWaterlevelData(); + } + + /** Execu5tes the calculation of 'waterlevel', fetches all input data from this artifact */ + private CalculationResult computeWaterlevelData() { + final double[] kms = new ComputationRangeAccess(this).getKms(); + if (kms == null) + return error(new WQKms[0], "no.kms.selected"); + + return computeWaterlevelData(kms); + } + + /** + * Execu5tes the calculation of 'waterlevel'. + * Allows to override the stations for which the calculation is done. All other inputs are fetched from this artifact. + */ + public final CalculationResult computeWaterlevelData(final double kms[]) { + + final River river = new RiverAccess(this).getRiver(); + if (river == null) return error(new WQKms[0], "no.river.selected"); - } - - double[] kms = getKms(); - if (kms == null) { - return error(new WQKms[0], "no.kms.selected"); - } double[] qs = getQs(); double[] ws = null; - boolean qSel = true; Calculation report = new Calculation(); if (qs == null) { log.debug("Determine Q values based on a set of W values."); - qSel = false; ws = getWs(); double [][] qws = getQsForWs(ws, report); if (qws == null || qws.length == 0) { @@ -273,10 +279,9 @@ "reference gauge: " + gauge.getName() + " (km " + refKm + ")"); } - return computeWaterlevelData(kms, qs, ws, wst, refKm, report); + return computeWaterlevelData(kms, qs, ws, wst, refKm, report); } - /** * Computes the data of a waterlevel computation based on the interpolation * in WstValueTable. @@ -287,7 +292,7 @@ * * @return an array of data triples that consist of W, Q and Kms. */ - public static CalculationResult computeWaterlevelData( + private static CalculationResult computeWaterlevelData( double [] kms, double [] qs, double [] ws, @@ -349,7 +354,7 @@ * * @return the computed data. */ - public static CalculationResult computeDurationCurveData( + private static CalculationResult computeDurationCurveData( Gauge gauge, WstValueTable wst, double location) @@ -409,7 +414,7 @@ * @return an object that contains tuples of W/Q values at the specified * location. */ - public static CalculationResult computeDischargeCurveData( + private static CalculationResult computeDischargeCurveData( WstValueTable wst, double location) { @@ -544,7 +549,7 @@ /** * Get corrected waterline against surface/profile. */ - public Lines.LineData waterLineC(int idx, FastCrossSectionLine csl) { + private Lines.LineData waterLineC(int idx, FastCrossSectionLine csl) { List points = csl.getPoints(); WQKms[] wqckms = (WQKms[]) @@ -665,7 +670,7 @@ * * @return an array of Q values. */ - public double [][] getQsForWs(double[] ws, Calculation report) { + private double [][] getQsForWs(double[] ws, Calculation report) { if (ws == null) { log.error("getQsForWs: ws == null"); @@ -803,19 +808,6 @@ /** - * Returns the selected Kms. - * - * @return the selected kms. - */ - public double[] getKms() { - return new ComputationRangeAccess(this).getKms(); - } - - public double [] getFromToStep() { - return new ComputationRangeAccess(this).getFromToStep(); - } - - /** * This method returns the Q values. * * @return the selected Q values or null, if no Q values are selected. diff -r 28eec75415d8 -r f61bc0c63188 artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java Wed Jun 06 14:15:58 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java Wed Jun 06 14:16:28 2018 +0200 @@ -32,6 +32,7 @@ import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.access.RangeAccess; +import org.dive4elements.river.artifacts.access.RangeAccess.KM_MODE; import org.dive4elements.river.artifacts.access.ComputationRangeAccess; import org.dive4elements.river.artifacts.model.WstFactory; import org.dive4elements.river.artifacts.model.WstValueTable; @@ -432,16 +433,10 @@ double[] minmaxW = null; if(valueTable != null) { - double[] km = null; - if(access.isRange()) { - km = access.getFromToStep(); - // Use the start km to determine the min max values. - minmaxW = valueTable.getMinMaxW(km[0]); - } - else { - km = access.getKms(); - minmaxW = valueTable.getMinMaxW(km[0]); - } + + final double startKm = access.getStartKm(); + // Use the start km to determine the min max values. + minmaxW = valueTable.getMinMaxW(startKm); } return minmaxW != null ? minmaxW @@ -490,20 +485,28 @@ protected double[] determineMinMaxQ(D4EArtifact winfo) { log.debug("WQSelect.determineMinMaxQ"); - WstValueTable valueTable = WstValueTableFactory.getTable( - RiverUtils.getRiver(winfo)); + final WstValueTable valueTable = WstValueTableFactory.getTable(RiverUtils.getRiver(winfo)); - ComputationRangeAccess access = new ComputationRangeAccess(winfo); + final ComputationRangeAccess access = new ComputationRangeAccess(winfo); double[] minmaxQ = null; if(valueTable != null) { - double[] km = null; - if(access.isRange()) { - km = new ComputationRangeAccess(winfo).getFromToStep(); + + final KM_MODE mode = access.getKmRangeMode(); + switch (mode) { + case RANGE: { + final double[] km = access.getFromToStep(); minmaxQ = valueTable.getMinMaxQ(km[0], km[1], km[2]); + break; } - else { - km = access.getKms(); + + case DISTANCE_ONLY: { + minmaxQ = valueTable.getMinMaxQ(access.getFrom(), access.getTo(), 0.1); + break; + } + + default: { + final double[] km = access.getKms(); minmaxQ = valueTable.getMinMaxQ(km[0]); for (int i = 1; i < km.length; i++) { double[] tmp = valueTable.getMinMaxQ(km[i]); @@ -514,6 +517,8 @@ minmaxQ[1] = tmp[1]; } } + break; + } } } return minmaxQ != null diff -r 28eec75415d8 -r f61bc0c63188 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistanceOnlyPanel.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistanceOnlyPanel.java Wed Jun 06 14:15:58 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistanceOnlyPanel.java Wed Jun 06 14:16:28 2018 +0200 @@ -13,6 +13,8 @@ import org.dive4elements.river.client.shared.model.Data; import org.dive4elements.river.client.shared.model.DataItem; import org.dive4elements.river.client.shared.model.DataList; +import org.dive4elements.river.client.shared.model.DefaultData; +import org.dive4elements.river.client.shared.model.DefaultDataItem; public class DistanceOnlyPanel extends DistancePanel { @@ -52,11 +54,14 @@ @Override public Data[] getData() { - final Data[] data = new Data[2]; + final Data[] data = new Data[3]; data[0] = getDataFrom(); data[1] = getDataTo(); + final DataItem item = new DefaultDataItem("ld_mode", "ld_mode", "distance_only"); + data[2] = new DefaultData("ld_mode", null, null, new DataItem[] { item }); + return data; }