Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java @ 4232:b3aa91e45010
Implemented the Q evaluation mode for historical discharge calculations.
Added the calculation itself, created new facets, added themes and improved the chart generator
to support the new facets.
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 24 Oct 2012 07:25:35 +0200 |
parents | 0e5544c54be8 |
children | b195fede1c3b |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java Tue Oct 23 16:07:39 2012 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java Wed Oct 24 07:25:35 2012 +0200 @@ -25,42 +25,36 @@ /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class HistoricalDischargeCurveGenerator -extends TimeseriesChartGenerator -implements FacetTypes -{ - private static Logger logger = - 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"; - - public static final String I18N_XAXIS_LABEL = - "chart.historical.discharge.xaxis.label"; + private static Logger logger = Logger + .getLogger(HistoricalDischargeCurveGenerator.class); - public static final String I18N_YAXIS_LABEL = - "chart.historical.discharge.yaxis.label"; + public static final String I18N_CHART_TITLE = "chart.historical.discharge.title"; - public static final String I18N_YAXIS_SECOND_LABEL = - "chart.historical.discharge.yaxis.second.label"; + public static final String I18N_CHART_SUBTITLE = "chart.historical.discharge.subtitle"; + 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 = "chart.historical.discharge.yaxis.second.label"; public static enum YAXIS { - Q(0); + W(0), Q(1); + protected int idx; + private YAXIS(int c) { idx = c; } } - @Override protected YAxisWalker getYAxisWalker() { return new YAxisWalker() { + @Override public int length() { return YAXIS.values().length; @@ -74,29 +68,23 @@ }; } - @Override protected String getDefaultChartTitle() { return msg(I18N_CHART_TITLE, I18N_CHART_TITLE); } - @Override protected String getDefaultChartSubtitle() { - FLYSArtifact flys = (FLYSArtifact) master; - Timerange evalTime = - new HistoricalDischargeAccess(flys).getEvaluationTimerange(); + FLYSArtifact flys = (FLYSArtifact) master; + Timerange evalTime = new HistoricalDischargeAccess(flys) + .getEvaluationTimerange(); - Object[] args = new Object[] { - FLYSUtils.getReferenceGaugeName(flys), - evalTime.getStart(), - evalTime.getEnd() - }; + Object[] args = new Object[] { FLYSUtils.getReferenceGaugeName(flys), + evalTime.getStart(), evalTime.getEnd() }; return msg(I18N_CHART_SUBTITLE, "", args); } - @Override protected String getDefaultXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL); @@ -121,88 +109,95 @@ plot.setRangeZeroBaselineVisible(true); } - @Override - public void doOut( - ArtifactAndFacet artifactFacet, - Document theme, - boolean visible - ) { + public void doOut(ArtifactAndFacet artifactFacet, Document theme, + boolean visible) { String name = artifactFacet.getFacetName(); logger.debug("HistoricalDischargeCurveGenerator.doOut: " + name); - logger.debug("Theme description is: " + artifactFacet.getFacetDescription()); - + logger.debug("Theme description is: " + + artifactFacet.getFacetDescription()); if (name.equals(HISTORICAL_DISCHARGE_Q)) { - doHistoricalDischargeOut( + doHistoricalDischargeOutQ( (FLYSArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), - artifactFacet.getFacetDescription(), - theme, - visible); + artifactFacet.getFacetDescription(), theme, visible); } - else if (name.equals(HISTORICAL_DISCHARGE_Q_DIFF)) { - doHistoricalDischargeDifferenceOut( + else if (name.equals(HISTORICAL_DISCHARGE_W)) { + doHistoricalDischargeOutW( (FLYSArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), - artifactFacet.getFacetDescription(), - theme, - visible); + artifactFacet.getFacetDescription(), theme, visible); + } + else if (name.equals(HISTORICAL_DISCHARGE_Q_DIFF)) { + doHistoricalDischargeDifferenceOutQ( + (FLYSArtifact) artifactFacet.getArtifact(), + artifactFacet.getData(context), + artifactFacet.getFacetDescription(), theme, visible); + } + else if (name.equals(HISTORICAL_DISCHARGE_W_DIFF)) { + doHistoricalDischargeDifferenceOutW( + (FLYSArtifact) artifactFacet.getArtifact(), + artifactFacet.getData(context), + artifactFacet.getFacetDescription(), theme, visible); } else if (FacetTypes.IS.MANUALPOINTS(name)) { - doPoints (artifactFacet.getData(context), - artifactFacet, - theme, visible, YAXIS.Q.idx); + doPoints(artifactFacet.getData(context), artifactFacet, theme, + visible, YAXIS.Q.idx); } - // TODO ADD THE CASE FOR DISPLAYING W VALUES else { - logger.warn("doOut(): unknown facet name: " + name); - return; + logger.warn("doOut(): unknown facet name: " + name); + return; } } - - protected void doHistoricalDischargeOut( - FLYSArtifact artifact, - Object data, - String desc, - Document theme, - boolean visible) - { + protected void doHistoricalDischargeOutQ(FLYSArtifact artifact, + Object data, String desc, Document theme, boolean visible) { logger.debug("doHistoricalDischargeOut(): description = " + desc); WQTimerange wqt = (WQTimerange) data; - TimeSeriesCollection tsc = newTimeSeriesCollection( - wqt.getTimeranges(), - wqt.getQs(), - theme, - desc); + TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), + wqt.getQs(), theme, desc); - addAxisDataset(tsc, 0, visible); + addAxisDataset(tsc, YAXIS.Q.idx, visible); } + protected void doHistoricalDischargeOutW(FLYSArtifact artifact, + Object data, String desc, Document theme, boolean visible) { + logger.debug("doHistoricalDischargeOut(): description = " + desc); - protected void doHistoricalDischargeDifferenceOut( - FLYSArtifact artifact, - Object data, - String desc, - Document theme, - boolean visible - ) { + WQTimerange wqt = (WQTimerange) data; + + TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), + wqt.getWs(), theme, desc); + + addAxisDataset(tsc, YAXIS.W.idx, visible); + } + + protected void doHistoricalDischargeDifferenceOutQ(FLYSArtifact artifact, + Object data, String desc, Document theme, boolean visible) { logger.debug("doHistoricalDischargeDifferenceOut: desc = " + desc); HistoricalWQTimerange wqt = (HistoricalWQTimerange) data; - TimeSeriesCollection tsc = newTimeSeriesCollection( - wqt.getTimeranges(), - wqt.getDiffs(), - theme, - desc); + TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), + wqt.getDiffs(), theme, desc); - addAxisDataset(tsc, 0, visible); + addAxisDataset(tsc, YAXIS.Q.idx, visible); } + protected void doHistoricalDischargeDifferenceOutW(FLYSArtifact artifact, + Object data, String desc, Document theme, boolean visible) { + logger.debug("doHistoricalDischargeDifferenceOut: desc = " + desc); + + HistoricalWQTimerange wqt = (HistoricalWQTimerange) data; + + TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), + wqt.getDiffs(), theme, desc); + + addAxisDataset(tsc, YAXIS.W.idx, visible); + } /** * Creates a new TimeSeriesCollection with a single TimeSeries. The @@ -211,15 +206,11 @@ * looks like a "step chart". */ protected TimeSeriesCollection newTimeSeriesCollection( - Timerange[] timeranges, - double[] values, - Document theme, - String desc - ) { + Timerange[] timeranges, double[] values, Document theme, String desc) { logger.debug("Create new TimeSeriesCollection for: " + desc); TimeSeriesCollection tsc = new TimeSeriesCollection(); - TimeSeries series = new StyledTimeSeries(desc, theme); + TimeSeries series = new StyledTimeSeries(desc, theme); for (int i = 0, n = timeranges.length; i < n; i++) { RegularTimePeriod[] rtp = newRegularTimePeriod(timeranges[i]); @@ -249,22 +240,19 @@ return tsc; } - /** * Creates an array that consists of two <i>Minute</i> periods [start, end]. - * - * @param timerange Supports start and end time. - * + * + * @param timerange + * Supports start and end time. + * * @return an array with two <i>Minute</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); + Date end = new Date(timerange.getEnd() - 1000 * 60 * 60 * 24); - return new RegularTimePeriod[] { - new Day(start), - new Day(end) - }; + return new RegularTimePeriod[] { new Day(start), new Day(end) }; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :