Mercurial > dive4elements > river
changeset 9321:a978b601a034
Salix: Fixed ArrrayoutOfBoundsException; minor cleanup
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/DistanceOnlyPartHistoricalSelect.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/DistanceOnlyPartHistoricalSelect.java Fri Jul 27 10:25:09 2018 +0200 @@ -14,7 +14,6 @@ import java.util.Map; import java.util.TreeMap; -import org.apache.log4j.Logger; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; @@ -30,14 +29,13 @@ public class DistanceOnlyPartHistoricalSelect extends DistanceOnlySelect { private static final long serialVersionUID = 1L; - private static Logger log = Logger.getLogger(DistanceOnlyPartHistoricalSelect.class); - List<BedHeight> bhs = null; - Integer epoch = null; - Integer year = null; - Double lowerKm = null; - Double upperKm = null; - River river = null; + private List<BedHeight> bhs = null; + private Integer epoch = null; + private Integer year = null; + private Double lowerKm = null; + private Double upperKm = null; + private River river = null; @Override protected String getUIProvider() { @@ -56,7 +54,7 @@ try { if (datakey.equals(name)) { - makeDataSourceYearEpoch(artifact, creator, select, context, getBedheights(artifact)); // ist nur n test + makeDataSourceYearEpoch(creator, select, context, getBedheights(artifact)); // ist nur n test } else if (name.equals("ld_from_part")) { final SalixLineAccess access = new SalixLineAccess((UINFOArtifact) artifact); @@ -89,7 +87,7 @@ } catch ( - final IllegalArgumentException iae) { + final IllegalArgumentException iae) { iae.printStackTrace(); } } @@ -118,7 +116,7 @@ } - private static final void makeDataSourceYearEpoch(final Artifact artifact, final ElementCreator creator, final Element select, final CallContext context, + private static final void makeDataSourceYearEpoch(final ElementCreator creator, final Element select, final CallContext context, final List<BedHeight> bedheights) { final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); @@ -184,5 +182,4 @@ } return new double[] { min, max }; } - -} +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadScenarioSelectLimit5.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadScenarioSelectLimit5.java Fri Jul 27 10:25:09 2018 +0200 @@ -11,7 +11,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.dive4elements.artifactdatabase.data.StateData; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; @@ -23,9 +22,8 @@ /** State in which to fetch years for sedminent load calculation. */ public class LoadScenarioSelectLimit5 extends DefaultState { + private static final long serialVersionUID = 1L; - /** The log used in this class. */ - private static Logger log = Logger.getLogger(LoadScenarioSelectLimit5.class); /** * The default constructor that initializes an empty State object. @@ -66,6 +64,4 @@ protected Element createData(final XMLUtils.ElementCreator cr, final Artifact artifact, final StateData data, final CallContext context) { return ScenarioTypeState.changeHeaderForCurrentState("state.uinfo.inundation.scenario.regional", data.getName(), cr, context); } - -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleEpochSelectState.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleEpochSelectState.java Fri Jul 27 10:25:09 2018 +0200 @@ -14,7 +14,6 @@ import java.util.Map; import java.util.TreeMap; -import org.apache.log4j.Logger; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; @@ -25,9 +24,8 @@ import org.w3c.dom.Element; public class LoadSingleEpochSelectState extends DefaultState { + private static final long serialVersionUID = 1L; - /** The log used in this class. */ - private static Logger log = Logger.getLogger(LoadSingleEpochSelectState.class); /** * The default constructor that initializes an empty State object. @@ -48,17 +46,17 @@ if (datakey.equals(name)) { final SalixLineAccess access = new SalixLineAccess((UINFOArtifact) artifact); final List<BedHeight> bhs = BedHeight.getBedHeightEpochs(access.getRiver(), access.getLowerKm(), access.getUpperKm()); - makeDataSourceYearEpoch(artifact, creator, select, context, bhs); + makeDataSourceYearEpoch(creator, select, context, bhs); } } catch ( - final IllegalArgumentException iae) { + final IllegalArgumentException iae) { iae.printStackTrace(); } } - public static final void makeDataSourceYearEpoch(final Artifact artifact, final ElementCreator creator, final Element select, final CallContext context, + public static final void makeDataSourceYearEpoch(final ElementCreator creator, final Element select, final CallContext context, final List<BedHeight> bedheights) { // TODO: maybe move to appropriate helper... final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); @@ -86,5 +84,4 @@ helper.submitMapToXml(); } - -} +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleYearSelectState.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleYearSelectState.java Fri Jul 27 10:25:09 2018 +0200 @@ -10,7 +10,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; @@ -21,9 +20,8 @@ /** State in which to fetch years for sedminent load calculation. */ public class LoadSingleYearSelectState extends DefaultState { + private static final long serialVersionUID = 1L; - /** The log used in this class. */ - private static Logger log = Logger.getLogger(LoadSingleYearSelectState.class); /** * The default constructor that initializes an empty State object. @@ -45,15 +43,13 @@ if (dataKeyofState.equals(name)) { final SalixLineAccess access = new SalixLineAccess((UINFOArtifact) artifact); final List<BedHeight> bhs = BedHeight.getBedHeightYear(access.getRiver(), access.getLowerKm(), access.getUpperKm()); - LoadSingleEpochSelectState.makeDataSourceYearEpoch(artifact, creator, select, context, bhs); + LoadSingleEpochSelectState.makeDataSourceYearEpoch(creator, select, context, bhs); } } catch ( - final IllegalArgumentException iae) { + final IllegalArgumentException iae) { iae.printStackTrace(); } - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineAccess.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineAccess.java Fri Jul 27 10:25:09 2018 +0200 @@ -24,14 +24,6 @@ */ final class SalixLineAccess extends RangeAccess { - static final String FIELD_DIFFID_CURRENT = "diffid_current"; - static final String FIELD_DIFFID_HIST = "diffid_historical"; - // calculation_mode - // ld_from , ld_to - // use_scenario (boolean) - // ld_from_part; ld_to_part - // scenario_selection (mögliche Werte:"scenarioType.option1" "scenarioType.option2" "scenarioType.option3" - /** * Type of a salix line scenario with key property used by the client */ @@ -68,15 +60,15 @@ assert (calculationMode == UinfoCalcMode.uinfo_salix_line); } - public boolean getUseScenario() { + private boolean getUseScenario() { return super.getBoolean("use_scenario"); } public ScenarioType getScenario() { if (getUseScenario()) return ScenarioType.forKey(getString("scenario_selection")); - else - return ScenarioType.NONE; + + return ScenarioType.NONE; } public Double getFromPart() {
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java Fri Jul 27 10:25:09 2018 +0200 @@ -14,6 +14,7 @@ import java.util.NavigableMap; import java.util.TreeMap; +import org.apache.commons.lang.math.DoubleRange; import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.access.RangeAccess; import org.dive4elements.river.artifacts.model.Calculation; @@ -49,29 +50,18 @@ final River river = accessSalix.getRiver(); final RiverInfo riverInfo = new RiverInfo(river); - // final DoubleRange range = accessSalix.getRange(); - // final boolean useScenario = accessSalix.getUseScenario(); - // final String selectedScenario = accessSalix.getScenario(); - // final Double fromPart = accessSalix.getFromPart(); - // final Double toPart = accessSalix.getToPart(); - // - // final boolean useSCenario = accessSalix.getUseScenario(); - // final String scenario = accessSalix.getScenario(); - // calculation_mode - // ld_from , ld_to - // use_scenario (boolean) - // ld_from_part; ld_to_part - // scenario_selection (mögliche Werte:"scenarioType.option1" "scenarioType.option2" "scenarioType.option3" - final RiverInfoProvider riverInfoProvider = RiverInfoProvider.forRange(this.context, river, accessSalix.getRange()); + final DoubleRange range = accessSalix.getRange(); - // FIXME: real calculation + final ScenarioType scenarioType = accessSalix.getScenario(); - final SalixLineCalculationResults results = new SalixLineCalculationResults(calcModeLabel, user, riverInfo, accessSalix.getRange()); + final RiverInfoProvider riverInfoProvider = RiverInfoProvider.forRange(this.context, river, range); - final SalixLineCalculator calculator = new SalixLineCalculator(this.context, riverInfoProvider); + final SalixLineCalculationResults results = new SalixLineCalculationResults(calcModeLabel, user, riverInfo, range); + + final SalixLineCalculator calculator = new SalixLineCalculator(riverInfoProvider); final NavigableMap<Double, List<Double>> rangeScenarios = buildRangeScenarios(accessSalix); - calculator.execute(problems, uinfo, rangeScenarios, accessSalix.getScenario(), buildScenarioLabels(accessSalix), results); + calculator.execute(problems, uinfo, rangeScenarios, scenarioType, buildScenarioLabels(accessSalix), results); // final Collection<ResultRow> rows = new ArrayList<>(); // SalixLineCalculationNoScenarioResult result = null; // verzweigung etwas ungünstig. möglicherweise auch die @@ -150,17 +140,6 @@ return new CalculationResult(results, problems); } - // private SalixScenario findScenarioByKm(final double km, final Map<DoubleRange, SalixScenario> rangeScenarioMap) { - // final Iterator<DoubleRange> rangeIterator = rangeScenarioMap.keySet().iterator(); - // while (rangeIterator.hasNext()) { - // final DoubleRange range = rangeIterator.next(); - // if (range.containsDouble(km + 0.0001)) { - // return rangeScenarioMap.get(range); - // } - // } - // return null; - // } - /** * Build a map of delta-Ws by km-range for the selected scenario */ @@ -175,6 +154,7 @@ // historisches Szenario aus MSH etc. else fillRangeScenarios(rangeScenarios, access); + return rangeScenarios; }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Fri Jul 27 10:25:09 2018 +0200 @@ -16,7 +16,6 @@ import java.util.Map.Entry; import java.util.NavigableMap; -import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.WINFOArtifact; import org.dive4elements.river.artifacts.access.ComputationRangeAccess; import org.dive4elements.river.artifacts.common.GeneralResultType; @@ -41,14 +40,12 @@ * * @author Matthias Schäfer */ -public class SalixLineCalculator { +final class SalixLineCalculator { private final List<ResultRow> rows = new ArrayList<>(); private final RiverInfoProvider riverInfoProvider; - private final CallContext context; - private final Map<Gauge, QPosition> gaugeMwPos; private final Map<Gauge, QPosition> gaugeMnwPos; private final Map<Gauge, QPosition> gaugeMhwPos; @@ -57,21 +54,13 @@ private WstValueTable wst; - /** - * List of delta-w (may be 0) mapped by km range - */ - private NavigableMap<Double, List<Double>> rangeScenarios; - - - public SalixLineCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) { - this.context = context; + public SalixLineCalculator(final RiverInfoProvider riverInfoProvider) { this.riverInfoProvider = riverInfoProvider; this.gaugeMwPos = new HashMap<>(); this.gaugeMnwPos = new HashMap<>(); this.gaugeMhwPos = new HashMap<>(); } - /** * Calculate the salix line result rows */ @@ -80,7 +69,6 @@ this.problems = problems; this.wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver()); - this.rangeScenarios = rangeScenarios; fetchGaugeMainValuePositions(); @@ -88,7 +76,7 @@ winfo.addStringData("ld_mode", "distance"); winfo.addStringData("ld_step", "100"); for (final double station : new ComputationRangeAccess(winfo).getKms()) { - this.rows.add(createRow(station)); + this.rows.add(createRow(station, rangeScenarios)); } if (scenarioType == ScenarioType.REGIONAL) results.addResult(new SalixLineCalculationRegionalResult("Salix", scenarioLabels, this.rows), problems); @@ -128,8 +116,10 @@ /** * Create a result row for a station and its gauge, and add w-q-values as selected + * + * @param rangeScenarios2 */ - private ResultRow createRow(final double station) { + private ResultRow createRow(final double station, final NavigableMap<Double, List<Double>> rangeScenarios) { final ResultRow row = ResultRow.create(); // Find station's gauge @@ -147,13 +137,14 @@ row.putValue(UInfoResultType.salix_delta_mw, calcMwmnw(mw, mnw)); // Calc scenario values (always all scenario types set, Result variant extracts the fields needed) final List<SalixScenario> scenarios = new ArrayList<>(); - final double[] deltaws = getDeltaWs(station); + final double[] deltaws = getDeltaWs(station, rangeScenarios); for (int i = 0; i <= deltaws.length - 1; i++) { if (Math.abs(deltaws[i]) < 0.0001) { row.putValue(UInfoResultType.salix_line_scenario, Double.NaN); row.putValue(UInfoResultType.salix_line_scenario_dwspl, 0); // TODO NaN when changed from int to double - } - else { + /* always need to add a member, so the exporter will produce empty columns */ + scenarios.add(null); + } else { final double salix = calcSalix(mhw, mw + deltaws[i]); row.putValue(UInfoResultType.salix_line_scenario, salix); row.putValue(UInfoResultType.salix_line_scenario_dwspl, (int) (deltaws[i] * 100)); @@ -170,8 +161,8 @@ private double interpolateW(final double station, final QPosition qPosition) { if (qPosition != null) return this.wst.interpolateW(station, qPosition, this.problems); - else - return Double.NaN; + + return Double.NaN; } /** @@ -190,16 +181,17 @@ /** * Gets the station-specific list of delta-ws of the active scenario, at least with one 0 item in any case + * + * @param rangeScenarios */ - private double[] getDeltaWs(final double station) { - final Entry<Double, List<Double>> stationScenarios = this.rangeScenarios.floorEntry(station); + private double[] getDeltaWs(final double station, final NavigableMap<Double, List<Double>> rangeScenarios) { + final Entry<Double, List<Double>> stationScenarios = rangeScenarios.floorEntry(station); if (stationScenarios == null) return new double[] { 0.0 }; - else { - final double[] deltaws = new double[stationScenarios.getValue().size()]; - for (int i = 0; i <= stationScenarios.getValue().size() - 1; i++) - deltaws[i] = stationScenarios.getValue().get(i); - return deltaws; - } + + final double[] deltaws = new double[stationScenarios.getValue().size()]; + for (int i = 0; i <= stationScenarios.getValue().size() - 1; i++) + deltaws[i] = stationScenarios.getValue().get(i); + return deltaws; } -} +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineState.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineState.java Fri Jul 27 10:25:09 2018 +0200 @@ -30,9 +30,6 @@ */ public class SalixLineState extends DefaultState { - /// ** The log that is used in this state. */ - // private static Logger log = Logger.getLogger(FlowDepthState.class); - private static final long serialVersionUID = 1L; /**
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixScenario.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixScenario.java Fri Jul 27 10:25:09 2018 +0200 @@ -51,5 +51,4 @@ public static final String getDwsplHeader() { return "uinfo.export.salix_line.csv.header.scenario_dwspl"; } - -} +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixZone.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixZone.java Fri Jul 27 10:25:09 2018 +0200 @@ -17,7 +17,7 @@ * @author Domenico Nardi Tironi * */ -public class SalixZone implements Comparable<SalixZone> { +final class SalixZone implements Comparable<SalixZone> { // IMMER ABGLEICHEN Server Client SalixZone.java private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; @@ -173,4 +173,4 @@ } return minKm; } -} +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/YearChoice.java Fri Jul 27 10:19:38 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/YearChoice.java Fri Jul 27 10:25:09 2018 +0200 @@ -31,5 +31,4 @@ entries.put("state.uinfo.epoch", null); return entries; } - } \ No newline at end of file