diff artifacts/src/main/java/org/dive4elements/river/exports/HistoricalDischargeCurveGenerator.java @ 9312:740d65e4aa14

Q [m³/s] one message
author gernotbelger
date Thu, 26 Jul 2018 15:54:20 +0200
parents 1cc7653ca84f
children 9b8e8fc1f408
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/HistoricalDischargeCurveGenerator.java	Thu Jul 26 11:16:06 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/HistoricalDischargeCurveGenerator.java	Thu Jul 26 15:54:20 2018 +0200
@@ -11,64 +11,48 @@
 import java.util.Date;
 
 import org.apache.log4j.Logger;
-
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.D4EArtifact;
-
 import org.dive4elements.river.artifacts.access.HistoricalDischargeAccess;
-
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.HistoricalWQTimerange;
 import org.dive4elements.river.artifacts.model.Timerange;
 import org.dive4elements.river.artifacts.model.WQTimerange;
-
 import org.dive4elements.river.jfree.StyledTimeSeries;
-
 import org.dive4elements.river.themes.ThemeDocument;
 import org.dive4elements.river.utils.RiverUtils;
-
 import org.jfree.chart.plot.XYPlot;
-
 import org.jfree.data.general.SeriesException;
-
 import org.jfree.data.time.FixedMillisecond;
 import org.jfree.data.time.RegularTimePeriod;
 import org.jfree.data.time.TimeSeries;
 import org.jfree.data.time.TimeSeriesCollection;
 
-
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class HistoricalDischargeCurveGenerator extends TimeseriesChartGenerator
-    implements FacetTypes {
-
-    private static Logger log = Logger
-        .getLogger(HistoricalDischargeCurveGenerator.class);
-
-    public static final String I18N_CHART_TITLE =
-        "chart.historical.discharge.title";
+public class HistoricalDischargeCurveGenerator extends TimeseriesChartGenerator implements FacetTypes {
 
-    public static final String I18N_CHART_SUBTITLE =
-        "chart.historical.discharge.subtitle";
+    private static Logger log = Logger.getLogger(HistoricalDischargeCurveGenerator.class);
 
-    public static final String I18N_XAXIS_LABEL =
-        "chart.historical.discharge.xaxis.label";
+    public static final String I18N_CHART_TITLE = "chart.historical.discharge.title";
 
-    public static final String I18N_YAXIS_LABEL =
-        "chart.historical.discharge.yaxis.label";
+    public static final String I18N_CHART_SUBTITLE = "chart.historical.discharge.subtitle";
 
-    public static final String I18N_YAXIS_SECOND_LABEL =
-        "chart.historical.discharge.yaxis.second.label";
+    public static final String I18N_XAXIS_LABEL = "chart.historical.discharge.xaxis.label";
+
+    public static final String I18N_YAXIS_LABEL = "chart.historical.discharge.yaxis.label";
+
+    public static final String I18N_YAXIS_SECOND_LABEL = "common.export.csv.header.q";
 
     public static enum YAXIS {
         W(0), Q(1);
 
         protected int idx;
 
-        private YAXIS(int c) {
-            idx = c;
+        private YAXIS(final int c) {
+            this.idx = c;
         }
     }
 
@@ -82,8 +66,8 @@
             }
 
             @Override
-            public String getId(int idx) {
-                YAXIS[] yaxes = YAXIS.values();
+            public String getId(final int idx) {
+                final YAXIS[] yaxes = YAXIS.values();
                 return yaxes[idx].toString();
             }
         };
@@ -96,12 +80,10 @@
 
     @Override
     protected String getDefaultChartSubtitle(final CallContext context) {
-        D4EArtifact flys = getArtifact();
-        Timerange evalTime = new HistoricalDischargeAccess(flys)
-            .getEvaluationTimerange();
+        final D4EArtifact flys = getArtifact();
+        final Timerange evalTime = new HistoricalDischargeAccess(flys).getEvaluationTimerange();
 
-        Object[] args = new Object[] { RiverUtils.getReferenceGaugeName(flys),
-            evalTime.getStart(), evalTime.getEnd() };
+        final Object[] args = new Object[] { RiverUtils.getReferenceGaugeName(flys), evalTime.getStart(), evalTime.getEnd() };
 
         return msg(I18N_CHART_SUBTITLE, "", args);
     }
@@ -112,119 +94,93 @@
     }
 
     @Override
-    protected String getDefaultYAxisLabel(int pos) {
+    protected String getDefaultYAxisLabel(final int pos) {
         if (pos == 0) {
             return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL);
-        }
-        else if (pos == 1) {
+        } else if (pos == 1) {
             return msg(I18N_YAXIS_SECOND_LABEL, I18N_YAXIS_SECOND_LABEL);
-        }
-        else {
+        } else {
             return "NO TITLE FOR Y AXIS: " + pos;
         }
     }
 
     @Override
-    protected void adjustPlot(XYPlot plot) {
+    protected void adjustPlot(final XYPlot plot) {
         super.adjustPlot(plot);
         plot.setRangeZeroBaselineVisible(true);
     }
 
     @Override
-    public void doOut(ArtifactAndFacet artifactFacet, ThemeDocument theme,
-        boolean visible) {
-        String name = artifactFacet.getFacetName();
+    public void doOut(final ArtifactAndFacet artifactFacet, final ThemeDocument theme, final boolean visible) {
+        final String name = artifactFacet.getFacetName();
         log.debug("HistoricalDischargeCurveGenerator.doOut: " + name);
-        log.debug("Theme description is: "
-            + artifactFacet.getFacetDescription());
+        log.debug("Theme description is: " + artifactFacet.getFacetDescription());
 
         final CallContext context = getContext();
-        
+
         if (name.equals(HISTORICAL_DISCHARGE_Q)) {
-            doHistoricalDischargeOutQ(
-                (D4EArtifact) artifactFacet.getArtifact(),
-                artifactFacet.getData(context),
-                artifactFacet.getFacetDescription(), theme, visible);
-        }
-        else if (name.equals(HISTORICAL_DISCHARGE_W)) {
-            doHistoricalDischargeOutW(
-                (D4EArtifact) artifactFacet.getArtifact(),
-                artifactFacet.getData(context),
-                artifactFacet.getFacetDescription(), theme, visible);
-        }
-        else if (name.equals(HISTORICAL_DISCHARGE_Q_DIFF)) {
-            doHistoricalDischargeDifferenceOutQ(
-                (D4EArtifact) artifactFacet.getArtifact(),
-                artifactFacet.getData(context),
-                artifactFacet.getFacetDescription(), theme, visible);
-        }
-        else if (name.equals(HISTORICAL_DISCHARGE_W_DIFF)) {
-            doHistoricalDischargeDifferenceOutW(
-                (D4EArtifact) artifactFacet.getArtifact(),
-                artifactFacet.getData(context),
-                artifactFacet.getFacetDescription(), theme, visible);
-        }
-        else if (FacetTypes.IS.MANUALPOINTS(name)) {
-            HistoricalDischargeAccess.EvaluationMode mode =
-                new HistoricalDischargeAccess(
-                    (D4EArtifact)getMaster()).getEvaluationMode();
-            int axis = mode == HistoricalDischargeAccess.EvaluationMode.W
-                ? YAXIS.Q.idx
-                : YAXIS.W.idx;
+            doHistoricalDischargeOutQ((D4EArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(), theme,
+                    visible);
+        } else if (name.equals(HISTORICAL_DISCHARGE_W)) {
+            doHistoricalDischargeOutW((D4EArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(), theme,
+                    visible);
+        } else if (name.equals(HISTORICAL_DISCHARGE_Q_DIFF)) {
+            doHistoricalDischargeDifferenceOutQ((D4EArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(),
+                    theme, visible);
+        } else if (name.equals(HISTORICAL_DISCHARGE_W_DIFF)) {
+            doHistoricalDischargeDifferenceOutW((D4EArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(),
+                    theme, visible);
+        } else if (FacetTypes.IS.MANUALPOINTS(name)) {
+            final HistoricalDischargeAccess.EvaluationMode mode = new HistoricalDischargeAccess((D4EArtifact) getMaster()).getEvaluationMode();
+            final int axis = mode == HistoricalDischargeAccess.EvaluationMode.W ? YAXIS.Q.idx : YAXIS.W.idx;
 
-            doPoints(artifactFacet.getData(context), artifactFacet, theme,
-                visible, axis);
-        }
-        else {
+            doPoints(artifactFacet.getData(context), artifactFacet, theme, visible, axis);
+        } else {
             log.warn("doOut(): unknown facet name: " + name);
             return;
         }
     }
 
-    protected void doHistoricalDischargeOutQ(D4EArtifact artifact,
-        Object data, String desc, ThemeDocument theme, boolean visible) {
+    protected void doHistoricalDischargeOutQ(final D4EArtifact artifact, final Object data, final String desc, final ThemeDocument theme,
+            final boolean visible) {
         log.debug("doHistoricalDischargeOut(): description = " + desc);
 
-        WQTimerange wqt = (WQTimerange) data;
+        final WQTimerange wqt = (WQTimerange) data;
 
-        TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(),
-            wqt.getQs(), theme, desc);
+        final TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), wqt.getQs(), theme, desc);
 
         addAxisDataset(tsc, YAXIS.Q.idx, visible);
     }
 
-    protected void doHistoricalDischargeOutW(D4EArtifact artifact,
-        Object data, String desc, ThemeDocument theme, boolean visible) {
+    protected void doHistoricalDischargeOutW(final D4EArtifact artifact, final Object data, final String desc, final ThemeDocument theme,
+            final boolean visible) {
         log.debug("doHistoricalDischargeOut(): description = " + desc);
 
-        WQTimerange wqt = (WQTimerange) data;
+        final WQTimerange wqt = (WQTimerange) data;
 
-        TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(),
-            wqt.getWs(), theme, desc);
+        final TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), wqt.getWs(), theme, desc);
 
         addAxisDataset(tsc, YAXIS.W.idx, visible);
     }
 
-    protected void doHistoricalDischargeDifferenceOutQ(D4EArtifact artifact,
-        Object data, String desc, ThemeDocument theme, boolean visible) {
+    protected void doHistoricalDischargeDifferenceOutQ(final D4EArtifact artifact, final Object data, final String desc, final ThemeDocument theme,
+            final boolean visible) {
         log.debug("doHistoricalDischargeDifferenceOut: desc = " + desc);
 
-        HistoricalWQTimerange wqt = (HistoricalWQTimerange) data;
+        final HistoricalWQTimerange wqt = (HistoricalWQTimerange) data;
 
-        TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(),
-            wqt.getDiffs(), theme, desc);
+        final TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), wqt.getDiffs(), theme, desc);
 
         addAxisDataset(tsc, YAXIS.Q.idx, visible);
     }
 
-    protected void doHistoricalDischargeDifferenceOutW(D4EArtifact artifact,
-        Object data, String desc, ThemeDocument theme, boolean visible) {
+    protected void doHistoricalDischargeDifferenceOutW(final D4EArtifact artifact, final Object data, final String desc, final ThemeDocument theme,
+            final boolean visible) {
         log.debug("doHistoricalDischargeDifferenceOut: desc = " + desc);
 
-        HistoricalWQTimerange wqt = (HistoricalWQTimerange) data;
+        final HistoricalWQTimerange wqt = (HistoricalWQTimerange) data;
 
-        TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(),
-            wqt.getDiffs(), theme, desc);
+        final TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), wqt.getDiffs(), theme, desc);
 
         addAxisDataset(tsc, YAXIS.W.idx, visible);
     }
@@ -235,19 +191,14 @@
      * provided by <i>wqt</i>. This has the effect, that the line in the chart
      * looks like a "step chart".
      */
-    protected TimeSeriesCollection newTimeSeriesCollection(
-        Timerange[] timeranges,
-        double[] values,
-        ThemeDocument theme,
-        String desc
-    ) {
+    protected TimeSeriesCollection newTimeSeriesCollection(final Timerange[] timeranges, final double[] values, final ThemeDocument theme, final String desc) {
         log.debug("Create new TimeSeriesCollection for: " + desc);
 
-        TimeSeriesCollection tsc = new TimeSeriesCollection();
-        TimeSeries series = new StyledTimeSeries(desc, theme);
+        final TimeSeriesCollection tsc = new TimeSeriesCollection();
+        final TimeSeries series = new StyledTimeSeries(desc, theme);
 
         for (int i = 0, n = timeranges.length; i < n; i++) {
-            RegularTimePeriod[] rtp = newRegularTimePeriod(timeranges[i]);
+            final RegularTimePeriod[] rtp = newRegularTimePeriod(timeranges[i]);
 
             try {
                 if (Double.isNaN(values[i])) {
@@ -264,7 +215,7 @@
                     log.debug("   Value:      " + values[i]);
                 }
             }
-            catch (SeriesException se) {
+            catch (final SeriesException se) {
                 log.warn("Error while adding TimePeriod: " + se);
             }
         }
@@ -283,13 +234,11 @@
      *
      * @return an array with two <i>FixedMillisecond</i> periods [start, end].
      */
-    protected RegularTimePeriod[] newRegularTimePeriod(Timerange timerange) {
-        Date start = new Date(timerange.getStart());
-        Date end = new Date(timerange.getEnd() - 1000 * 60 * 60 * 24);
+    protected RegularTimePeriod[] newRegularTimePeriod(final Timerange timerange) {
+        final Date start = new Date(timerange.getStart());
+        final Date end = new Date(timerange.getEnd() - 1000 * 60 * 60 * 24);
 
-        return new RegularTimePeriod[] {
-            new FixedMillisecond(start),
-            new FixedMillisecond(end) };
+        return new RegularTimePeriod[] { new FixedMillisecond(start), new FixedMillisecond(end) };
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org