changeset 9514:ee6508687e3f

Added default vegetation zones tzo iota result map.
author gernotbelger
date Mon, 01 Oct 2018 13:03:42 +0200
parents 1722727803f7
children 4efaa2622c43
files artifacts/doc/conf/artifacts/uinfo.xml artifacts/doc/conf/themes.xml artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/UINFOArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/PredefinedVegetationZonesArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationResults.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCrossSectionIndexData.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineState.java artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCrossSectionProcessor.java artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java
diffstat 10 files changed, 63 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/artifacts/uinfo.xml	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/doc/conf/artifacts/uinfo.xml	Mon Oct 01 13:03:42 2018 +0200
@@ -156,6 +156,7 @@
             <facet name="uinfo_facet_salix_waterlevel_mw_cross_section_water_line" description="Waterlevels used during salix line calculation" />
             <facet name="uinfo_facet_salix_waterlevel_mhw_cross_section_water_line" description="Waterlevels used during salix line calculation" />
             <facet name="uinfo_facet_salix_waterlevel_hw5_cross_section_water_line" description="Waterlevels used during salix line calculation" />
+            <facet name="uinfo_facet_default_vegetation_zones_cross_section" description="Standard Vegetation Zones" />
 
             <facet name="cross_section" description="facet.cross_section" />
             <facet name="area" description="an area" />
--- a/artifacts/doc/conf/themes.xml	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/doc/conf/themes.xml	Mon Oct 01 13:03:42 2018 +0200
@@ -494,6 +494,7 @@
         
         <mapping from="uinfo_salix_line.manualpoints" to="ManualPoints"/>
         <mapping from="uinfo_facet_vegetation_zones_cross_section" to="VegetationZonesCrossSection"/>
+        <mapping from="uinfo_facet_default_vegetation_zones_cross_section" to="VegetationZonesCrossSection"/>
         
         <mapping from="bundu_facet_channelmin" to="BunduChannel"/>
         <mapping from="bundu_facet_bedheight" to="BunduBed"/>
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/UINFOArtifact.java	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/UINFOArtifact.java	Mon Oct 01 13:03:42 2018 +0200
@@ -112,14 +112,12 @@
 
     @Override
     public double getWaterLevel(final ComputeType type, final String hash, final String stateId, final double currentKm, final Serializable waterLineIndex,
-            final double nextKm,
-            final double prevKm,
-            final CallContext context) {
+            final double nextKm, final double prevKm, final CallContext context) {
 
         final CalculationResult res = (CalculationResult) this.compute(context, hash, stateId, type, false);
         final Object data = res.getData();
         if (data instanceof SalixLineCalculationResults)
-            return ((SalixLineCalculationResults) data).getCrossSectionLine(currentKm, waterLineIndex, nextKm, prevKm, context);
+            return ((SalixLineCalculationResults) data).getCrossSectionLine(currentKm, waterLineIndex, nextKm, prevKm);
 
         throw new IllegalStateException("Cross section stuff should only happen for salix line");
     }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/PredefinedVegetationZonesArtifact.java	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/PredefinedVegetationZonesArtifact.java	Mon Oct 01 13:03:42 2018 +0200
@@ -23,7 +23,6 @@
 import org.dive4elements.river.artifacts.AbstractStaticStateArtifact;
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.model.FacetTypes;
-import org.dive4elements.river.artifacts.resources.Resources;
 import org.dive4elements.river.artifacts.states.StaticState;
 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
 import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZonesCrossSectionProcessor;
@@ -42,8 +41,6 @@
     /** Artifact name. */
     private static final String NAME = "predefined_vegetation_zones";
 
-    private static final String DEFAULT_VEGZONES_DESCRIPTION = "uinfo_facet_vegetation_default_zones_cross_section.description";
-
     private static final String STATIC_STATE_NAME = "state.predefined_vegetation_zones.static";
 
     static {
@@ -95,10 +92,8 @@
 
         addStringData(UINFOArtifact.FIELD_VEGZONES, vegZoneData);
 
-        final String seriesName = Resources.getMsg(callMeta, DEFAULT_VEGZONES_DESCRIPTION);
-
         final List<Facet> facets = new ArrayList<>(1);
-        facets.add(VegetationZonesCrossSectionProcessor.createVegetationZonesCrossSectionFacet(seriesName));
+        facets.add(VegetationZonesCrossSectionProcessor.createDefaultVegetationZonesCrossSectionFacet(callMeta));
         addFacets(STATIC_STATE_NAME, facets);
     }
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationResults.java	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationResults.java	Mon Oct 01 13:03:42 2018 +0200
@@ -12,7 +12,6 @@
 import java.io.Serializable;
 
 import org.apache.commons.lang.math.DoubleRange;
-import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.common.AbstractCalculationResults;
 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
 
@@ -27,10 +26,9 @@
         super(calcModeLabel, user, river, calcRange);
     }
 
-    public double getCrossSectionLine(final double currentKm, final Serializable waterLineIndex, final double nextKm, final double prevKm,
-            final CallContext context) {
+    public double getCrossSectionLine(final double currentKm, final Serializable waterLineIndex, final double nextKm, final double prevKm) {
 
         final SalixLineCrossSectionIndexData indexData = (SalixLineCrossSectionIndexData) waterLineIndex;
-        return indexData.getCrossSectionLine(this, currentKm, nextKm, prevKm, context);
+        return indexData.getCrossSectionLine(this, currentKm, nextKm, prevKm);
     }
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java	Mon Oct 01 13:03:42 2018 +0200
@@ -177,28 +177,4 @@
         noScen.add(null);
         return noScen;
     }
-
-    // /**
-    // * Find and return a height (iota, w main value) of a station in a previously calculated result
-    // */
-    // public double fetchStationHeight(final double station, final AbstractResultType resultType,
-    // final SalixLineCalculationResult result) {
-    //
-    // // Search the station in the previously calculated result rows
-    // final ResultRow stationRow = searchStation(station, result.getRows());
-    // if (stationRow != null)
-    // return stationRow.getDoubleValue(resultType);
-    // return Double.NaN;
-    // }
-
-    // /**
-    // * Searches the row of a station in a result rows collection
-    // */
-    // private ResultRow searchStation(final double station, final Collection<ResultRow> rows) {
-    // for (final ResultRow row : rows) {
-    // if (row.getDoubleValue(GeneralResultType.station) > station + 0.0001)
-    // return row;
-    // }
-    // return null;
-    // }
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCrossSectionIndexData.java	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCrossSectionIndexData.java	Mon Oct 01 13:03:42 2018 +0200
@@ -11,8 +11,6 @@
 
 import java.io.Serializable;
 
-import org.dive4elements.artifacts.CallContext;
-
 /**
  * The 'index' that tells the cross section facet which of my result are to be fetched as a cross section line.
  *
@@ -68,8 +66,7 @@
         this.waterlevel = waterlevel;
     }
 
-    public double getCrossSectionLine(final SalixLineCalculationResults results, final double currentKm, final double nextKm, final double prevKm,
-            final CallContext context) {
+    public double getCrossSectionLine(final SalixLineCalculationResults results, final double currentKm, final double nextKm, final double prevKm) {
 
         final SalixLineCalculationResult result = results.getResults().get(this.resultIndex);
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineState.java	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineState.java	Mon Oct 01 13:03:42 2018 +0200
@@ -25,6 +25,7 @@
 import org.dive4elements.river.artifacts.states.DefaultState;
 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
 import org.dive4elements.river.artifacts.uinfo.salix.SalixLineCrossSectionIndexData.SalixWaterlevel;
+import org.dive4elements.river.artifacts.uinfo.vegetationzones.VegetationZonesCrossSectionProcessor;
 
 /**
  * @author Domenico Nardi Tironi
@@ -84,6 +85,10 @@
         int facetIndex = 0;
 
         if (!resultList.isEmpty()) {
+
+            /* we know there is exactly one result */
+            final SalixLineCalculationResult result = resultList.get(0);
+
             facets.add(SalixLineProcessor.createSalixLineFilteredFacet(context, hash, stateId, facetIndex++, 0));
             facets.add(SalixLineProcessor.createSalixLineRawFacet(context, hash, stateId, facetIndex++, 0));
             facets.add(SalixLineProcessor.createSalixMnwMwFilteredFacet(context, hash, stateId, facetIndex++, 0));
@@ -91,15 +96,12 @@
             facets.add(SalixLineProcessor.createSalixRankFacet(context, hash, stateId, facetIndex++, 0));
 
             facets.add(SalixLineProcessor.createSalixCrossSectionFacet(context, type, hash, stateId, facetIndex++));
-
-            final SalixLineCalculationResult result = resultList.get(0);
+            facets.add(VegetationZonesCrossSectionProcessor.createDefaultVegetationZonesCrossSectionFacet(context.getMeta()));
 
             for (int i = 0; i <= result.getScenarioCount() - 1; i++) {
                 final String scenarioLabel = result.getScenarioLabel(i);
 
                 final String sublabel = Resources.getMsg(context.getMeta(), "uinfo_salix_scenario_deltaw", "uinfo_salix_scenario_deltaw", scenarioLabel);
-                // REMARK: using data index as facetIndex, as we know there is only one result of this type. Else we should just
-                // increment
                 facets.add(SalixLineProcessor.createSalixScenarioFilteredFacet(context, hash, stateId, i, 0, facetIndex++, sublabel));
                 facets.add(SalixLineProcessor.createSalixScenarioRawFacet(context, hash, stateId, i, 0, facetIndex++, sublabel));
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCrossSectionProcessor.java	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCrossSectionProcessor.java	Mon Oct 01 13:03:42 2018 +0200
@@ -18,13 +18,14 @@
 import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.artifacts.DataProvider;
 import org.dive4elements.river.artifacts.D4EArtifact;
-import org.dive4elements.river.artifacts.common.AbstractProcessor;
+import org.dive4elements.river.artifacts.access.RiverAccess;
 import org.dive4elements.river.artifacts.model.CrossSectionFacetUtils;
 import org.dive4elements.river.artifacts.model.river.MainWstValuesCalculator;
+import org.dive4elements.river.artifacts.resources.Resources;
 import org.dive4elements.river.exports.CrossSectionGenerator;
-import org.dive4elements.river.exports.DiagramGenerator;
 import org.dive4elements.river.jfree.StripedAreaDataset;
 import org.dive4elements.river.jfree.StripedAreaDataset.Stripe;
 import org.dive4elements.river.model.FastCrossSectionLine;
@@ -35,17 +36,25 @@
  * @author Domenico Nardi Tironi
  *
  */
-public class VegetationZonesCrossSectionProcessor extends AbstractProcessor {
+public final class VegetationZonesCrossSectionProcessor {
 
     private static final String MAIN_VALUE_MQ = "mq";
 
-    public static final String FACET_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_vegetation_zones_cross_section";
+    private static final String FACET_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_vegetation_zones_cross_section";
 
+    private static final String FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_default_vegetation_zones_cross_section";
+
+    private static final String DEFAULT_VEGZONES_DESCRIPTION = "uinfo_facet_vegetation_default_zones_cross_section.description";
 
     private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
 
     static {
         HANDLED_FACET_TYPES.add(FACET_VEGETATION_ZONES_CROSS_SECTION);
+        HANDLED_FACET_TYPES.add(FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION);
+    }
+
+    public static final boolean canHandle(final String facettype) {
+        return HANDLED_FACET_TYPES.contains(facettype);
     }
 
     public static Facet createVegetationZonesCrossSectionFacet(final String description) {
@@ -53,6 +62,13 @@
         return new VegetationZonesCrossSectionFacet(FACET_VEGETATION_ZONES_CROSS_SECTION, description);
     }
 
+    public static Facet createDefaultVegetationZonesCrossSectionFacet(final CallMeta callMeta) {
+
+        final String description = Resources.getMsg(callMeta, DEFAULT_VEGZONES_DESCRIPTION);
+
+        return new VegetationZonesCrossSectionFacet(FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION, description);
+    }
+
     public static void generateSeries(final CrossSectionGenerator generator, final ArtifactAndFacet bundle, final CallContext context,
             final ThemeDocument theme, final boolean visible) {
 
@@ -62,27 +78,39 @@
             return;
         final double currentStation = crossSection.getKm();
 
+        final RiverAccess rAccess = new RiverAccess((D4EArtifact) bundle.getArtifact());
+        final River river = rAccess.getRiver();
+
+        final List<VegetationZoneServerClientXChange> zones = findZonesData(bundle, context, river);
+
+        final StripedAreaDataset dataset = new StripedAreaDataset(theme);
+
+        for (final VegetationZoneServerClientXChange zone : zones) {
+
+            final double lower = uefdToHeight(context, river, currentStation, zone.getLowerFromTo());
+            final double upper = uefdToHeight(context, river, currentStation, zone.getUpperFromTo());
+
+            final Color color = Color.decode(zone.getHexColor());
+            final String label = String.format("%s (%dd-%dd)", zone.getZoneName(), zone.getLowerFromTo(), zone.getUpperFromTo());
+            dataset.addStripe(new Stripe(label, color, lower, upper));
+        }
+
+        generator.addAxisDataset(dataset, 0, visible);
+        return;
+    }
+
+    private static List<VegetationZoneServerClientXChange> findZonesData(final ArtifactAndFacet bundle, final CallContext context, final River river) {
+
         if (bundle.getFacetName().equals(FACET_VEGETATION_ZONES_CROSS_SECTION)) {
 
-            final StripedAreaDataset dataset = new StripedAreaDataset(theme);
-
             final Artifact artifact = bundle.getArtifact();
             final VegetationzonesAccess vAccess = new VegetationzonesAccess((D4EArtifact) artifact);
-            final River river = vAccess.getRiver();
-            final List<VegetationZoneServerClientXChange> zones = VegetationZoneServerClientXChange.parse(vAccess.getVegZones());
-
-            for (final VegetationZoneServerClientXChange zone : zones) {
+            return VegetationZoneServerClientXChange.parse(vAccess.getVegZones());
+        }
 
-                final double lower = uefdToHeight(context, river, currentStation, zone.getLowerFromTo());
-                final double upper = uefdToHeight(context, river, currentStation, zone.getUpperFromTo());
+        if (bundle.getFacetName().equals(FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION)) {
 
-                final Color color = Color.decode(zone.getHexColor());
-                final String label = String.format("%s (%dd-%dd)", zone.getZoneName(), zone.getLowerFromTo(), zone.getUpperFromTo());
-                dataset.addStripe(new Stripe(label, color, lower, upper));
-            }
-
-            generator.addAxisDataset(dataset, 0, visible);
-            return;
+            return VegetationZoneServerClientXChange.getStandardList(river, context);
         }
 
         throw new UnsupportedOperationException();
@@ -90,6 +118,7 @@
 
     private static double uefdToHeight(final CallContext context, final River river, final double station, final int uefd) {
 
+        // FIXME: cache me
         final MainWstValuesCalculator mainWstValues = MainWstValuesCalculator.forRiver(context, river, null, MAIN_VALUE_MQ);
 
         final double mw = mainWstValues.interpolateW(station, MAIN_VALUE_MQ);
@@ -101,16 +130,4 @@
         final double dgm = Math.exp((uefd - f2) / f1) + mw - 0.5;
         return dgm;
     }
-
-    public VegetationZonesCrossSectionProcessor() {
-        super(CrossSectionGenerator.I18N_YAXIS_LABEL, HANDLED_FACET_TYPES);
-
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
-        throw new UnsupportedOperationException();
-    }
-
 }
\ No newline at end of file
--- a/artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java	Mon Oct 01 13:01:55 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java	Mon Oct 01 13:03:42 2018 +0200
@@ -308,7 +308,7 @@
                     attr,
                     visible);
         }
-        else if (name.equals(VegetationZonesCrossSectionProcessor.FACET_VEGETATION_ZONES_CROSS_SECTION)) {
+        else if (VegetationZonesCrossSectionProcessor.canHandle(name)) {
             VegetationZonesCrossSectionProcessor.generateSeries(this, artifactFacet, context, attr, visible);
         }
         else if (FacetTypes.IS.MANUALLINE(name)) {

http://dive4elements.wald.intevation.org