diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodQProcessor.java @ 9631:6ecd1a28017f

Nachtrag Pos. 20: Q theme for height chart added, calculator corrected (rows for km without any infrastructure)
author mschaefer
date Tue, 15 Oct 2019 12:26:13 +0200
parents
children 9c07a33c2d62
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/FloodQProcessor.java	Tue Oct 15 12:26:13 2019 +0200
@@ -0,0 +1,86 @@
+/** 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 java.util.HashSet;
+import java.util.Set;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.common.AbstractCalculationResult;
+import org.dive4elements.river.artifacts.common.AbstractProcessor;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.flood_duration.FloodDurationCalculationResult.ValueGetter;
+import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.process.QOutProcessor;
+import org.dive4elements.river.themes.ThemeDocument;
+
+/**
+ * Processor to generate the facet and data series of mainvalue discharges
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public final class FloodQProcessor extends AbstractProcessor {
+
+    private static final String FACET_MAIN_VALUE_Q_DESCRIPTION = "mainvalue.q.description";
+
+    public static final String FACET_MAIN_VALUE_Q = "mainvalue.q";
+
+    private static final String I18N_AXIS_LABEL = QOutProcessor.I18N_LONGITUDINAL_LABEL;
+
+    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
+
+    static {
+        HANDLED_FACET_TYPES.add(FACET_MAIN_VALUE_Q);
+    }
+
+    public FloodQProcessor() {
+        super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
+    }
+
+    public static Facet createMainValueQFacet(final CallContext context, final String hash, final String id, final FloodDurationCalculationResult result,
+            final int facetIndex, final int resultIndex, final int dataIndex) {
+        final String description = Resources.getMsg(context.getMeta(), FACET_MAIN_VALUE_Q_DESCRIPTION, FACET_MAIN_VALUE_Q_DESCRIPTION,
+                result.getWaterlevelLabel(dataIndex));
+
+        return new FloodDurationFacet(facetIndex, resultIndex, dataIndex, FACET_MAIN_VALUE_Q, description, ComputeType.ADVANCE, I18N_AXIS_LABEL, hash, id);
+    }
+
+    @Override
+    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
+
+        final String facetName = bundle.getFacetName();
+        if (FACET_MAIN_VALUE_Q.contentEquals(facetName)) {
+
+            final AbstractCalculationResult data = getResult(generator, bundle);
+
+            final FloodDurationFacet facet = (FloodDurationFacet) bundle.getFacet();
+            final int index = facet.getWaterlevelIndex();
+
+            if (data instanceof FloodDurationCalculationResult) {
+                final FloodDurationCalculationResult.ValueGetter valuegetter = new ValueGetter() {
+                    @Override
+                    public double getValue(final DurationWaterlevel waterlevel) {
+                        return waterlevel.getDischarge();
+                    }
+                };
+                final double[][] points = ((FloodDurationCalculationResult) data).getMainValueDurationPoints(valuegetter, index);
+                return buildSeriesForPoints(points, generator, bundle, theme, visible, null);
+            }
+        }
+
+        final String error = String.format("Unknown facet name: %s", facetName);
+        throw new UnsupportedOperationException(error);
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org