# HG changeset patch # User gernotbelger # Date 1519751212 -3600 # Node ID e3519c3e7a0a91e03ad877e17588489942469b60 # Parent 924cd99433378d42128cd3a34c265ac679ef881a Workflow for SINFO-Transport bodies heights inclduing winfo calculation diff -r 924cd9943337 -r e3519c3e7a0a artifacts/doc/conf/artifacts/sinfo.xml --- a/artifacts/doc/conf/artifacts/sinfo.xml Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/doc/conf/artifacts/sinfo.xml Tue Feb 27 18:06:52 2018 +0100 @@ -1,89 +1,131 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - + + + + - - - + + + - - - - - - + + + + + + - - - - - + + + + - - + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java Tue Feb 27 18:06:52 2018 +0100 @@ -20,7 +20,7 @@ import org.dive4elements.river.artifacts.access.Calculation4Access; import org.dive4elements.river.artifacts.access.RangeAccess; - +import org.dive4elements.river.artifacts.access.ComputationRangeAccess; import org.dive4elements.river.artifacts.geom.Lines; import org.dive4elements.river.artifacts.model.Calculation1; @@ -808,48 +808,13 @@ * @return the selected kms. */ public double[] getKms() { - RangeAccess rangeAccess = new RangeAccess(this); - if (rangeAccess.isRange()) { - return rangeAccess.getKmSteps(); - } - else { - return LocationDistanceSelect.getLocations(this); - } + return new ComputationRangeAccess(this).getKms(); } - public double [] getFromToStep() { - RangeAccess rangeAccess = new RangeAccess(this); - if (!rangeAccess.isRange()) { - return null; - } - double [] fromTo = rangeAccess.getKmRange(); - - if (fromTo == null) { - return null; - } - - StateData dStep = getData("ld_step"); - if (dStep == null) { - return null; - } - - double [] result = new double[3]; - result[0] = fromTo[0]; - result[1] = fromTo[1]; - - try { - String step = (String)dStep.getValue(); - result[2] = DoubleUtil.round(Double.parseDouble(step) / 1000d); - } - catch (NumberFormatException nfe) { - return null; - } - - return result; + return new ComputationRangeAccess(this).getFromToStep(); } - /** * This method returns the Q values. * diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/java/org/dive4elements/river/artifacts/access/ComputationRangeAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/ComputationRangeAccess.java Tue Feb 27 18:06:52 2018 +0100 @@ -0,0 +1,64 @@ +/** 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.access; + +import org.dive4elements.artifactdatabase.data.StateData; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.states.ComputationRangeState; +import org.dive4elements.river.utils.DoubleUtil; + +/** + * Access to data handled by {@link ComputationRangeState}. + * + * @author Gernot Belger + */ +public class ComputationRangeAccess extends RangeAccess { + + public ComputationRangeAccess(final D4EArtifact artifact) { + super(artifact); + } + + public double[] getFromToStep() { + + if (!isRange()) + return null; + + final double[] fromTo = getKmRange(); + + if (fromTo == null) + return null; + + final StateData dStep = getArtifact().getData("ld_step"); + if (dStep == null) + return null; + + final double[] result = new double[3]; + result[0] = fromTo[0]; + result[1] = fromTo[1]; + + try { + final String dStepValue = (String) dStep.getValue(); + result[2] = DoubleUtil.round(Double.parseDouble(dStepValue) / 1000d); + return result; + } + catch (final NumberFormatException nfe) { + nfe.printStackTrace(); + return null; + } + } + + public double[] getKms() { + + if (isRange()) + return getKmSteps(); + + return getLocations(); + } +} \ No newline at end of file diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/CalculationSelectSinfo.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/CalculationSelectSinfo.java Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/CalculationSelectSinfo.java Tue Feb 27 18:06:52 2018 +0100 @@ -1,13 +1,12 @@ /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde - * Software engineering by - * Björnsen Beratende Ingenieure GmbH + * 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; import java.util.ArrayList; @@ -27,46 +26,31 @@ */ public class CalculationSelectSinfo extends DefaultState { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** The log that is used in this class. */ + /** The log that is used in this class. */ private static Logger log = Logger.getLogger(CalculationSelectSinfo.class); - public CalculationSelectSinfo() { - } - - @Override - protected Element[] createItems( - XMLUtils.ElementCreator cr, - Artifact artifact, - String name, - CallContext context) - { - final CallMeta meta = context.getMeta(); - + protected Element[] createItems(final XMLUtils.ElementCreator cr, final Artifact artifact, final String name, final CallContext context) { + final CallMeta meta = context.getMeta(); + final Collection calcs = new ArrayList<>(SinfoCalcMode.values().length); for (final SinfoCalcMode calcMode : SinfoCalcMode.values()) { - final String calc = calcMode.name(); - - final String label = Resources.getMsg(meta, calc, calc); - - final Element element = createItem( - cr, new String[] { - label, - calc - }); - calcs.add(element); - } - + final String calc = calcMode.name(); + + final String label = Resources.getMsg(meta, calc, calc); + + final Element element = createItem(cr, new String[] { label, calc }); + calcs.add(element); + } + return calcs.toArray(new Element[calcs.size()]); } @Override - public boolean validate(Artifact artifact) - throws IllegalArgumentException - { + public boolean validate(final Artifact artifact) throws IllegalArgumentException { log.debug("CalculationSelect.validate"); final SINFOArtifact sinfo = (SINFOArtifact) artifact; @@ -74,5 +58,4 @@ sinfo.getCalculationMode(); return true; } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : +} \ No newline at end of file diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java Tue Feb 27 18:06:52 2018 +0100 @@ -19,7 +19,6 @@ import org.apache.commons.lang.math.DoubleRange; import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.analysis.UnivariateRealFunction; -import org.apache.log4j.Logger; import org.dive4elements.artifacts.ArtifactDatabase; import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.BedHeightsArtifact; @@ -47,7 +46,7 @@ class FlowDepthCalculation { - private static Logger log = Logger.getLogger(FlowDepthCalculation.class); + // private static Logger log = Logger.getLogger(FlowDepthCalculation.class); private static final int VALID_BED_MEASUREMENT_YEARS = 20; @@ -172,14 +171,14 @@ if (doCalcTkh) { qInterpolator = DoubleUtil.getLinearInterpolator(((QKms) wstKms).allKms(), ((QKms) wstKms).allQs()); if (qInterpolator != null) - qRange = new DoubleRange( ((QKms) wstKms).allQs().min(), ((QKms) wstKms).allQs().max()); + qRange = new DoubleRange(((QKms) wstKms).allQs().min(), ((QKms) wstKms).allQs().max()); else { final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, label); problems.addProblem(message); doCalcTkh = false; } } - + // FIXME: sort by station first, but in what direction? // FIXME: using river.getKmUp()? final List values = bedHeight.getValues(); @@ -198,7 +197,7 @@ problems.addProblem(message); } } - + FlowVelocityModelKmValueFinder flowVelocitiesFinder = null; if (doCalcTkh) { flowVelocitiesFinder = new FlowVelocityModelKmValueFinder(); @@ -245,60 +244,43 @@ double d50 = Double.NaN; try { d50 = bedMeasurementsFinder.findD50(km); - } catch (Exception e) { + } + catch (final Exception e) { final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingD50", null, label); problems.addProblem(km, message); - //FIXME: cumulate problems to one message? + // FIXME: cumulate problems to one message? } if (!Double.isNaN(d50)) { if (flowVelocitiesFinder.findKmQValues(km, discharge)) { tkh = calculateTkh(wst - meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), d50, flowVelocitiesFinder.getFindTauFound()); if (!Double.isNaN(tkh) && (tkh < 0)) tkh = 0; - /* log.debug(String.format("calculateTkh km %.3f q %.0f w %.2f mbh %.2f vm %.1f tau %.1f d50(mm) %.1f tkh(cm) %.1f", - km, discharge, wst, meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), flowVelocitiesFinder.getFindTauFound(), d50*1000, tkh)); */ - } - else { + /* + * log.debug(String.format("calculateTkh km %.3f q %.0f w %.2f mbh %.2f vm %.1f tau %.1f d50(mm) %.1f tkh(cm) %.1f", + * km, discharge, wst, meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), flowVelocitiesFinder.getFindTauFound(), + * d50*1000, tkh)); + */ + } else { final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, label); problems.addProblem(km, message); - //FIXME: cumulate problems to one message? + // FIXME: cumulate problems to one message? } - } - else + } else tkh = Double.NaN; } - + // Soil kind SoilKind kind = SoilKind.mobil; if (doCalcTkh) { try { - kind = soilKindFinder.findSoilKind(km); - } catch (Exception e) { + kind = soilKindFinder.findSoilKind(km); + } + catch (final Exception e) { final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingSoilKind", null, label); problems.addProblem(km, message); - //FIXME: cumulate problems to one message? + // FIXME: cumulate problems to one message? } } - - /* // REMARK: bissl spielerei zum testen damit die sohlart nicht zu schnell wechselt - SoilKind kind; - final boolean changeKind = Math.random() > 0.95; - if (changeKind) { - switch (lastKind) { - case starr: - kind = SoilKind.mobil; - break; - case mobil: - default: - kind = SoilKind.starr; - break; - } - } else - kind = lastKind; - lastKind = kind; - */ - - //tkh = 100 + 10 * (Math.random() - 0.5); final double flowDepthTkh; final double tkhUp; @@ -326,15 +308,14 @@ final String gaugeLabel = gauge == null ? notinrange : gauge.getName(); - resultData.addRow(km, flowDepth, flowDepthTkh, kind, tkh, tkhUp, tkhDown, wst, discharge, wstLabel, - gaugeLabel, meanBedHeight, bedHeightLabel, location); + resultData.addRow(km, flowDepth, flowDepthTkh, kind, tkh, tkhUp, tkhDown, wst, discharge, wstLabel, gaugeLabel, meanBedHeight, bedHeightLabel, + location); } catch (final FunctionEvaluationException e) { /* should only happen if out of range */ e.printStackTrace(); /* simply ignore */ } - } return resultData; @@ -470,16 +451,21 @@ return BedHeight.getBedHeightById(bedheightId); } - + /** * Calculates a transport body height - * @param h flow depth in m - * @param vm flow velocity in m - * @param d50 grain diameter D50 in m (!) - * @param tau shear stress in N/m^2 + * + * @param h + * flow depth in m + * @param vm + * flow velocity in m + * @param d50 + * grain diameter D50 in m (!) + * @param tau + * shear stress in N/m^2 * @return transport body height in cm (!) */ - private double calculateTkh(double h, double vm, double d50, double tau) { + private double calculateTkh(final double h, final double vm, final double d50, final double tau) { final double PHYS_G = 9.81; final double PHYS_SPECGRAV_S = 2.6; final double PHYS_VELOCCOEFF_N = 6; @@ -487,10 +473,10 @@ final double PHYS_VISCOSITY_NUE = 1.3e-6; final double PHYS_GRAIN_DENSITY_RHOS = 2603; final double PHYS_WATER_DENSITY_RHO = 999.97; - + final double froude = vm / Math.sqrt(PHYS_G * h); final double partReynolds = Math.sqrt((PHYS_SPECGRAV_S - 1) * PHYS_G * d50) / PHYS_VISCOSITY_NUE * d50; - final double critShields = 0.22 * Math.pow(partReynolds, -0.6) + 0.06 * Math.pow(10, 7.7 * Math.pow(partReynolds, -0.6)); + final double critShields = 0.22 * Math.pow(partReynolds, -0.6) + 0.06 * Math.pow(10, 7.7 * Math.pow(partReynolds, -0.6)); final double critTau = critShields * (PHYS_GRAIN_DENSITY_RHOS - PHYS_WATER_DENSITY_RHO) * PHYS_G * d50; return 100 * h * (1 - Math.pow(froude, 2)) / (2 * PHYS_VELOCCOEFF_N * PHYS_FORMCOEFF_ALPHA) * (1 - critTau / tau); } diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthState.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthState.java Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthState.java Tue Feb 27 18:06:52 2018 +0100 @@ -78,15 +78,10 @@ */ private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List facets, final Object old) { - final CalculationResult res; - if (old instanceof CalculationResult) - res = (CalculationResult) old; - else - res = new FlowDepthCalculation(context).calculate(sinfo); + final CalculationResult res = doCompute(sinfo, context, old); - if (facets == null) { + if (facets == null) return res; - } final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData(); @@ -140,4 +135,11 @@ return res; } + + private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { + if (old instanceof CalculationResult) + return (CalculationResult) old; + + return new FlowDepthCalculation(context).calculate(sinfo); + } } \ No newline at end of file diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkh/TkhState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkh/TkhState.java Tue Feb 27 18:06:52 2018 +0100 @@ -0,0 +1,161 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * 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.tkh; + +import java.util.List; + +import org.dive4elements.artifactdatabase.state.Facet; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.river.artifacts.ChartArtifact; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.WINFOArtifact; +import org.dive4elements.river.artifacts.model.Calculation; +import org.dive4elements.river.artifacts.model.CalculationResult; +import org.dive4elements.river.artifacts.model.EmptyFacet; +import org.dive4elements.river.artifacts.model.WQKms; +import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; +import org.dive4elements.river.artifacts.states.DefaultState; + +/** State in which a waterlevel has been calculated. */ +public class TkhState extends DefaultState { + + /// ** The log that is used in this state. */ + // private static Logger log = Logger.getLogger(FlowDepthState.class); + + private static final long serialVersionUID = 1L; + + private static final String I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth.filtered.description"; + + private static final String I18N_FACET_FLOW_DEPTH_TKH_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth.tkh.filtered.description"; + + private static final String I18N_FACET_TKH_DESCRIPTION = "sinfo.facet.tkh.description"; + + private static final String SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL = "sinfo.chart.flow_depth.yaxis.label"; + + private static final String SINFO_CHART_TKX_YAXIS_LABEL = "sinfo.chart.tkh.yaxis.label"; + + /** + * From this state can only be continued trivially. + */ + @Override + protected String getUIProvider() { + return "continue"; + } + + @Override + public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List facets, final Object old) { + // FIXME: why is this necessary? + if (artifact instanceof ChartArtifact) { + facets.add(new EmptyFacet()); + return null; + } + + return compute((SINFOArtifact) artifact, context, hash, facets, old); + } + + @Override + public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List facets, final Object old) { + if (artifact instanceof ChartArtifact) { + facets.add(new EmptyFacet()); + return null; + } + return compute((SINFOArtifact) artifact, context, hash, facets, old); + } + + /** + * Compute result or returned object from cache, create facets. + * + * @param old + * Object that was cached. + */ + private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List facets, final Object old) { + + final CalculationResult res = doCompute(sinfo, context, old); + + if (facets == null) + return res; + + // final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData(); + // + // /* add themes for chart, for each result */ + // final List resultList = results.getResults(); + // for (int index = 0; index < resultList.size(); index++) { + // + // final FlowDepthCalculationResult result = resultList.get(index); + // + // /* filtered (zoom dependent mean) flow depth */ + // final String facetFlowDepthFilteredDescription = Resources.getMsg(context.getMeta(), + // I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, + // I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, result.getLabel()); + // facets.add(new FlowDepthFacet(index, FlowDepthProcessor.FACET_FLOW_DEPTH_FILTERED, facetFlowDepthFilteredDescription, + // SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, ComputeType.ADVANCE, this.id, hash)); + // + // if (results.isUseTkh()) { + // /* filtered (zoom dependent mean) flow depth including tkh */ + // final String facetFlowDepthTkhFilteredDescription = Resources.getMsg(context.getMeta(), + // I18N_FACET_FLOW_DEPTH_TKH_FILTERED_DESCRIPTION, + // I18N_FACET_FLOW_DEPTH_TKH_FILTERED_DESCRIPTION, result.getLabel()); + // facets.add(new FlowDepthFacet(index, FlowDepthProcessor.FACET_FLOW_DEPTH_TKH_FILTERED, + // facetFlowDepthTkhFilteredDescription, + // SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, ComputeType.ADVANCE, this.id, hash)); + // + // // FIXME: add other themes + // // - Streckenfavoriten + // + // // FIXME: + // // - Gemittelte Linie der Fließtiefe mitsamt TKH + // // - Transportkörperhöhen (oben/unten/schraffur) + // final String facetTkhDescription = Resources.getMsg(context.getMeta(), I18N_FACET_TKH_DESCRIPTION, + // I18N_FACET_TKH_DESCRIPTION, + // result.getLabel()); + // facets.add(new FlowDepthFacet(index, TkhProcessor.FACET_TKH, facetTkhDescription, SINFO_CHART_TKX_YAXIS_LABEL, + // ComputeType.ADVANCE, this.id, + // hash)); + // } + // + // // FIXME: Datenkorbkonfiguration + // } + // + // if (!resultList.isEmpty()) { + // final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); + // final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); + // + // facets.add(csv); + // facets.add(pdf); + // } + // + // final Calculation report = res.getReport(); + // + // if (report.hasProblems()) { + // facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); + // } + // + // return res; + return null; + } + + private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { + if (old instanceof CalculationResult) + return (CalculationResult) old; + + // res = new FlowDepthCalculation(context).calculate(sinfo); + + final WINFOArtifact winfo = new WinfoArtifactWrapper(sinfo); + + final CalculationResult waterlevelData = winfo.getWaterlevelData(context); + final Calculation winfoProblems = waterlevelData.getReport(); + + final WQKms[] kms = (WQKms[]) waterlevelData.getData(); + + final Object result = new Object(); + final Calculation problems = new Calculation(); + + return new CalculationResult(result, problems); + } +} \ No newline at end of file diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkh/WinfoArtifactWrapper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkh/WinfoArtifactWrapper.java Tue Feb 27 18:06:52 2018 +0100 @@ -0,0 +1,42 @@ +/** 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.tkh; + +import java.util.Collection; + +import org.dive4elements.artifactdatabase.data.DefaultStateData; +import org.dive4elements.artifactdatabase.data.StateData; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.river.artifacts.WINFOArtifact; + +/** + * Ugly wrapper around WINfoArtifact in order to a) not to break serialization of WInfoArtifact b) be able to copy data + * into it + * + * @author Gernot Belger + * + */ +class WinfoArtifactWrapper extends WINFOArtifact { + + private static final long serialVersionUID = 1L; + + public WinfoArtifactWrapper(final D4EArtifact dataSource) { + final Collection allData = dataSource.getAllData(); + for (final StateData stateData : allData) { + + final DefaultStateData clonedData = new DefaultStateData(); + clonedData.set(stateData); + + addData(clonedData.getName(), clonedData); + } + + addStringData("calculation_mode", "calc.surface.curve"); + } +} \ No newline at end of file diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java Tue Feb 27 18:06:52 2018 +0100 @@ -30,10 +30,9 @@ import org.dive4elements.river.model.Wst; import org.dive4elements.river.artifacts.D4EArtifact; -import org.dive4elements.river.artifacts.WINFOArtifact; import org.dive4elements.river.artifacts.access.RangeAccess; - +import org.dive4elements.river.artifacts.access.ComputationRangeAccess; import org.dive4elements.river.artifacts.model.WstFactory; import org.dive4elements.river.artifacts.model.WstValueTable; import org.dive4elements.river.artifacts.model.WstValueTableFactory; @@ -104,8 +103,6 @@ Boolean isQ = flys.getDataAsBoolean(WQ_MODE); Boolean isFree = flys.getDataAsBoolean(WQ_FREE); - WINFOArtifact winfo = (WINFOArtifact) flys; - Element dataElement = creator.create("data"); creator.addAttr(dataElement, "name", name, true); creator.addAttr(dataElement, "type", type, true); @@ -116,10 +113,10 @@ String label; if (!isQ || isFree) { - label = getLabel(winfo, cc, value); + label = getLabel(flys, cc, value); } else { - label = getSpecialLabel(winfo, cc, value); + label = getSpecialLabel(flys, cc, value); } creator.addAttr(itemElement, "label", label, true); @@ -131,7 +128,7 @@ protected static String getLabel( - WINFOArtifact winfo, + D4EArtifact winfo, CallContext cc, String raw ) { @@ -167,7 +164,7 @@ protected static String getSpecialLabel( - WINFOArtifact winfo, + D4EArtifact winfo, CallContext cc, String raw ) { @@ -250,12 +247,12 @@ String name, CallContext context ){ - WINFOArtifact winfo = (WINFOArtifact) artifact; + D4EArtifact flys = (D4EArtifact) artifact; - double[] minmaxW = determineMinMaxW(winfo); - double[] minmaxWFree = determineMinMaxWFree(winfo); - double[] minmaxQ = determineMinMaxQAtGauge(winfo); - double[] minmaxQFree = determineMinMaxQ(winfo); + double[] minmaxW = determineMinMaxW(flys); + double[] minmaxWFree = determineMinMaxWFree(flys); + double[] minmaxQ = determineMinMaxQAtGauge(flys); + double[] minmaxQFree = determineMinMaxQ(flys); if (name.equals("wq_from")) { Element minW = createItem(cr, new String[] { @@ -400,7 +397,7 @@ * * @return the min and max W values for the current gauge. */ - protected double[] determineMinMaxW(WINFOArtifact winfo) { + protected double[] determineMinMaxW(D4EArtifact winfo) { log.debug("WQSelect.determineCurrentGauge"); RangeAccess rangeAccess = new RangeAccess(winfo); @@ -425,22 +422,24 @@ * * @return the min and max W values. */ - protected double[] determineMinMaxWFree(WINFOArtifact winfo) { + protected double[] determineMinMaxWFree(D4EArtifact winfo) { log.debug("WQSelect.determineMinMaxWFree"); WstValueTable valueTable = WstValueTableFactory.getTable( RiverUtils.getRiver(winfo)); + ComputationRangeAccess access = new ComputationRangeAccess(winfo); + double[] minmaxW = null; if(valueTable != null) { double[] km = null; - if(new RangeAccess(winfo).isRange()) { - km = winfo.getFromToStep(); + if(access.isRange()) { + km = access.getFromToStep(); // Use the start km to determine the min max values. minmaxW = valueTable.getMinMaxW(km[0]); } else { - km = winfo.getKms(); + km = access.getKms(); minmaxW = valueTable.getMinMaxW(km[0]); } } @@ -459,7 +458,7 @@ * * @return the min and max Q values for the current gauge. */ - protected double[] determineMinMaxQAtGauge(WINFOArtifact winfo) { + protected double[] determineMinMaxQAtGauge(D4EArtifact winfo) { log.debug("WQSelect.determineMinMaxQAtGauge"); RangeAccess rangeAccess = new RangeAccess(winfo); @@ -488,21 +487,23 @@ * * @return the min and max Q values for the current kilometer range. */ - protected double[] determineMinMaxQ(WINFOArtifact winfo) { + protected double[] determineMinMaxQ(D4EArtifact winfo) { log.debug("WQSelect.determineMinMaxQ"); WstValueTable valueTable = WstValueTableFactory.getTable( RiverUtils.getRiver(winfo)); + ComputationRangeAccess access = new ComputationRangeAccess(winfo); + double[] minmaxQ = null; if(valueTable != null) { double[] km = null; - if(new RangeAccess(winfo).isRange()) { - km = winfo.getFromToStep(); + if(access.isRange()) { + km = new ComputationRangeAccess(winfo).getFromToStep(); minmaxQ = valueTable.getMinMaxQ(km[0], km[1], km[2]); } else { - km = winfo.getKms(); + km = access.getKms(); minmaxQ = valueTable.getMinMaxQ(km[0]); for (int i = 1; i < km.length; i++) { double[] tmp = valueTable.getMinMaxQ(km[i]); @@ -527,7 +528,7 @@ { log.debug("WQSelect.validate"); - WINFOArtifact flys = (WINFOArtifact) artifact; + D4EArtifact flys = (D4EArtifact) artifact; StateData data = getData(flys, WQ_SELECTION); boolean isRange = data != null @@ -567,7 +568,7 @@ } - protected boolean validateSingle(WINFOArtifact artifact) + protected boolean validateSingle(D4EArtifact artifact) throws IllegalArgumentException { log.debug("WQSelect.validateSingle"); @@ -623,7 +624,7 @@ } - protected boolean validateRange(WINFOArtifact artifact) + protected boolean validateRange(D4EArtifact artifact) throws IllegalArgumentException { log.debug("WQSelect.validateRange"); @@ -685,7 +686,7 @@ * @return true, if everything was fine, otherwise an exception is thrown. */ protected boolean validateGaugeW( - WINFOArtifact artifact, + D4EArtifact artifact, double from, double to, double step) @@ -711,7 +712,7 @@ * @return true, if everything was fine, otherwise an exception is thrown. */ protected boolean validateGaugeQ( - WINFOArtifact artifact, + D4EArtifact artifact, double from, double to, double step) @@ -737,7 +738,7 @@ * @return true, if everything was fine, otherwise an exception is thrown. */ protected boolean validateFreeQ( - WINFOArtifact artifact, + D4EArtifact artifact, double from, double to, double step) @@ -763,7 +764,7 @@ * @return true, if everything was fine, otherwise an exception is thrown. */ protected boolean validateFreeW( - WINFOArtifact artifact, + D4EArtifact artifact, double from, double to, double step) diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/resources/messages.properties --- a/artifacts/src/main/resources/messages.properties Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/src/main/resources/messages.properties Tue Feb 27 18:06:52 2018 +0100 @@ -788,7 +788,15 @@ help.state.sinfo.calculation_mode=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.calculation_mode state.sinfo.distance_only = Range selection -help.state.sinfo.distance_only=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only +help.state.sinfo.distance_only = ${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only + +state.sinfo.distance = Choose the range +help.state.sinfo.distance = ${help.url}/OnlineHilfe/help.state.sinfo.distance + +help.state.sinfo.wq=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.wq + +state.sinfo.transport_bodies_heights=Transportk\u00f6rperh\u00f6hen +help.state.sinfo.transport_bodies_heights=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.transport_bodies_heights state.sinfo.waterlevel_soundings_select= Chosen Differences help.state.sinfo.waterlevel_soundings_select=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.waterlevel_soundings_select diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/resources/messages_de.properties --- a/artifacts/src/main/resources/messages_de.properties Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/src/main/resources/messages_de.properties Tue Feb 27 18:06:52 2018 +0100 @@ -794,7 +794,15 @@ help.state.sinfo.calculation_mode=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.calculation_mode state.sinfo.distance_only = Wahl der Berechnungsstrecke -help.state.sinfo.distance_only=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only +help.state.sinfo.distance_only = ${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only + +state.sinfo.distance = Wahl der Berechnungsstrecke +help.state.sinfo.distance = ${help.url}/OnlineHilfe/help.state.sinfo.distance + +help.state.sinfo.wq=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.wq + +state.sinfo.transport_bodies_heights=Transportk\u00f6rperh\u00f6hen +help.state.sinfo.transport_bodies_heights=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.transport_bodies_heights state.sinfo.waterlevel_soundings_select= Ausgew\u00e4hlte Differenzen help.state.sinfo.waterlevel_soundings_select=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.waterlevel_soundings_select diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/resources/messages_de_DE.properties --- a/artifacts/src/main/resources/messages_de_DE.properties Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/src/main/resources/messages_de_DE.properties Tue Feb 27 18:06:52 2018 +0100 @@ -792,7 +792,15 @@ help.state.sinfo.calculation_mode=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.calculation_mode state.sinfo.distance_only = Wahl der Berechnungsstrecke -help.state.sinfo.distance_only=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only +help.state.sinfo.distance_only = ${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only + +state.sinfo.distance = Wahl der Berechnungsstrecke +help.state.sinfo.distance = ${help.url}/OnlineHilfe/help.state.sinfo.distance + +help.state.sinfo.wq=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.wq + +state.sinfo.transport_bodies_heights=Transportk\u00f6rperh\u00f6hen +help.state.sinfo.transport_bodies_heights=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.transport_bodies_heights state.sinfo.waterlevel_soundings_select= Ausgew\u00e4hlte Differenzen help.state.sinfo.waterlevel_soundings_select=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.waterlevel_soundings_select diff -r 924cd9943337 -r e3519c3e7a0a artifacts/src/main/resources/messages_en.properties --- a/artifacts/src/main/resources/messages_en.properties Mon Feb 26 18:10:03 2018 +0100 +++ b/artifacts/src/main/resources/messages_en.properties Tue Feb 27 18:06:52 2018 +0100 @@ -789,7 +789,15 @@ help.state.sinfo.calculation_mode=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.calculation_mode state.sinfo.distance_only = Range selection -help.state.sinfo.distance_only=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only +help.state.sinfo.distance_only = ${help.url}/OnlineHilfe/SINFO#help.state.sinfo.distance_only + +state.sinfo.distance = Choose the range +help.state.sinfo.distance = ${help.url}/OnlineHilfe/help.state.sinfo.distance + +help.state.sinfo.wq=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.wq + +state.sinfo.transport_bodies_heights=Transportk\u00f6rperh\u00f6hen +help.state.sinfo.transport_bodies_heights=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.transport_bodies_heights state.sinfo.waterlevel_soundings_select= Chosen Differences help.state.sinfo.waterlevel_soundings_select=${help.url}/OnlineHilfe/SINFO#help.state.sinfo.waterlevel_soundings_select