Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
9311:7c7f73e5e01e | 9312:740d65e4aa14 |
---|---|
9 package org.dive4elements.river.exports; | 9 package org.dive4elements.river.exports; |
10 | 10 |
11 import java.util.Date; | 11 import java.util.Date; |
12 | 12 |
13 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
14 | |
15 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | 14 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
16 import org.dive4elements.artifacts.CallContext; | 15 import org.dive4elements.artifacts.CallContext; |
17 import org.dive4elements.river.artifacts.D4EArtifact; | 16 import org.dive4elements.river.artifacts.D4EArtifact; |
18 | |
19 import org.dive4elements.river.artifacts.access.HistoricalDischargeAccess; | 17 import org.dive4elements.river.artifacts.access.HistoricalDischargeAccess; |
20 | |
21 import org.dive4elements.river.artifacts.model.FacetTypes; | 18 import org.dive4elements.river.artifacts.model.FacetTypes; |
22 import org.dive4elements.river.artifacts.model.HistoricalWQTimerange; | 19 import org.dive4elements.river.artifacts.model.HistoricalWQTimerange; |
23 import org.dive4elements.river.artifacts.model.Timerange; | 20 import org.dive4elements.river.artifacts.model.Timerange; |
24 import org.dive4elements.river.artifacts.model.WQTimerange; | 21 import org.dive4elements.river.artifacts.model.WQTimerange; |
25 | |
26 import org.dive4elements.river.jfree.StyledTimeSeries; | 22 import org.dive4elements.river.jfree.StyledTimeSeries; |
27 | |
28 import org.dive4elements.river.themes.ThemeDocument; | 23 import org.dive4elements.river.themes.ThemeDocument; |
29 import org.dive4elements.river.utils.RiverUtils; | 24 import org.dive4elements.river.utils.RiverUtils; |
30 | |
31 import org.jfree.chart.plot.XYPlot; | 25 import org.jfree.chart.plot.XYPlot; |
32 | |
33 import org.jfree.data.general.SeriesException; | 26 import org.jfree.data.general.SeriesException; |
34 | |
35 import org.jfree.data.time.FixedMillisecond; | 27 import org.jfree.data.time.FixedMillisecond; |
36 import org.jfree.data.time.RegularTimePeriod; | 28 import org.jfree.data.time.RegularTimePeriod; |
37 import org.jfree.data.time.TimeSeries; | 29 import org.jfree.data.time.TimeSeries; |
38 import org.jfree.data.time.TimeSeriesCollection; | 30 import org.jfree.data.time.TimeSeriesCollection; |
39 | 31 |
40 | |
41 /** | 32 /** |
42 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 33 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
43 */ | 34 */ |
44 public class HistoricalDischargeCurveGenerator extends TimeseriesChartGenerator | 35 public class HistoricalDischargeCurveGenerator extends TimeseriesChartGenerator implements FacetTypes { |
45 implements FacetTypes { | 36 |
46 | 37 private static Logger log = Logger.getLogger(HistoricalDischargeCurveGenerator.class); |
47 private static Logger log = Logger | 38 |
48 .getLogger(HistoricalDischargeCurveGenerator.class); | 39 public static final String I18N_CHART_TITLE = "chart.historical.discharge.title"; |
49 | 40 |
50 public static final String I18N_CHART_TITLE = | 41 public static final String I18N_CHART_SUBTITLE = "chart.historical.discharge.subtitle"; |
51 "chart.historical.discharge.title"; | 42 |
52 | 43 public static final String I18N_XAXIS_LABEL = "chart.historical.discharge.xaxis.label"; |
53 public static final String I18N_CHART_SUBTITLE = | 44 |
54 "chart.historical.discharge.subtitle"; | 45 public static final String I18N_YAXIS_LABEL = "chart.historical.discharge.yaxis.label"; |
55 | 46 |
56 public static final String I18N_XAXIS_LABEL = | 47 public static final String I18N_YAXIS_SECOND_LABEL = "common.export.csv.header.q"; |
57 "chart.historical.discharge.xaxis.label"; | |
58 | |
59 public static final String I18N_YAXIS_LABEL = | |
60 "chart.historical.discharge.yaxis.label"; | |
61 | |
62 public static final String I18N_YAXIS_SECOND_LABEL = | |
63 "chart.historical.discharge.yaxis.second.label"; | |
64 | 48 |
65 public static enum YAXIS { | 49 public static enum YAXIS { |
66 W(0), Q(1); | 50 W(0), Q(1); |
67 | 51 |
68 protected int idx; | 52 protected int idx; |
69 | 53 |
70 private YAXIS(int c) { | 54 private YAXIS(final int c) { |
71 idx = c; | 55 this.idx = c; |
72 } | 56 } |
73 } | 57 } |
74 | 58 |
75 @Override | 59 @Override |
76 protected YAxisWalker getYAxisWalker() { | 60 protected YAxisWalker getYAxisWalker() { |
80 public int length() { | 64 public int length() { |
81 return YAXIS.values().length; | 65 return YAXIS.values().length; |
82 } | 66 } |
83 | 67 |
84 @Override | 68 @Override |
85 public String getId(int idx) { | 69 public String getId(final int idx) { |
86 YAXIS[] yaxes = YAXIS.values(); | 70 final YAXIS[] yaxes = YAXIS.values(); |
87 return yaxes[idx].toString(); | 71 return yaxes[idx].toString(); |
88 } | 72 } |
89 }; | 73 }; |
90 } | 74 } |
91 | 75 |
94 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE); | 78 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE); |
95 } | 79 } |
96 | 80 |
97 @Override | 81 @Override |
98 protected String getDefaultChartSubtitle(final CallContext context) { | 82 protected String getDefaultChartSubtitle(final CallContext context) { |
99 D4EArtifact flys = getArtifact(); | 83 final D4EArtifact flys = getArtifact(); |
100 Timerange evalTime = new HistoricalDischargeAccess(flys) | 84 final Timerange evalTime = new HistoricalDischargeAccess(flys).getEvaluationTimerange(); |
101 .getEvaluationTimerange(); | 85 |
102 | 86 final Object[] args = new Object[] { RiverUtils.getReferenceGaugeName(flys), evalTime.getStart(), evalTime.getEnd() }; |
103 Object[] args = new Object[] { RiverUtils.getReferenceGaugeName(flys), | |
104 evalTime.getStart(), evalTime.getEnd() }; | |
105 | 87 |
106 return msg(I18N_CHART_SUBTITLE, "", args); | 88 return msg(I18N_CHART_SUBTITLE, "", args); |
107 } | 89 } |
108 | 90 |
109 @Override | 91 @Override |
110 protected String getDefaultXAxisLabel(final CallContext context) { | 92 protected String getDefaultXAxisLabel(final CallContext context) { |
111 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL); | 93 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL); |
112 } | 94 } |
113 | 95 |
114 @Override | 96 @Override |
115 protected String getDefaultYAxisLabel(int pos) { | 97 protected String getDefaultYAxisLabel(final int pos) { |
116 if (pos == 0) { | 98 if (pos == 0) { |
117 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL); | 99 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL); |
118 } | 100 } else if (pos == 1) { |
119 else if (pos == 1) { | |
120 return msg(I18N_YAXIS_SECOND_LABEL, I18N_YAXIS_SECOND_LABEL); | 101 return msg(I18N_YAXIS_SECOND_LABEL, I18N_YAXIS_SECOND_LABEL); |
121 } | 102 } else { |
122 else { | |
123 return "NO TITLE FOR Y AXIS: " + pos; | 103 return "NO TITLE FOR Y AXIS: " + pos; |
124 } | 104 } |
125 } | 105 } |
126 | 106 |
127 @Override | 107 @Override |
128 protected void adjustPlot(XYPlot plot) { | 108 protected void adjustPlot(final XYPlot plot) { |
129 super.adjustPlot(plot); | 109 super.adjustPlot(plot); |
130 plot.setRangeZeroBaselineVisible(true); | 110 plot.setRangeZeroBaselineVisible(true); |
131 } | 111 } |
132 | 112 |
133 @Override | 113 @Override |
134 public void doOut(ArtifactAndFacet artifactFacet, ThemeDocument theme, | 114 public void doOut(final ArtifactAndFacet artifactFacet, final ThemeDocument theme, final boolean visible) { |
135 boolean visible) { | 115 final String name = artifactFacet.getFacetName(); |
136 String name = artifactFacet.getFacetName(); | |
137 log.debug("HistoricalDischargeCurveGenerator.doOut: " + name); | 116 log.debug("HistoricalDischargeCurveGenerator.doOut: " + name); |
138 log.debug("Theme description is: " | 117 log.debug("Theme description is: " + artifactFacet.getFacetDescription()); |
139 + artifactFacet.getFacetDescription()); | |
140 | 118 |
141 final CallContext context = getContext(); | 119 final CallContext context = getContext(); |
142 | 120 |
143 if (name.equals(HISTORICAL_DISCHARGE_Q)) { | 121 if (name.equals(HISTORICAL_DISCHARGE_Q)) { |
144 doHistoricalDischargeOutQ( | 122 doHistoricalDischargeOutQ((D4EArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(), theme, |
145 (D4EArtifact) artifactFacet.getArtifact(), | 123 visible); |
146 artifactFacet.getData(context), | 124 } else if (name.equals(HISTORICAL_DISCHARGE_W)) { |
147 artifactFacet.getFacetDescription(), theme, visible); | 125 doHistoricalDischargeOutW((D4EArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(), theme, |
148 } | 126 visible); |
149 else if (name.equals(HISTORICAL_DISCHARGE_W)) { | 127 } else if (name.equals(HISTORICAL_DISCHARGE_Q_DIFF)) { |
150 doHistoricalDischargeOutW( | 128 doHistoricalDischargeDifferenceOutQ((D4EArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(), |
151 (D4EArtifact) artifactFacet.getArtifact(), | 129 theme, visible); |
152 artifactFacet.getData(context), | 130 } else if (name.equals(HISTORICAL_DISCHARGE_W_DIFF)) { |
153 artifactFacet.getFacetDescription(), theme, visible); | 131 doHistoricalDischargeDifferenceOutW((D4EArtifact) artifactFacet.getArtifact(), artifactFacet.getData(context), artifactFacet.getFacetDescription(), |
154 } | 132 theme, visible); |
155 else if (name.equals(HISTORICAL_DISCHARGE_Q_DIFF)) { | 133 } else if (FacetTypes.IS.MANUALPOINTS(name)) { |
156 doHistoricalDischargeDifferenceOutQ( | 134 final HistoricalDischargeAccess.EvaluationMode mode = new HistoricalDischargeAccess((D4EArtifact) getMaster()).getEvaluationMode(); |
157 (D4EArtifact) artifactFacet.getArtifact(), | 135 final int axis = mode == HistoricalDischargeAccess.EvaluationMode.W ? YAXIS.Q.idx : YAXIS.W.idx; |
158 artifactFacet.getData(context), | 136 |
159 artifactFacet.getFacetDescription(), theme, visible); | 137 doPoints(artifactFacet.getData(context), artifactFacet, theme, visible, axis); |
160 } | 138 } else { |
161 else if (name.equals(HISTORICAL_DISCHARGE_W_DIFF)) { | |
162 doHistoricalDischargeDifferenceOutW( | |
163 (D4EArtifact) artifactFacet.getArtifact(), | |
164 artifactFacet.getData(context), | |
165 artifactFacet.getFacetDescription(), theme, visible); | |
166 } | |
167 else if (FacetTypes.IS.MANUALPOINTS(name)) { | |
168 HistoricalDischargeAccess.EvaluationMode mode = | |
169 new HistoricalDischargeAccess( | |
170 (D4EArtifact)getMaster()).getEvaluationMode(); | |
171 int axis = mode == HistoricalDischargeAccess.EvaluationMode.W | |
172 ? YAXIS.Q.idx | |
173 : YAXIS.W.idx; | |
174 | |
175 doPoints(artifactFacet.getData(context), artifactFacet, theme, | |
176 visible, axis); | |
177 } | |
178 else { | |
179 log.warn("doOut(): unknown facet name: " + name); | 139 log.warn("doOut(): unknown facet name: " + name); |
180 return; | 140 return; |
181 } | 141 } |
182 } | 142 } |
183 | 143 |
184 protected void doHistoricalDischargeOutQ(D4EArtifact artifact, | 144 protected void doHistoricalDischargeOutQ(final D4EArtifact artifact, final Object data, final String desc, final ThemeDocument theme, |
185 Object data, String desc, ThemeDocument theme, boolean visible) { | 145 final boolean visible) { |
186 log.debug("doHistoricalDischargeOut(): description = " + desc); | 146 log.debug("doHistoricalDischargeOut(): description = " + desc); |
187 | 147 |
188 WQTimerange wqt = (WQTimerange) data; | 148 final WQTimerange wqt = (WQTimerange) data; |
189 | 149 |
190 TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), | 150 final TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), wqt.getQs(), theme, desc); |
191 wqt.getQs(), theme, desc); | |
192 | 151 |
193 addAxisDataset(tsc, YAXIS.Q.idx, visible); | 152 addAxisDataset(tsc, YAXIS.Q.idx, visible); |
194 } | 153 } |
195 | 154 |
196 protected void doHistoricalDischargeOutW(D4EArtifact artifact, | 155 protected void doHistoricalDischargeOutW(final D4EArtifact artifact, final Object data, final String desc, final ThemeDocument theme, |
197 Object data, String desc, ThemeDocument theme, boolean visible) { | 156 final boolean visible) { |
198 log.debug("doHistoricalDischargeOut(): description = " + desc); | 157 log.debug("doHistoricalDischargeOut(): description = " + desc); |
199 | 158 |
200 WQTimerange wqt = (WQTimerange) data; | 159 final WQTimerange wqt = (WQTimerange) data; |
201 | 160 |
202 TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), | 161 final TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), wqt.getWs(), theme, desc); |
203 wqt.getWs(), theme, desc); | |
204 | 162 |
205 addAxisDataset(tsc, YAXIS.W.idx, visible); | 163 addAxisDataset(tsc, YAXIS.W.idx, visible); |
206 } | 164 } |
207 | 165 |
208 protected void doHistoricalDischargeDifferenceOutQ(D4EArtifact artifact, | 166 protected void doHistoricalDischargeDifferenceOutQ(final D4EArtifact artifact, final Object data, final String desc, final ThemeDocument theme, |
209 Object data, String desc, ThemeDocument theme, boolean visible) { | 167 final boolean visible) { |
210 log.debug("doHistoricalDischargeDifferenceOut: desc = " + desc); | 168 log.debug("doHistoricalDischargeDifferenceOut: desc = " + desc); |
211 | 169 |
212 HistoricalWQTimerange wqt = (HistoricalWQTimerange) data; | 170 final HistoricalWQTimerange wqt = (HistoricalWQTimerange) data; |
213 | 171 |
214 TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), | 172 final TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), wqt.getDiffs(), theme, desc); |
215 wqt.getDiffs(), theme, desc); | |
216 | 173 |
217 addAxisDataset(tsc, YAXIS.Q.idx, visible); | 174 addAxisDataset(tsc, YAXIS.Q.idx, visible); |
218 } | 175 } |
219 | 176 |
220 protected void doHistoricalDischargeDifferenceOutW(D4EArtifact artifact, | 177 protected void doHistoricalDischargeDifferenceOutW(final D4EArtifact artifact, final Object data, final String desc, final ThemeDocument theme, |
221 Object data, String desc, ThemeDocument theme, boolean visible) { | 178 final boolean visible) { |
222 log.debug("doHistoricalDischargeDifferenceOut: desc = " + desc); | 179 log.debug("doHistoricalDischargeDifferenceOut: desc = " + desc); |
223 | 180 |
224 HistoricalWQTimerange wqt = (HistoricalWQTimerange) data; | 181 final HistoricalWQTimerange wqt = (HistoricalWQTimerange) data; |
225 | 182 |
226 TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), | 183 final TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(), wqt.getDiffs(), theme, desc); |
227 wqt.getDiffs(), theme, desc); | |
228 | 184 |
229 addAxisDataset(tsc, YAXIS.W.idx, visible); | 185 addAxisDataset(tsc, YAXIS.W.idx, visible); |
230 } | 186 } |
231 | 187 |
232 /** | 188 /** |
233 * Creates a new TimeSeriesCollection with a single TimeSeries. The | 189 * Creates a new TimeSeriesCollection with a single TimeSeries. The |
234 * TimeSeries will consist of two RegularTimePeriods for each W/Q value | 190 * TimeSeries will consist of two RegularTimePeriods for each W/Q value |
235 * provided by <i>wqt</i>. This has the effect, that the line in the chart | 191 * provided by <i>wqt</i>. This has the effect, that the line in the chart |
236 * looks like a "step chart". | 192 * looks like a "step chart". |
237 */ | 193 */ |
238 protected TimeSeriesCollection newTimeSeriesCollection( | 194 protected TimeSeriesCollection newTimeSeriesCollection(final Timerange[] timeranges, final double[] values, final ThemeDocument theme, final String desc) { |
239 Timerange[] timeranges, | |
240 double[] values, | |
241 ThemeDocument theme, | |
242 String desc | |
243 ) { | |
244 log.debug("Create new TimeSeriesCollection for: " + desc); | 195 log.debug("Create new TimeSeriesCollection for: " + desc); |
245 | 196 |
246 TimeSeriesCollection tsc = new TimeSeriesCollection(); | 197 final TimeSeriesCollection tsc = new TimeSeriesCollection(); |
247 TimeSeries series = new StyledTimeSeries(desc, theme); | 198 final TimeSeries series = new StyledTimeSeries(desc, theme); |
248 | 199 |
249 for (int i = 0, n = timeranges.length; i < n; i++) { | 200 for (int i = 0, n = timeranges.length; i < n; i++) { |
250 RegularTimePeriod[] rtp = newRegularTimePeriod(timeranges[i]); | 201 final RegularTimePeriod[] rtp = newRegularTimePeriod(timeranges[i]); |
251 | 202 |
252 try { | 203 try { |
253 if (Double.isNaN(values[i])) { | 204 if (Double.isNaN(values[i])) { |
254 log.warn("Skip TimePeriod because value is NaN."); | 205 log.warn("Skip TimePeriod because value is NaN."); |
255 continue; | 206 continue; |
262 log.debug("added Item to TimeSeries:"); | 213 log.debug("added Item to TimeSeries:"); |
263 log.debug(" TimePeriod: " + rtp[0] + " - " + rtp[1]); | 214 log.debug(" TimePeriod: " + rtp[0] + " - " + rtp[1]); |
264 log.debug(" Value: " + values[i]); | 215 log.debug(" Value: " + values[i]); |
265 } | 216 } |
266 } | 217 } |
267 catch (SeriesException se) { | 218 catch (final SeriesException se) { |
268 log.warn("Error while adding TimePeriod: " + se); | 219 log.warn("Error while adding TimePeriod: " + se); |
269 } | 220 } |
270 } | 221 } |
271 | 222 |
272 tsc.addSeries(series); | 223 tsc.addSeries(series); |
281 * @param timerange | 232 * @param timerange |
282 * Supports start and end time. | 233 * Supports start and end time. |
283 * | 234 * |
284 * @return an array with two <i>FixedMillisecond</i> periods [start, end]. | 235 * @return an array with two <i>FixedMillisecond</i> periods [start, end]. |
285 */ | 236 */ |
286 protected RegularTimePeriod[] newRegularTimePeriod(Timerange timerange) { | 237 protected RegularTimePeriod[] newRegularTimePeriod(final Timerange timerange) { |
287 Date start = new Date(timerange.getStart()); | 238 final Date start = new Date(timerange.getStart()); |
288 Date end = new Date(timerange.getEnd() - 1000 * 60 * 60 * 24); | 239 final Date end = new Date(timerange.getEnd() - 1000 * 60 * 60 * 24); |
289 | 240 |
290 return new RegularTimePeriod[] { | 241 return new RegularTimePeriod[] { new FixedMillisecond(start), new FixedMillisecond(end) }; |
291 new FixedMillisecond(start), | |
292 new FixedMillisecond(end) }; | |
293 } | 242 } |
294 } | 243 } |
295 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 244 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |