diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationAccess.java @ 9067:2ed3824a3d53

sinfo access collision, floodDuration
author gernotbelger
date Mon, 14 May 2018 14:59:10 +0200
parents
children 611a523fc42f
line wrap: on
line diff
--- /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

http://dive4elements.wald.intevation.org