[PATCH 3 of 4] No rounding during calculation (Meilenstein-2 2.4.2 and 2.9), delta-w-cm as double (for historical scenario)
Wald Commits
scm-commit at wald.intevation.org
Fri Sep 28 10:16:41 CEST 2018
# HG changeset patch
# User mschaefer
# Date 1538122389 -7200
# Node ID 76c0665888a318e1c608acd9fa9a09d5682bc855
# Parent 83e6acdf8fc6a0ba9593f4637ad8e77333cef576
No rounding during calculation (Meilenstein-2 2.4.2 and 2.9), delta-w-cm as double (for historical scenario)
diff -r 83e6acdf8fc6 -r 76c0665888a3 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java Fri Sep 28 10:11:06 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java Fri Sep 28 10:13:09 2018 +0200
@@ -18,7 +18,6 @@
import org.apache.commons.lang.math.DoubleRange;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.access.RangeAccess;
-import org.dive4elements.river.artifacts.common.AbstractResultType;
import org.dive4elements.river.artifacts.common.GeneralResultType;
import org.dive4elements.river.artifacts.model.Calculation;
import org.dive4elements.river.artifacts.model.CalculationResult;
@@ -33,7 +32,6 @@
import org.dive4elements.river.artifacts.uinfo.salix.SalixLineAccess.ScenarioType;
import org.dive4elements.river.model.BedHeight;
import org.dive4elements.river.model.River;
-import org.dive4elements.river.utils.Formatter;
/**
* Calculation of a iota (former salix) longitudinal section, optionally with a delta scenario
@@ -194,7 +192,7 @@
final double historicalMSH = historicalFinder.getMeanBedHeight(station);
if (Double.isNaN(historicalMSH))
return Double.NaN;
- return Formatter.roundFlowDepth(historicalMSH).subtract(Formatter.roundFlowDepth(currentMSH)).doubleValue();
+ return (historicalMSH - currentMSH);
}
/**
@@ -268,16 +266,4 @@
}
return "";
}
-
- // FIXME: check if needed
- /**
- * Fetches a iota or waterlevel height of a station from a salix calculation result
- */
- public double fetchStationHeight(final double station, final AbstractResultType resultType, final SalixLineCalculationResult result) {
-
- final Calculation problems = new Calculation();
-
- final SalixLineCalculator calculator = new SalixLineCalculator(null);
- return calculator.fetchStationHeight(problems, station, resultType, result);
- }
}
\ No newline at end of file
diff -r 83e6acdf8fc6 -r 76c0665888a3 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationResult.java Fri Sep 28 10:11:06 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationResult.java Fri Sep 28 10:13:09 2018 +0200
@@ -131,12 +131,13 @@
if (context instanceof ExportContextCSV) {
final NumberFormat formatter = ((AbstractExportContext) context).getSalixScenFormatter();
+ final NumberFormat intFormatter = ((AbstractExportContext) context).getIntegerFormatter();
final List<SalixScenario> scenarios = (List<SalixScenario>) row.getValue(UInfoResultType.customMultiRowColSalixScenarios);
for (int i = 1; i <= this.getScenarioCount(); i++) {
if (i > scenarios.size())
break;
if (scenarios.get(i - 1) != null) {
- lines.add(scenarios.get(i - 1).getDeltaWFormatted());
+ lines.add(scenarios.get(i - 1).getDeltaWFormatted(intFormatter));
lines.add(scenarios.get(i - 1).getSalixValueFormatted(formatter));
} else {
lines.add("");
diff -r 83e6acdf8fc6 -r 76c0665888a3 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Fri Sep 28 10:11:06 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Fri Sep 28 10:13:09 2018 +0200
@@ -9,7 +9,6 @@
*/
package org.dive4elements.river.artifacts.uinfo.salix;
-import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -18,7 +17,6 @@
import org.dive4elements.river.artifacts.WINFOArtifact;
import org.dive4elements.river.artifacts.access.ComputationRangeAccess;
-import org.dive4elements.river.artifacts.common.AbstractResultType;
import org.dive4elements.river.artifacts.common.GeneralResultType;
import org.dive4elements.river.artifacts.common.ResultRow;
import org.dive4elements.river.artifacts.model.Calculation;
@@ -28,8 +26,6 @@
import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
import org.dive4elements.river.artifacts.uinfo.common.UInfoResultType;
import org.dive4elements.river.artifacts.uinfo.salix.SalixLineAccess.ScenarioType;
-import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZoneServerClientXChange;
-import org.dive4elements.river.utils.Formatter;
/**
* Calculation of the result rows of the u-info salix line calc mode
@@ -38,23 +34,25 @@
*/
final class SalixLineCalculator {
- private static final String MAIN_VALUE_MNQ = "mnq";
+ private static final String MAIN_VALUE_MNQ = "MNQ";
- private static final String MAIN_VALUE_MQ = "mq";
+ private static final String MAIN_VALUE_MQ = "MQ";
- private static final String MAIN_VALUE_MHQ = "mhq";
+ private static final String MAIN_VALUE_MHQ = "MHQ";
- private static final String MAIN_VALUE_HQ5 = "hq5";
+ private static final String MAIN_VALUE_HQ5 = "HQ5";
- private static final BigDecimal SALIX_DISTANCE = new BigDecimal("2.31");
+ private static final double SALIX_DISTANCE = 2.31;
private final List<ResultRow> rows = new ArrayList<>();
private final RiverInfoProvider riverInfoProvider;
+
public SalixLineCalculator(final RiverInfoProvider riverInfoProvider) {
this.riverInfoProvider = riverInfoProvider;
}
+
/**
* Calculate the salix line result rows
*/
@@ -98,8 +96,6 @@
/**
* Create a result row for a station and its gauge, and add w-q-values as selected
- *
- * @param mainWstValues
*/
private ResultRow createRow(final MainWstValuesCalculator mainWstValues, final double station, final NavigableMap<Double, List<Double>> rangeScenarios) {
@@ -123,7 +119,7 @@
// Calc salix-line and mw-mnw
row.putValue(UInfoResultType.salixline, calcSalix(mhw, mw, 0.0));
row.putValue(UInfoResultType.salix_mw_mnw, calcMwmnw(mw, mnw));
- final double salixw = Formatter.roundW(mhw).subtract(SALIX_DISTANCE).doubleValue();
+ final double salixw = mhw - SALIX_DISTANCE;
row.putValue(UInfoResultType.salixw, salixw);
// Calc scenario values (always all scenario types set, Result variant extracts the fields needed)
final List<SalixScenario> scenarios = new ArrayList<>();
@@ -132,7 +128,7 @@
if (deltaw != null) {
final double salix = calcSalix(mhw, mw, deltaw.doubleValue());
final double scen = calcSalix(mhw, 0.0, deltaw.doubleValue());
- scenarios.add(new SalixScenario((int) (deltaw * 100), salix, scen));
+ scenarios.add(new SalixScenario(deltaw * 100, salix, scen));
} else {
scenarios.add(null);
}
@@ -148,7 +144,7 @@
private double calcSalix(final double mhw, final double mw, final double deltamw) {
if (Double.isNaN(mw) || Double.isInfinite(mw) || Double.isNaN(mhw) || Double.isInfinite(mhw))
return mhw - mw; // preserving NaN or Infinity
- return Formatter.roundW(mhw).subtract(SALIX_DISTANCE).subtract(Formatter.roundW(mw).add(Formatter.roundW(deltamw))).doubleValue();
+ return mhw - SALIX_DISTANCE - mw - deltamw;
}
/**
@@ -157,7 +153,7 @@
private double calcMwmnw(final double mw, final double mnw) {
if (Double.isNaN(mw) || Double.isInfinite(mw) || Double.isNaN(mnw) || Double.isInfinite(mnw))
return mnw - mw; // preserving NaN or Inifinity
- return Formatter.roundW(mnw).subtract(Formatter.roundW(mw)).doubleValue();
+ return mnw - mw;
}
/**
@@ -174,19 +170,6 @@
}
/**
- * Find and return a height (iota, w main value) of a station in a previously calculated result
- */
- public double fetchStationHeight(final Calculation problems, final double station, final AbstractResultType resultType,
- final SalixLineCalculationResult result) {
-
- // Search the station in the previously calculated result rows
- final ResultRow stationRow = searchStation(station, result.getRows());
- if (stationRow != null)
- return stationRow.getDoubleValue(resultType);
- return Double.NaN;
- }
-
- /**
* Searches the row of a station in a result rows collection
*/
private ResultRow searchStation(final double station, final Collection<ResultRow> rows) {
@@ -196,29 +179,4 @@
}
return null;
}
-
- /**
- * Computes the height of a vegetation zone limit for a station and a previously computed salix line result
- */
- public double computeVegetationZoneHeight(final Calculation problems, final double station, final int vegetationZoneType,
- final SalixLineCalculationResult result) {
-
- // Search the station in the previously calculated result rows
- final ResultRow stationRow = searchStation(station, result.getRows());
- if (stationRow == null)
- return Double.NaN;
-
- // Compute height from overflow duration days
- final List<VegetationZoneServerClientXChange> vzs = VegetationZoneServerClientXChange.getStandardList(null, null); // TODO river, context
- if ((vegetationZoneType >= 1) && (vegetationZoneType <= vzs.size())) {
- final int uefd = vzs.get(vegetationZoneType - 1).getMin_day_overflow();
- // Üfd = -70,559 ∗ ln((DGM - MW) + 0,5) + 80,711
- final double f1 = -70.559;
- final double f2 = -88.711;
- final double mw = stationRow.getDoubleValue(UInfoResultType.waterlevelMW);
- final double dgm = Math.exp((uefd - f2) / f1) + mw - 0.5;
- return dgm;
- }
- return Double.NaN;
- }
}
diff -r 83e6acdf8fc6 -r 76c0665888a3 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixScenario.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixScenario.java Fri Sep 28 10:11:06 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixScenario.java Fri Sep 28 10:13:09 2018 +0200
@@ -23,10 +23,10 @@
private static final long serialVersionUID = 1L;
private final double salix_value;
- private final int deltaW;
+ private final double deltaW;
private final double salixW;
- public SalixScenario(final int deltaW, final double salix_value, final double salixW) {
+ public SalixScenario(final double deltaW, final double salix_value, final double salixW) {
this.deltaW = deltaW;
this.salix_value = salix_value;
this.salixW = salixW;
@@ -36,15 +36,15 @@
return this.salix_value;
}
- public int getDeltaW() {
+ public double getDeltaW() {
return this.deltaW;
}
- public String getDeltaWFormatted() {
- // if (Double.isNaN(this.deltaW))
- // return StringUtils.EMPTY;
+ public String getDeltaWFormatted(final NumberFormat formatter) {
+ if (Double.isNaN(this.deltaW))
+ return StringUtils.EMPTY;
- return String.valueOf(this.deltaW);
+ return formatter.format(this.deltaW);
}
public String getSalixValueFormatted(final NumberFormat formatter) {
More information about the Dive4Elements-commits
mailing list