changeset 2715:250a370c377d

Added chart generator for middle bed height charts. flys-artifacts/trunk@4441 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 18 May 2012 11:58:38 +0000
parents 2952f6dee5cf
children 150dcdefeb7d
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/minfo.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java flys-artifacts/src/main/java/de/intevation/flys/exports/MiddleBedHeightGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/MiddleBedHeightInfoGenerator.java
diffstat 9 files changed, 362 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri May 18 10:51:04 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri May 18 11:58:38 2012 +0000
@@ -1,3 +1,24 @@
+2012-05-18  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java,
+	  doc/conf/artifacts/minfo.xml: Adapted facets for middle bed height. We
+	  now distinguish between epochs and singles.
+
+	* doc/conf/conf.xml: Registered new output generator for middle bed height.
+
+	* doc/conf/themes.xml: Added new themes for middle bed height epoch and
+	  single curves.
+
+	* src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightCalculation.java:
+	  Take the km range into account.
+
+	* src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java:
+	  Create facets for single and epochs.
+
+	* src/main/java/de/intevation/flys/exports/MiddleBedHeightInfoGenerator.java,
+	* src/main/java/de/intevation/flys/exports/MiddleBedHeightGenerator.java:
+	  Chart and info generator for middle bed height charts.
+
 2012-05-18  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightData.java:
--- a/flys-artifacts/doc/conf/artifacts/minfo.xml	Fri May 18 10:51:04 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/minfo.xml	Fri May 18 11:58:38 2012 +0000
@@ -87,7 +87,8 @@
             <outputmodes>
                 <outputmode name="bedheight_middle" description="output.bedheight_middle" mime-type="image/png" type="chart">
                     <facets>
-                        <!-- TODO -->
+                        <facet name="bedheight_middle.single" description="A facet for total channels"/>
+                        <facet name="bedheight_middle.epoch" description="A facet for total channels"/>
                     </facets>
                 </outputmode>
                 <outputmode name="bedheight_middle_export" description="output.bedheight_middle_export" mime-type="text/plain" type="export">
--- a/flys-artifacts/doc/conf/conf.xml	Fri May 18 10:51:04 2012 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Fri May 18 11:58:38 2012 +0000
@@ -230,6 +230,8 @@
         <output-generator name="flow_velocity">de.intevation.flys.exports.FlowVelocityGenerator</output-generator>
         <output-generator name="flow_velocity_chartinfo">de.intevation.flys.exports.FlowVelocityInfoGenerator</output-generator>
         <output-generator name="flow_velocity_export">de.intevation.flys.exports.FlowVelocityExporter</output-generator>
+        <output-generator name="bedheight_middle">de.intevation.flys.exports.MiddleBedHeightGenerator</output-generator>
+        <output-generator name="bedheight_middle_chartinfo">de.intevation.flys.exports.MiddleBedHeightInfoGenerator</output-generator>
         <output-generator name="bedheight_middle_export">de.intevation.flys.exports.MiddleBedHeightExporter</output-generator>
         <!-- Error report generators. -->
         <output-generator name="discharge_longitudinal_section_report">de.intevation.flys.exports.ReportGenerator</output-generator>
--- a/flys-artifacts/doc/conf/themes.xml	Fri May 18 10:51:04 2012 +0000
+++ b/flys-artifacts/doc/conf/themes.xml	Fri May 18 11:58:38 2012 +0000
@@ -1001,6 +1001,29 @@
 
 
     <!--
+         MIDDLE BED HEIGHT
+    -->
+    <theme name="MiddleBedHeightSingle">
+        <inherits>
+            <inherit from="HiddenColorLines"/>
+            <inherit from="MinMaxPoints"/>
+        </inherits>
+        <fields>
+            <field name="linecolor" type="Color" display="Linienfarbe" default="204, 204, 204"/>
+        </fields>
+    </theme>
+
+    <theme name="MiddleBedHeightEpoch">
+        <inherits>
+            <inherit from="FlowVelocityVMainChannel"/>
+        </inherits>
+        <fields>
+            <field name="linecolor" type="Color" display="Linienfarbe" default="0, 0, 102"/>
+        </fields>
+    </theme>
+
+
+    <!--
       Mappings are following now. A mapping maps between a name of a facet
       and a theme.
       Always the first matching mapping is taken, so consider putting most
@@ -1124,5 +1147,8 @@
         <mapping from="flow_velocity.totalchannel" to="FlowVelocityVTotalChannel"/>
         <mapping from="flow_velocity.mainchannel" to="FlowVelocityVMainChannel"/>
         <mapping from="flow_velocity.tau" to="FlowVelocityTau"/>
+        <mapping from="bedheight_middle.single" to="MiddleBedHeightSingle"/>
+        <mapping from="bedheight_middle.epoch" to="MiddleBedHeightEpoch"/>
+
     </mappings>
 </themes>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Fri May 18 10:51:04 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Fri May 18 11:58:38 2012 +0000
@@ -38,6 +38,10 @@
         public static boolean T(String type) {
             return type.equals(FLOW_VELOCITY_TAU);
         }
+        public static boolean H(String type) {
+            return type.equals(MIDDLE_BED_HEIGHT_SINGLE)
+                || type.equals(MIDDLE_BED_HEIGHT_EPOCH);
+        }
         public static boolean MANUALPOINTS(String type) {
             return type.endsWith("manualpoints");
         }
@@ -148,6 +152,8 @@
     String FLOW_VELOCITY_TAU          = "flow_velocity.tau";
     String FLOW_VELOCITY_ANNOTATION   = "flow_velocity.annotation";
 
-    String MIDDLE_BED_HEIGHT = "bedheight_middle.height";
+    String MIDDLE_BED_HEIGHT_SINGLE     = "bedheight_middle.single";
+    String MIDDLE_BED_HEIGHT_EPOCH      = "bedheight_middle.epoch";
+    String MIDDLE_BED_HEIGHT_ANNOTATION = "bedheight_middle.annotation";
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightCalculation.java	Fri May 18 10:51:04 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightCalculation.java	Fri May 18 11:58:38 2012 +0000
@@ -92,12 +92,14 @@
     ) {
         logger.info("MiddleBedHeightCalculation.buildCalculationResult");
 
-        int size = singles.size() + epochs.size();
+        int    size = singles.size() + epochs.size();
+        double kmLo = artifact.getDataAsDouble("ld_from");
+        double kmHi = artifact.getDataAsDouble("ld_to");
 
         List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>();
 
         for (BedHeightSingle single: singles) {
-            MiddleBedHeightData d = prepareSingleData(single);
+            MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi);
 
             if (d != null) {
                 data.add(d);
@@ -105,7 +107,7 @@
         }
 
         for (BedHeightEpoch epoch: epochs) {
-            MiddleBedHeightData d = prepareEpochData(epoch);
+            MiddleBedHeightData d = prepareEpochData(epoch, kmLo, kmHi);
 
             if (d != null) {
                 data.add(d);
@@ -119,10 +121,15 @@
     }
 
 
-    protected MiddleBedHeightData prepareSingleData(BedHeightSingle single) {
+    protected MiddleBedHeightData prepareSingleData(
+        BedHeightSingle single,
+        double kmLo,
+        double kmHi
+    ) {
         logger.debug("Prepare data for single: " + single.getDescription());
 
-        List<BedHeightSingleValue> values = single.getValues();
+        List<BedHeightSingleValue> values =
+            BedHeightSingleValue.getBedHeightSingleValues(single, kmLo, kmHi);
 
         MiddleBedHeightData data = new MiddleBedHeightData(
             single.getYear(),
@@ -145,12 +152,17 @@
     }
 
 
-    protected MiddleBedHeightData prepareEpochData(BedHeightEpoch epoch) {
+    protected MiddleBedHeightData prepareEpochData(
+        BedHeightEpoch epoch,
+        double kmLo,
+        double kmHi
+    ) {
         logger.debug("Prepare data for epoch: " + epoch.getDescription());
 
         TimeInterval ti = epoch.getTimeInterval();
 
-        List<BedHeightEpochValue> values = epoch.getValues();
+        List<BedHeightEpochValue> values =
+            BedHeightEpochValue.getBedHeightEpochValues(epoch, kmLo, kmHi);
 
         MiddleBedHeightData data = new MiddleBedHeightData(
             DateUtils.getYearFromDate(ti.getStartTime()),
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java	Fri May 18 10:51:04 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java	Fri May 18 11:58:38 2012 +0000
@@ -52,14 +52,26 @@
         int    idx = 0;
 
         for (MiddleBedHeightData d: data) {
-            newFacets.add(new MiddleBedHeightFacet(
-                idx,
-                MIDDLE_BED_HEIGHT,
-                buildMiddleBedHeightName(artifact, context, d),
-                ComputeType.ADVANCE,
-                id,
-                hash
-            ));
+            if (d.getStartYear() == d.getEndYear()) {
+                newFacets.add(new MiddleBedHeightFacet(
+                    idx,
+                    MIDDLE_BED_HEIGHT_SINGLE,
+                    d.getSoundingName(context),
+                    ComputeType.ADVANCE,
+                    id,
+                    hash
+                ));
+            }
+            else {
+                newFacets.add(new MiddleBedHeightFacet(
+                    idx,
+                    MIDDLE_BED_HEIGHT_EPOCH,
+                    d.getSoundingName(context),
+                    ComputeType.ADVANCE,
+                    id,
+                    hash
+                ));
+            }
 
             idx++;
         }
@@ -77,15 +89,5 @@
 
         return res;
     }
-
-
-    protected String buildMiddleBedHeightName(
-        FLYSArtifact        artifact,
-        CallContext         cc,
-        MiddleBedHeightData data
-    ) {
-        logger.error("TODO: Implement buildMiddleBedHeightName");
-        return "TODO: Implement buildMiddleBedHeightName";
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MiddleBedHeightGenerator.java	Fri May 18 11:58:38 2012 +0000
@@ -0,0 +1,248 @@
+package de.intevation.flys.exports;
+
+import org.apache.log4j.Logger;
+
+import org.jfree.data.xy.XYSeries;
+
+import org.w3c.dom.Document;
+
+import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.MiddleBedHeightData;
+
+import de.intevation.flys.jfree.FLYSAnnotation;
+import de.intevation.flys.jfree.StyledXYSeries;
+
+import de.intevation.flys.utils.FLYSUtils;
+
+
+/**
+ * An OutGenerator that generates middle bed height charts.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class MiddleBedHeightGenerator
+extends      XYChartGenerator
+implements   FacetTypes
+{
+    public enum YAXIS {
+        H(0);
+        protected int idx;
+        private YAXIS(int c) {
+           idx = c;
+        }
+    }
+
+    /** The logger that is used in this generator. */
+    private static Logger logger = Logger.getLogger(MiddleBedHeightGenerator.class);
+
+    /** Key to look up internationalized String for annotations label. */
+    public static final String I18N_ANNOTATIONS_LABEL =
+        "chart.bedheight_middle.annotations.label";
+
+    public static final String I18N_CHART_TITLE =
+        "chart.bedheight_middle.section.title";
+
+    public static final String I18N_CHART_SUBTITLE =
+        "chart.bedheight_middle.section.subtitle";
+
+    public static final String I18N_CHART_SHORT_SUBTITLE =
+        "chart.bedheight_middle.section.shortsubtitle";
+
+    public static final String I18N_XAXIS_LABEL =
+        "chart.bedheight_middle.section.xaxis.label";
+
+    public static final String I18N_YAXIS_LABEL =
+        "chart.bedheight_middle.section.yaxis.label";
+
+    public static final String I18N_CHART_TITLE_DEFAULT  = "Mittlere Sohlöhe";
+    public static final String I18N_XAXIS_LABEL_DEFAULT  = "km";
+    public static final String I18N_YAXIS_LABEL_DEFAULT  = "mittlere Sohlhöhen [müNN]";
+
+
+
+    @Override
+    protected YAxisWalker getYAxisWalker() {
+        return new YAxisWalker() {
+            @Override
+            public int length() {
+                return YAXIS.values().length;
+            }
+
+            @Override
+            public String getId(int idx) {
+                YAXIS[] yaxes = YAXIS.values();
+                return yaxes[idx].toString();
+            }
+        };
+    }
+
+
+    /**
+     * Returns the default title for this chart.
+     *
+     * @return the default title for this chart.
+     */
+    @Override
+    public String getDefaultChartTitle() {
+        Object[] args = new Object[] {
+            getRiverName()
+        };
+
+        return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT, args);
+    }
+
+
+    /**
+     * Get internationalized label for the x axis.
+     */
+    @Override
+    protected String getDefaultXAxisLabel() {
+        FLYSArtifact flys = (FLYSArtifact) master;
+
+        return msg(
+            I18N_XAXIS_LABEL,
+            I18N_XAXIS_LABEL_DEFAULT,
+            new Object[] { FLYSUtils.getRiver(flys).getName() });
+    }
+
+
+    @Override
+    protected String getDefaultYAxisLabel(int index) {
+        String label = "default";
+
+        if (index == YAXIS.H.idx) {
+            label = getHAxisLabel();
+        }
+
+        return label;
+    }
+
+
+    /**
+     * Get internationalized label for the y axis.
+     */
+    protected String getHAxisLabel() {
+        FLYSArtifact flys = (FLYSArtifact) master;
+
+        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
+    }
+
+
+    /**
+     * Produce output.
+     * @param facet current facet.
+     * @param attr  theme for facet
+     */
+    public void doOut(
+        ArtifactAndFacet artifactAndFacet,
+        Document         attr,
+        boolean          visible
+    ) {
+        String name = artifactAndFacet.getFacetName();
+
+        logger.debug("MiddleBedHeightGenerator.doOut: " + name);
+
+        if (name == null) {
+            logger.error("No facet name for doOut(). No output generated!");
+            return;
+        }
+
+        Facet facet = artifactAndFacet.getFacet();
+
+        if (facet == null) {
+            return;
+        }
+
+        if (name.equals(MIDDLE_BED_HEIGHT_SINGLE) || name.equals(MIDDLE_BED_HEIGHT_EPOCH)) {
+            doHeightOut(
+                (MiddleBedHeightData) artifactAndFacet.getData(context),
+                artifactAndFacet,
+                attr,
+                visible);
+        }
+        else if (name.equals(MIDDLE_BED_HEIGHT_ANNOTATION)) {
+            doAnnotations(
+                (FLYSAnnotation) artifactAndFacet.getData(context),
+                 artifactAndFacet,
+                 attr,
+                 visible);
+        }
+        else if (FacetTypes.IS.AREA(name)) {
+            doArea(
+                artifactAndFacet.getData(context),
+                artifactAndFacet,
+                attr,
+                visible);
+        }
+        else if (FacetTypes.IS.MANUALPOINTS(name)) {
+            doPoints(
+                artifactAndFacet.getData(context),
+                artifactAndFacet,
+                attr,
+                visible,
+                YAXIS.H.idx);
+        }
+        else {
+            logger.warn("Unknown facet name: " + name);
+            return;
+        }
+    }
+
+
+    /**
+     * @param data A data object
+     * @param facet The facet. This facet does NOT support any data objects. Use
+     * FLYSArtifact.getNativeFacet() instead to retrieve a Facet which supports
+     * data.
+     * @param theme The theme that contains styling information.
+     * @param visible The visibility of the curve.
+     */
+    protected void doHeightOut(
+        MiddleBedHeightData data,
+        ArtifactAndFacet    aandf,
+        Document            theme,
+        boolean             visible
+    ) {
+        logger.debug("MiddleBedHeightGenerator.doMainChannelOut");
+
+        XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
+
+        StyledSeriesBuilder.addPoints(series, data.getMiddleHeightsPoints(), true);
+
+        addAxisSeries(series, YAXIS.H.idx, visible);
+    }
+
+
+    /** Look up the axis identifier for a given facet type. */
+    public int axisIdxForFacet(String facetName) {
+        if (FacetTypes.IS.H(facetName)) {
+            return YAXIS.H.idx;
+        }
+        else {
+            logger.warn("Could not find axis for facet " + facetName);
+            return YAXIS.H.idx;
+        }
+    }
+
+
+    /**
+     * Do Area out.
+     * @param theme styling information.
+     * @param visible whether or not visible.
+     */
+    protected void doArea(
+        Object     o,
+        ArtifactAndFacet aandf,
+        Document   theme,
+        boolean    visible
+    ) {
+        logger.debug("FlowVelocityGenerator.doArea");
+        logger.warn("TODO: Implement FlowVelocityGenerator.doArea");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MiddleBedHeightInfoGenerator.java	Fri May 18 11:58:38 2012 +0000
@@ -0,0 +1,17 @@
+package de.intevation.flys.exports;
+
+
+/**
+ * A ChartInfoGenerator that generates meta information for specific
+ * middle bed height curves.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class MiddleBedHeightInfoGenerator
+extends      ChartInfoGenerator
+{
+    public MiddleBedHeightInfoGenerator() {
+        super(new MiddleBedHeightGenerator());
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org