changeset 7984:cf674b03901a facet-metadata

Bedheight facet now returns double[][]. Removed obsolete processor code.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 01 Jul 2014 13:27:53 +0200
parents 62befca02480
children 10debf4b82be
files artifacts/src/main/java/org/dive4elements/river/artifacts/BedHeightsArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedHeightFacet.java artifacts/src/main/java/org/dive4elements/river/exports/process/BedHeightProcessor.java
diffstat 3 files changed, 62 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/BedHeightsArtifact.java	Tue Jul 01 13:25:46 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/BedHeightsArtifact.java	Tue Jul 01 13:27:53 2014 +0200
@@ -24,6 +24,7 @@
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.minfo.BedHeightFacet;
 import org.dive4elements.river.artifacts.model.minfo.BedHeightFactory;
+import org.dive4elements.river.artifacts.model.minfo.BedHeightSoundingWidthFacet;
 import org.dive4elements.river.artifacts.states.StaticState;
 
 import org.dive4elements.river.artifacts.resources.Resources;
@@ -102,30 +103,32 @@
                     type = "singlevalues";
                     facetType = BEDHEIGHT_SOUNDING_WIDTH;
                 }
-                // e.g. 'single'
+                addStringData("height_id", parts[2]);
+                addStringData("time", parts[3]);
+                addStringData("type", type);
                 String btype = type;
                 int hId = Integer.parseInt(parts[2]);
-                if (name.equals("bedheight")) {
-                    addStringData("type", type);
-                    addStringData("height_id", parts[2]);
-                    addStringData("time", parts[3]);
-                }
+
                 if (type.equals("singlevalues")) {
                     btype = "single";
                 }
 
                 String bedHName = BedHeightFactory.getHeightName(btype, hId);
 
+                Facet facet =  null;
                 if (facetType.equals(BEDHEIGHT_SOUNDING_WIDTH)) {
                     bedHName = Resources.getMsg(
                         callMeta,
                         "facet.bedheight.sounding_width",
                         "facet.bedheight.sounding_widt",
                         new Object[] { bedHName });
+                    facet = new BedHeightSoundingWidthFacet(facetType, bedHName);
+                }
+                else {
+                    facet = new BedHeightFacet(
+                        facetType, bedHName, type);
                 }
 
-                Facet facet = new BedHeightFacet(
-                        facetType, bedHName, type);
 
                 ArrayList<Facet> facets = new ArrayList<Facet>(1);
                 facets.add(facet);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedHeightFacet.java	Tue Jul 01 13:25:46 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedHeightFacet.java	Tue Jul 01 13:27:53 2014 +0200
@@ -8,6 +8,11 @@
 
 package org.dive4elements.river.artifacts.model.minfo;
 
+import gnu.trove.TDoubleArrayList;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.D4EArtifact;
@@ -21,6 +26,8 @@
 extends      BlackboardDataFacet
 implements   FacetTypes {
 
+    private static final Logger logger = Logger.getLogger(BedHeightFacet.class);
+
     private String type;
 
     public BedHeightFacet(String name, String description, String type) {
@@ -50,18 +57,39 @@
              * @return List of {@link BedHeightSingleValue}s */
             BedHeightSingle single = BedHeightSingle.getBedHeightSingleById(
                     access.getHeightId());
-            return BedHeightSingleValue.getBedHeightSingleValues(single,
+            List<BedHeightSingleValue> bedheightValues =
+                BedHeightSingleValue.getBedHeightSingleValues(
+                    single,
                     access.getFrom(),
                     access.getTo());
+            double[][] values = new double[2][bedheightValues.size()];
+            int i = 0;
+            for (BedHeightSingleValue bedheightValue : bedheightValues) {
+                values[0][i] = bedheightValue.getStation();
+                values[1][i] = bedheightValue.getHeight();
+                i++;
+            }
+            return values;
         }
         else {
             /* Former doc (from BedHeightAccess):
              * Return the {@link BedHeight} at the height_id and time of the artifact
              * @return {@link BedHeight} */
-            return BedHeightFactory.getHeight(
+            BedHeightData data = BedHeightFactory.getHeight(
                 access.getType(),
                 access.getHeightId(),
                 access.getTime());
+            //data.removeNaNs();
+            TDoubleArrayList stations= data.getStations();
+            double[][] values = new double[2][stations.size()];
+            logger.debug("stations: " + stations.size());
+            for (int i = 0; i < stations.size(); i++) {
+                logger.debug("station: " + stations.get(i));
+                values[0][i] = stations.get(i);
+                logger.debug("height: " + data.getHeight(i));
+                values[1][i] = data.getHeight(i);
+            }
+            return values;
         }
     }
 
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/BedHeightProcessor.java	Tue Jul 01 13:25:46 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/BedHeightProcessor.java	Tue Jul 01 13:27:53 2014 +0200
@@ -49,7 +49,9 @@
             ThemeDocument    theme,
             boolean          visible) {
         XYSeries series = prepareSeries(bundle, theme, generator.getCallContext());
-        generator.addAxisSeries(series, axisName, visible);
+        if (series != null) {
+            generator.addAxisSeries(series, axisName, visible);
+        }
     }
 
     @Override
@@ -61,68 +63,36 @@
             int index
     ) {
         XYSeries series = prepareSeries(bundle, theme, generator.getCallContext());
-        generator.addAxisSeries(series, index, visible);
+        if (series != null) {
+            generator.addAxisSeries(series, index, visible);
+        }
     }
 
     /** Prepare an series, independent of axis. */
-    private XYSeries prepareSeries(ArtifactAndFacet bundle,
-        ThemeDocument theme, CallContext context) {
-        Object data = bundle.getData(context);
+    private XYSeries prepareSeries(
+        ArtifactAndFacet bundle,
+        ThemeDocument theme,
+        CallContext context
+    ) {
         Map<String, String> metaData = bundle.getFacet().getMetaData(
             bundle.getArtifact(), context);
         StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(),
                 theme);
         series.putMetaData(metaData, bundle.getArtifact(), context);
         yAxisLabel = metaData.get("Y");
-        if (data instanceof BedDiffYearResult) {
-            BedDiffYearResult bData = (BedDiffYearResult) data;
-
-            double[][] points;
-            String facetType = bundle.getFacetName();
-
-            if (FacetTypes.BED_DIFFERENCE_YEAR_HEIGHT1.equals(facetType) ||
-                FacetTypes.BED_DIFFERENCE_YEAR_HEIGHT1_FILTERED.equals(facetType)) {
-                points = bData.getHeights1Data();
-            } else {
-                points = bData.getHeights2Data();
-            }
-            StyledSeriesBuilder.addPointsFactorY(series,
-                    points,
-                    false,
-                    GAP_TOLERANCE,
-                    1d);
-        } else if (data instanceof BedHeightSingleData) {
-            BedHeightSingleData bData = (BedHeightSingleData)data;
-            double[][] points = new double[][]
-                {bData.getStations().toNativeArray(), bData.getHeights()};
 
-            logger.debug("doBedheightSingleOut");
-            StyledSeriesBuilder.addPointsFactorY(series,
-                    points,
-                    false,
-                    GAP_TOLERANCE,
-                    1d);
+        Object raw = bundle.getData(context);
+        if (!(raw instanceof double[][])) {
+            logger.error("Unkown datatype: " + raw.getClass().getName());
+            return null;
         }
-        else if (data instanceof List<?>) {
-            List<BedHeightSingleValue> bData = (List<BedHeightSingleValue>)data;
-            double[][] points = new double[2][];
-
-            logger.debug("doBedheightSingleValueOut");
 
-            for(int i = 0; i < bData.size(); i++) {
-                BedHeightSingleValue bvalue = bData.get(i);
-                points[0][i] = bvalue.getStation();
-                points[1][i] = bvalue.getHeight();
-            }
-            StyledSeriesBuilder.addPointsFactorY(series,
-                    points,
-                    false,
-                    GAP_TOLERANCE,
-                    1d);
-        }
-        else {
-            logger.error("Unknown data type " + data.getClass());
-        }
+        double[][] data = (double[][])raw;
+        StyledSeriesBuilder.addPointsFactorY(series,
+            data,
+            false,
+            GAP_TOLERANCE,
+            1d);
         return series;
     }
 

http://dive4elements.wald.intevation.org