# HG changeset patch # User mschaefer # Date 1537366868 -7200 # Node ID e44c1a8b0c5428af5e672efe33fe20abfa38e5d1 # Parent 8562c60371b867c8d62586d37806d8f0f66a887f Fixed: rounding problems in iota/salix scenario calculation diff -r 8562c60371b8 -r e44c1a8b0c54 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java Tue Sep 18 17:28:22 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultType.java Wed Sep 19 16:21:08 2018 +0200 @@ -12,6 +12,7 @@ import java.text.NumberFormat; import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.common.AbstractResultType; import org.dive4elements.river.artifacts.common.I18NStrings; @@ -30,6 +31,8 @@ private static final long serialVersionUID = 1L; + protected static Logger log = Logger.getLogger(SInfoResultType.class); + protected SInfoResultType(final String unit, final String csvHeader) { super(unit, csvHeader, csvHeader); } @@ -209,6 +212,8 @@ @Override public String exportValue(final CallContext context, final Object value) { final double doubleValue = asDouble(value); + log.trace(String.format("meanBedHeight.exportValue value: %f doubleValue: %f formatted to: %s", value, doubleValue, + exportDoubleValue(context, doubleValue))); return exportDoubleValue(context, doubleValue); } diff -r 8562c60371b8 -r e44c1a8b0c54 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 Tue Sep 18 17:28:22 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Wed Sep 19 16:21:08 2018 +0200 @@ -167,16 +167,18 @@ row.putValue(UInfoResultType.waterlevelMH5, hw5); // Calc salix-line and mw-mnw - row.putValue(UInfoResultType.salixline, calcSalix(mhw, mw)); + row.putValue(UInfoResultType.salixline, calcSalix(mhw, mw, 0.0)); row.putValue(UInfoResultType.salix_mw_mnw, calcMwmnw(mw, mnw)); - row.putValue(UInfoResultType.salixw, mhw - SALIX_DISTANCE.doubleValue()); + final double salixw = Formatter.roundW(mhw).subtract(SALIX_DISTANCE).doubleValue(); + row.putValue(UInfoResultType.salixw, salixw); // Calc scenario values (always all scenario types set, Result variant extracts the fields needed) final List scenarios = new ArrayList<>(); final List deltaws = getDeltaWs(station, rangeScenarios); for (final Double deltaw : deltaws) { if (deltaw != null) { - final double salix = calcSalix(mhw, mw + deltaw); - scenarios.add(new SalixScenario((int) (deltaw * 100), salix, mhw + deltaw - SALIX_DISTANCE.doubleValue())); + 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)); } else { scenarios.add(null); @@ -199,10 +201,10 @@ /** * Calculates the salix value */ - private double calcSalix(final double mhw, final double mw) { + 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 mw; // preserving NaN or Infinity - return Formatter.roundW(mhw).subtract(SALIX_DISTANCE).subtract(Formatter.roundW(mw)).doubleValue(); + return mhw - mw; // preserving NaN or Infinity + return Formatter.roundW(mhw).subtract(SALIX_DISTANCE).subtract(Formatter.roundW(mw).add(Formatter.roundW(deltamw))).doubleValue(); } /** diff -r 8562c60371b8 -r e44c1a8b0c54 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 Tue Sep 18 17:28:22 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixScenario.java Wed Sep 19 16:21:08 2018 +0200 @@ -58,11 +58,11 @@ return this.salixW; } - public String getSalixWFormatted() { + public String getSalixWFormatted(final NumberFormat formatter) { if (Double.isNaN(this.salixW)) return StringUtils.EMPTY; - return String.valueOf(this.salixW); + return formatter.format(this.salixW); } public static final String getScenarioValueHeader() {