changeset 7153:fdf2d31b8955

Add SedimentLoadProcessor
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 25 Sep 2013 17:40:43 +0200
parents 8c169743f4d0
children e7690ed60b4c
files artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java
diffstat 1 files changed, 98 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java	Wed Sep 25 17:40:43 2013 +0200
@@ -0,0 +1,98 @@
+/* Copyright (C) 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.exports.process;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.jfree.data.xy.XYSeries;
+import org.dive4elements.river.artifacts.D4EArtifact;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.access.SedimentLoadAccess;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.themes.ThemeDocument;
+
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoad;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction;
+
+public class SedimentLoadProcessor extends DefaultProcessor {
+
+    private final static Logger logger =
+            Logger.getLogger(SedimentLoadProcessor.class);
+
+    public static final String I18N_YAXIS_LABEL_1 =
+        "chart.sedimentload.ls.yaxis.label.tpera";
+    public static final String I18N_YAXIS_LABEL_2 =
+        "chart.sedimentload.ls.yaxis.label.m3pera";
+    public static final String I18N_YAXIS_LABEL_DEFAULT_1 = "[t/a]";
+    public static final String I18N_YAXIS_LABEL_DEFAULT_2 = "[m\u00b3/a]";
+
+    @Override
+    public void doOut(
+            DiagramGenerator generator,
+            ArtifactAndFacet bundle,
+            ThemeDocument    theme,
+            boolean          visible) {
+        CallContext context = generator.getCallContext();
+        XYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
+                theme);
+        Object data = bundle.getData(context);
+        String facetName = bundle.getFacetName();
+        double [][] points;
+
+        if (FacetTypes.IS.SEDIMENT_LOAD(facetName)) {
+            points = (double[][]) data;
+        } else if (FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facetName)) {
+            SedimentLoad load = (SedimentLoad) data;
+            Set<Double> kms = load.getKms();
+            points = new double[2][kms.size()];
+            int counter = 0;
+            for (Double km: kms) {
+                SedimentLoadFraction fraction = load.getFraction(km);
+                points[0][counter] = km;
+                points[1][counter] = fraction.getUnknown();
+                counter++;
+            }
+        } else {
+            logger.error("Unknown facet name: " + facetName);
+            return;
+        }
+        StyledSeriesBuilder.addPoints(series, points, true);
+
+        generator.addAxisSeries(series, axisName, visible);
+    }
+
+    @Override
+    public boolean canHandle(String facettype) {
+        return FacetTypes.IS.SEDIMENT_LOAD(facettype) ||
+            FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facettype);
+    }
+
+    @Override
+    public String getAxisLabel(DiagramGenerator generator) {
+        SedimentLoadAccess slaccess =
+            new SedimentLoadAccess((D4EArtifact) generator.getMaster());
+        String unit = slaccess.getUnit();
+        if (unit != null && unit.equals("m3_per_a")) {
+            return generator.msg(I18N_YAXIS_LABEL_2, I18N_YAXIS_LABEL_DEFAULT_2);
+        }
+        else {
+            return generator.msg(I18N_YAXIS_LABEL_1, I18N_YAXIS_LABEL_DEFAULT_1);
+        }
+    }
+}
+
+
+

http://dive4elements.wald.intevation.org