Mercurial > dive4elements > river
changeset 9067:2ed3824a3d53
sinfo access collision, floodDuration
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/AccessHelper.java Mon May 14 14:59:10 2018 +0200 @@ -0,0 +1,108 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.artifacts.common; + +import org.apache.log4j.Logger; +import org.dive4elements.artifacts.Artifact; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.access.Access; + +import gnu.trove.TIntArrayList; + +/** + * @author Domenico Nardi Tironi + * + */ +public class AccessHelper extends Access { + + private static Logger log = Logger.getLogger(AccessHelper.class); + + // private final Artifact artifact; + + public AccessHelper(final Artifact artifact) { + this.artifact = (D4EArtifact) artifact; + } + + public String getYearEpoch() { + + return getString("ye_select"); // ACHTUNG, Ergebniswerte wurden geändert in state.sinfo.epoch und state.sinfo.year + + } + + /** [year1, years2,..] if its about years. */ + public int[] getYears(final String yearSelectedValue) { + int[] years = null; + // if (years != null) { + // return years; + // } + if (getYearEpoch().equals(yearSelectedValue)) { + final TIntArrayList ints = new TIntArrayList(); + final String yearsData = getString("years"); + if (yearsData == null || yearsData.isEmpty()) { + log.warn("No years provided"); + return null; + } + for (final String sValue : yearsData.split(" ")) { + try { + ints.add(Integer.parseInt(sValue)); + } + catch (final NumberFormatException e) { + /* Client should prevent this */ + log.warn("Invalid year value: " + sValue); + continue; + } + } + + if (!ints.isEmpty()) { + ints.sort(); + years = ints.toNativeArray(); + } + return years; + } + return null; + } + + public int[][] getEpochs(final String epochSelectedValue) { + int epochs[][] = null; + // if (epochs != null) { + // return epochs; + // } + + if (!getYearEpoch().equals(epochSelectedValue)) { + return null; + } + + final String data = getString("epochs"); + + if (data == null) { + log.warn("No 'epochs' parameter specified!"); + return null; + } + + final String[] parts = data.split(";"); + + epochs = new int[parts.length][]; + + for (int i = 0; i < parts.length; i++) { + final String[] values = parts[i].split(","); + final TIntArrayList ints = new TIntArrayList(); + try { + ints.add(Integer.parseInt(values[0])); + ints.add(Integer.parseInt(values[1])); + epochs[i] = ints.toNativeArray(); + } + catch (final NumberFormatException nfe) { + log.warn("Cannot parse int from string: '" + values + "'"); + } + } + return epochs; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionAccess.java Mon May 14 14:59:10 2018 +0200 @@ -0,0 +1,62 @@ +/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.artifacts.sinfo.collision; + +import org.apache.commons.lang.math.DoubleRange; +import org.dive4elements.river.artifacts.access.RangeAccess; +import org.dive4elements.river.artifacts.common.AccessHelper; +import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; +import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode; + +/** + * Access to the flow depth calculation type specific SInfo artifact data. + * REMARK: this class is NOT intended to be hold in the results (or anywhere else), in order to avoid a permanent + * reference to the artifact instance. + * Hence we do NOT cache any data. + * + * @author Gernot Belger + */ +final class CollisionAccess extends RangeAccess { + + private final AccessHelper helper; + + /// Fields from state: + + // calculation_mode (String), sollte sinfo_calc_collision sein + // ld_from, ld_to + // ye_select (String), mögliche werte: "state.sinfo.epoch" "state.sinfo.year" + // years (String) + // epochs (String) + + public CollisionAccess(final SINFOArtifact artifact) { + super(artifact); + + /* assert calculation mode */ + final SinfoCalcMode calculationMode = artifact.getCalculationMode(); + this.helper = new AccessHelper(artifact); + assert (calculationMode == SinfoCalcMode.sinfo_calc_flow_depth); + } + + public DoubleRange getRange() { + final double from = getFrom(); + final double to = getTo(); + return new DoubleRange(from, to); + } + + public int[] getYears() { + return this.helper.getYears("state.sinfo.year"); + } + + public int[][] getEpochs() { + return this.helper.getEpochs("state.sinfo.epoch"); + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionCalculation.java Mon May 14 14:59:10 2018 +0200 @@ -0,0 +1,57 @@ +/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.artifacts.sinfo.collision; + +import org.apache.commons.lang.math.DoubleRange; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.river.artifacts.model.Calculation; +import org.dive4elements.river.artifacts.model.CalculationResult; +import org.dive4elements.river.artifacts.resources.Resources; +import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; +import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; +import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; +import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; +import org.dive4elements.river.model.River; + +class CollisionCalculation { + + // private static Logger log = Logger.getLogger(FloodDurationCalculation.class); + + private final CallContext context; + + public CollisionCalculation(final CallContext context) { + this.context = context; + } + + public CalculationResult calculate(final SINFOArtifact sinfo) { + + final String user = CalculationUtils.findArtifactUser(this.context, sinfo); + + /* access input data */ + final CollisionAccess access = new CollisionAccess(sinfo); + final River river = access.getRiver(); + final RiverInfo riverInfo = new RiverInfo(river); + + final DoubleRange calcRange = access.getRange(); + + /* calculate results for each diff pair */ + final Calculation problems = new Calculation(); + + final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange); + + final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); + + final int[] years = access.getYears(); + final int[][] epochs = access.getEpochs(); + + return null; // new CalculationResult(results, problems); + } + +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionLoadYearEpochAccess.java Fri May 11 17:04:35 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde - * Software engineering by - * Björnsen Beratende Ingenieure GmbH - * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt - * - * This file is Free Software under the GNU AGPL (>=v3) - * and comes with ABSOLUTELY NO WARRANTY! Check out the - * documentation coming with Dive4Elements River for details. - */ -package org.dive4elements.river.artifacts.sinfo.collision; - -import org.dive4elements.river.artifacts.D4EArtifact; -import org.dive4elements.river.artifacts.access.RangeAccess; - -/** - * @author Domenico Nardi Tironi - * - */ -public class CollisionLoadYearEpochAccess extends RangeAccess { - - private int[][] epochs; - - private int[] years; - - public CollisionLoadYearEpochAccess(final D4EArtifact artifact) { - // TODO Auto-generated constructor stub - } - - public int[] getYears() { - // TODO Auto-generated method stub - return null; - } - -}
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionState.java Fri May 11 17:04:35 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionState.java Mon May 14 14:59:10 2018 +0200 @@ -109,6 +109,6 @@ if (old instanceof CalculationResult) return (CalculationResult) old; - return null; // new FlowDepthCalculation(context).calculate(sinfo); + return new CollisionCalculation(context).calculate(sinfo); } } \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadYearSelect.java Fri May 11 17:04:35 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadYearSelect.java Mon May 14 14:59:10 2018 +0200 @@ -10,7 +10,7 @@ import org.apache.log4j.Logger; import org.dive4elements.artifacts.Artifact; -import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; import org.dive4elements.river.artifacts.states.DefaultState; /** State in which to fetch years for sedminent load calculation. */ @@ -28,16 +28,19 @@ /** Year Select Widget. */ @Override protected String getUIProvider() { - return "uinfo.inundationduration.load_year_select"; + return "minfo.sedimentload_year_select"; // TODO: eigenes Panel oder allgemeineren Code } @Override public boolean validate(final Artifact artifact) throws IllegalArgumentException { - final CollisionLoadYearEpochAccess access = new CollisionLoadYearEpochAccess((D4EArtifact) artifact); + // TODO: check verstehen + + final CollisionAccess access = new CollisionAccess((SINFOArtifact) artifact); // Second year should be later than first. + if (access.getYears() == null || access.getYears().length == 0) - return true; // TODO: richtig in CollisionLoadYear... implementieren + return true; // throw new IllegalArgumentException("error_years_wrong"); return true;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationAccess.java Mon May 14 14:59:10 2018 +0200 @@ -0,0 +1,160 @@ +/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.artifacts.sinfo.flood_duration; + +import org.apache.commons.lang.math.DoubleRange; +import org.apache.log4j.Logger; +import org.dive4elements.river.artifacts.access.RangeAccess; +import org.dive4elements.river.artifacts.common.AccessHelper; +import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; +import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode; + +import gnu.trove.TDoubleArrayList; + +/** + * Access to the flow depth calculation type specific SInfo artifact data. + * REMARK: this class is NOT intended to be hold in the results (or anywhere else), in order to avoid a permanent + * reference to the artifact instance. + * Hence we do NOT cache any data. + * + * @author Gernot Belger + */ +final class FloodDurationAccess extends RangeAccess { + + private static Logger log = Logger.getLogger(FloodDurationAccess.class); + + private static final String FIELD_DIFFIDS = "diffids"; //$NON-NLS-1$ + + private static final String FIELD_USE_TKH = "use_transport_bodies"; //$NON-NLS-1$ + + private final AccessHelper helper; + + /// Fields from state: + + // calculation_mode (String), sollte sinfo_calc_flood_duration sein + // ld_from, ld_to, ld_step + // riverside, mögliche werte: "state.sinfo.riverside.left" "state.sinfo.riverside.right" "state.sinfo.riverside.both" + // wspl + // State.sinfo.WQ: + // <data name="wq_isq" type="Boolean" /> + // <data name="wq_isfree" type="Boolean" /> + // <data name="wq_isrange" type="Boolean" /> + // <data name="wq_from" type="Double" /> + // <data name="wq_to" type="Double" /> + // <data name="wq_step" type="Double" /> + // <data name="wq_single" type="Double[]" /> + public FloodDurationAccess(final SINFOArtifact artifact) { + super(artifact); + + /* assert calculation mode */ + final SinfoCalcMode calculationMode = artifact.getCalculationMode(); + this.helper = new AccessHelper(artifact); + assert (calculationMode == SinfoCalcMode.sinfo_calc_flood_duration); + } + + public DoubleRange getRange() { + final double from = getFrom(); + final double to = getTo(); + return new DoubleRange(from, to); + } + + @Override + public Double getStep() { + return super.getStep(); + } + + public String getRiverside() { + return super.getString("riverside"); + } + + public Boolean getWspl() { + return super.getBoolean("wspl"); + } + + public Boolean getWqIsQ() { + if (!getWspl()) { + return null;// + } + return super.getBoolean("wq_isq"); + } + + public Boolean getWqIsFree() { + if (!getWspl()) { + return null;// + } + return super.getBoolean("wq_isfree"); + } + + public Boolean getWqIsRange() { + if (!getWspl()) { + return null;// + } + return super.getBoolean("wq_isrange"); + } + + public Double getWqFrom() { + if (!getWspl()) { + return null;// + } + if (!getWqIsRange()) + return null; + + return super.getDouble("wq_from"); + } + + public Double getWqTo() { + if (!getWspl()) { + return null;// + } + if (!getWqIsRange()) + return null; + return super.getDouble("wq_to"); + } + + public Double getWqStep() { + if (!getWspl()) { + return null; + } + if (!getWqIsRange()) + return null; + + return super.getDouble("wq_step"); + } + + public double[] getWqSingle() { + if (!getWspl()) { + return null;// + } + if (getWqIsRange()) + return null; + + final String wqSingles = super.getString("wq_single"); + + if (wqSingles == null || wqSingles.isEmpty()) { + log.warn("No wqSingles provided"); + return null; + } + final TDoubleArrayList doubles = new gnu.trove.TDoubleArrayList(); + for (final String value : wqSingles.split(" ")) { + try { + + doubles.add(Double.parseDouble(value));// Punkt/komma? + } + catch (final NumberFormatException e) { + /* Client should prevent this */ + log.warn("Invalid wqsingle value: " + value); + continue; + } + } + return doubles.toNativeArray(); + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java Mon May 14 14:59:10 2018 +0200 @@ -0,0 +1,65 @@ +/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.artifacts.sinfo.flood_duration; + +import org.apache.commons.lang.math.DoubleRange; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.river.artifacts.model.Calculation; +import org.dive4elements.river.artifacts.model.CalculationResult; +import org.dive4elements.river.artifacts.resources.Resources; +import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; +import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; +import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; +import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; +import org.dive4elements.river.model.River; + +class FloodDurationCalculation { + + // private static Logger log = Logger.getLogger(FloodDurationCalculation.class); + + private final CallContext context; + + public FloodDurationCalculation(final CallContext context) { + this.context = context; + } + + public CalculationResult calculate(final SINFOArtifact sinfo) { + + final String user = CalculationUtils.findArtifactUser(this.context, sinfo); + + /* access input data */ + final FloodDurationAccess access = new FloodDurationAccess(sinfo); + final River river = access.getRiver(); + final RiverInfo riverInfo = new RiverInfo(river); + + final DoubleRange calcRange = access.getRange(); + + /* calculate results for each diff pair */ + final Calculation problems = new Calculation(); + + final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange); + + final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); + + final String riverside = access.getRiverside(); + final double step = access.getStep(); + final boolean wspl = access.getWspl(); + final Boolean wqisfree = access.getWqIsFree(); + final Boolean wqIsQ = access.getWqIsQ(); + final Boolean wqIsRange = access.getWqIsRange(); + final Double wqFrom = access.getWqFrom(); + final Double wqTo = access.getWqTo(); + final Double wqStep = access.getWqStep(); + final double[] wqSingle = access.getWqSingle(); + + return null; // new CalculationResult(results, problems); + } + +} \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationState.java Fri May 11 17:04:35 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationState.java Mon May 14 14:59:10 2018 +0200 @@ -109,6 +109,6 @@ if (old instanceof CalculationResult) return (CalculationResult) old; - return null; // new FlowDepthCalculation(context).calculate(sinfo); + return new FloodDurationCalculation(context).calculate(sinfo); } } \ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthAccess.java Fri May 11 17:04:35 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthAccess.java Mon May 14 14:59:10 2018 +0200 @@ -28,7 +28,7 @@ */ final class FlowDepthAccess extends RangeAccess { - private static final String FIELD_DIFFIDS = "diffids"; + private static final String FIELD_DIFFIDS = "diffids"; //$NON-NLS-1$ private static final String FIELD_USE_TKH = "use_transport_bodies"; //$NON-NLS-1$
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java Fri May 11 17:04:35 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java Mon May 14 14:59:10 2018 +0200 @@ -32,7 +32,7 @@ class FlowDepthCalculation { - // private static Logger log = Logger.getLogger(FlowDepthCalculation.class); + // private static Logger log = Logger.getLogger(FloodDurationCalculation.class); private final CallContext context;
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java Fri May 11 17:04:35 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java Mon May 14 14:59:10 2018 +0200 @@ -17,7 +17,7 @@ import org.dive4elements.river.artifacts.sinfo.util.WstInfo; /** - * Contains the results of a {@link FlowDepthCalculation}. + * Contains the results of a {@link FloodDurationCalculation}. * * @author Gernot Belger */
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculationResult.java Fri May 11 17:04:35 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculationResult.java Mon May 14 14:59:10 2018 +0200 @@ -17,7 +17,7 @@ import org.dive4elements.river.artifacts.sinfo.util.WstInfo; /** - * Contains the results of a {@link FlowDepthCalculation}. + * Contains the results of a {@link FloodDurationCalculation}. * * @author Gernot Belger */
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculationResult.java Fri May 11 17:04:35 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculationResult.java Mon May 14 14:59:10 2018 +0200 @@ -17,7 +17,7 @@ import org.dive4elements.river.artifacts.sinfo.util.WstInfo; /** - * Contains the results of a {@link FlowDepthCalculation}. + * Contains the results of a {@link FloodDurationCalculation}. * * @author Gernot Belger */
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculationResult.java Fri May 11 17:04:35 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculationResult.java Mon May 14 14:59:10 2018 +0200 @@ -16,7 +16,7 @@ import org.dive4elements.river.artifacts.sinfo.util.WstInfo; /** - * Contains the results of a {@link FlowDepthCalculation}. + * Contains the results of a {@link FloodDurationCalculation}. * * @author Gernot Belger */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesTableState.java Mon May 14 14:59:10 2018 +0200 @@ -0,0 +1,25 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.artifacts.uinfo.vegetationzones; + +import org.dive4elements.river.artifacts.states.DefaultState; + +/** + * @author Domenico Nardi Tironi + */ +public class VegetationZonesTableState extends DefaultState { + + private static final long serialVersionUID = 1L; + + @Override + protected String getUIProvider() { + return "uinfo.vegetationzones.table"; + } +} \ No newline at end of file