comparison 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
comparison
equal deleted inserted replaced
4231:adcb8aee1910 4232:b3aa91e45010
23 23
24 24
25 /** 25 /**
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
27 */ 27 */
28 public class HistoricalDischargeCurveGenerator 28 public class HistoricalDischargeCurveGenerator extends TimeseriesChartGenerator
29 extends TimeseriesChartGenerator 29 implements FacetTypes {
30 implements FacetTypes 30
31 { 31 private static Logger logger = Logger
32 private static Logger logger = 32 .getLogger(HistoricalDischargeCurveGenerator.class);
33 Logger.getLogger(HistoricalDischargeCurveGenerator.class); 33
34 34 public static final String I18N_CHART_TITLE = "chart.historical.discharge.title";
35 35
36 public static final String I18N_CHART_TITLE = 36 public static final String I18N_CHART_SUBTITLE = "chart.historical.discharge.subtitle";
37 "chart.historical.discharge.title"; 37
38 38 public static final String I18N_XAXIS_LABEL = "chart.historical.discharge.xaxis.label";
39 public static final String I18N_CHART_SUBTITLE = 39
40 "chart.historical.discharge.subtitle"; 40 public static final String I18N_YAXIS_LABEL = "chart.historical.discharge.yaxis.label";
41 41
42 public static final String I18N_XAXIS_LABEL = 42 public static final String I18N_YAXIS_SECOND_LABEL = "chart.historical.discharge.yaxis.second.label";
43 "chart.historical.discharge.xaxis.label";
44
45 public static final String I18N_YAXIS_LABEL =
46 "chart.historical.discharge.yaxis.label";
47
48 public static final String I18N_YAXIS_SECOND_LABEL =
49 "chart.historical.discharge.yaxis.second.label";
50
51 43
52 public static enum YAXIS { 44 public static enum YAXIS {
53 Q(0); 45 W(0), Q(1);
46
54 protected int idx; 47 protected int idx;
48
55 private YAXIS(int c) { 49 private YAXIS(int c) {
56 idx = c; 50 idx = c;
57 } 51 }
58 } 52 }
59 53
60
61 @Override 54 @Override
62 protected YAxisWalker getYAxisWalker() { 55 protected YAxisWalker getYAxisWalker() {
63 return new YAxisWalker() { 56 return new YAxisWalker() {
57
64 @Override 58 @Override
65 public int length() { 59 public int length() {
66 return YAXIS.values().length; 60 return YAXIS.values().length;
67 } 61 }
68 62
72 return yaxes[idx].toString(); 66 return yaxes[idx].toString();
73 } 67 }
74 }; 68 };
75 } 69 }
76 70
77
78 @Override 71 @Override
79 protected String getDefaultChartTitle() { 72 protected String getDefaultChartTitle() {
80 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE); 73 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE);
81 } 74 }
82 75
83
84 @Override 76 @Override
85 protected String getDefaultChartSubtitle() { 77 protected String getDefaultChartSubtitle() {
86 FLYSArtifact flys = (FLYSArtifact) master; 78 FLYSArtifact flys = (FLYSArtifact) master;
87 Timerange evalTime = 79 Timerange evalTime = new HistoricalDischargeAccess(flys)
88 new HistoricalDischargeAccess(flys).getEvaluationTimerange(); 80 .getEvaluationTimerange();
89 81
90 Object[] args = new Object[] { 82 Object[] args = new Object[] { FLYSUtils.getReferenceGaugeName(flys),
91 FLYSUtils.getReferenceGaugeName(flys), 83 evalTime.getStart(), evalTime.getEnd() };
92 evalTime.getStart(),
93 evalTime.getEnd()
94 };
95 84
96 return msg(I18N_CHART_SUBTITLE, "", args); 85 return msg(I18N_CHART_SUBTITLE, "", args);
97 } 86 }
98
99 87
100 @Override 88 @Override
101 protected String getDefaultXAxisLabel() { 89 protected String getDefaultXAxisLabel() {
102 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL); 90 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL);
103 } 91 }
119 protected void adjustPlot(XYPlot plot) { 107 protected void adjustPlot(XYPlot plot) {
120 super.adjustPlot(plot); 108 super.adjustPlot(plot);
121 plot.setRangeZeroBaselineVisible(true); 109 plot.setRangeZeroBaselineVisible(true);
122 } 110 }
123 111
124 112 @Override
125 @Override 113 public void doOut(ArtifactAndFacet artifactFacet, Document theme,
126 public void doOut( 114 boolean visible) {
127 ArtifactAndFacet artifactFacet,
128 Document theme,
129 boolean visible
130 ) {
131 String name = artifactFacet.getFacetName(); 115 String name = artifactFacet.getFacetName();
132 logger.debug("HistoricalDischargeCurveGenerator.doOut: " + name); 116 logger.debug("HistoricalDischargeCurveGenerator.doOut: " + name);
133 logger.debug("Theme description is: " + artifactFacet.getFacetDescription()); 117 logger.debug("Theme description is: "
134 118 + artifactFacet.getFacetDescription());
135 119
136 if (name.equals(HISTORICAL_DISCHARGE_Q)) { 120 if (name.equals(HISTORICAL_DISCHARGE_Q)) {
137 doHistoricalDischargeOut( 121 doHistoricalDischargeOutQ(
138 (FLYSArtifact) artifactFacet.getArtifact(), 122 (FLYSArtifact) artifactFacet.getArtifact(),
139 artifactFacet.getData(context), 123 artifactFacet.getData(context),
140 artifactFacet.getFacetDescription(), 124 artifactFacet.getFacetDescription(), theme, visible);
141 theme, 125 }
142 visible); 126 else if (name.equals(HISTORICAL_DISCHARGE_W)) {
127 doHistoricalDischargeOutW(
128 (FLYSArtifact) artifactFacet.getArtifact(),
129 artifactFacet.getData(context),
130 artifactFacet.getFacetDescription(), theme, visible);
143 } 131 }
144 else if (name.equals(HISTORICAL_DISCHARGE_Q_DIFF)) { 132 else if (name.equals(HISTORICAL_DISCHARGE_Q_DIFF)) {
145 doHistoricalDischargeDifferenceOut( 133 doHistoricalDischargeDifferenceOutQ(
146 (FLYSArtifact) artifactFacet.getArtifact(), 134 (FLYSArtifact) artifactFacet.getArtifact(),
147 artifactFacet.getData(context), 135 artifactFacet.getData(context),
148 artifactFacet.getFacetDescription(), 136 artifactFacet.getFacetDescription(), theme, visible);
149 theme, 137 }
150 visible); 138 else if (name.equals(HISTORICAL_DISCHARGE_W_DIFF)) {
139 doHistoricalDischargeDifferenceOutW(
140 (FLYSArtifact) artifactFacet.getArtifact(),
141 artifactFacet.getData(context),
142 artifactFacet.getFacetDescription(), theme, visible);
151 } 143 }
152 else if (FacetTypes.IS.MANUALPOINTS(name)) { 144 else if (FacetTypes.IS.MANUALPOINTS(name)) {
153 doPoints (artifactFacet.getData(context), 145 doPoints(artifactFacet.getData(context), artifactFacet, theme,
154 artifactFacet, 146 visible, YAXIS.Q.idx);
155 theme, visible, YAXIS.Q.idx); 147 }
156 }
157 // TODO ADD THE CASE FOR DISPLAYING W VALUES
158 else { 148 else {
159 logger.warn("doOut(): unknown facet name: " + name); 149 logger.warn("doOut(): unknown facet name: " + name);
160 return; 150 return;
161 } 151 }
162 } 152 }
163 153
164 154 protected void doHistoricalDischargeOutQ(FLYSArtifact artifact,
165 protected void doHistoricalDischargeOut( 155 Object data, String desc, Document theme, boolean visible) {
166 FLYSArtifact artifact,
167 Object data,
168 String desc,
169 Document theme,
170 boolean visible)
171 {
172 logger.debug("doHistoricalDischargeOut(): description = " + desc); 156 logger.debug("doHistoricalDischargeOut(): description = " + desc);
173 157
174 WQTimerange wqt = (WQTimerange) data; 158 WQTimerange wqt = (WQTimerange) data;
175 159
176 TimeSeriesCollection tsc = newTimeSeriesCollection( 160 TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(),
177 wqt.getTimeranges(), 161 wqt.getQs(), theme, desc);
178 wqt.getQs(), 162
179 theme, 163 addAxisDataset(tsc, YAXIS.Q.idx, visible);
180 desc); 164 }
181 165
182 addAxisDataset(tsc, 0, visible); 166 protected void doHistoricalDischargeOutW(FLYSArtifact artifact,
183 } 167 Object data, String desc, Document theme, boolean visible) {
184 168 logger.debug("doHistoricalDischargeOut(): description = " + desc);
185 169
186 protected void doHistoricalDischargeDifferenceOut( 170 WQTimerange wqt = (WQTimerange) data;
187 FLYSArtifact artifact, 171
188 Object data, 172 TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(),
189 String desc, 173 wqt.getWs(), theme, desc);
190 Document theme, 174
191 boolean visible 175 addAxisDataset(tsc, YAXIS.W.idx, visible);
192 ) { 176 }
177
178 protected void doHistoricalDischargeDifferenceOutQ(FLYSArtifact artifact,
179 Object data, String desc, Document theme, boolean visible) {
193 logger.debug("doHistoricalDischargeDifferenceOut: desc = " + desc); 180 logger.debug("doHistoricalDischargeDifferenceOut: desc = " + desc);
194 181
195 HistoricalWQTimerange wqt = (HistoricalWQTimerange) data; 182 HistoricalWQTimerange wqt = (HistoricalWQTimerange) data;
196 183
197 TimeSeriesCollection tsc = newTimeSeriesCollection( 184 TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(),
198 wqt.getTimeranges(), 185 wqt.getDiffs(), theme, desc);
199 wqt.getDiffs(), 186
200 theme, 187 addAxisDataset(tsc, YAXIS.Q.idx, visible);
201 desc); 188 }
202 189
203 addAxisDataset(tsc, 0, visible); 190 protected void doHistoricalDischargeDifferenceOutW(FLYSArtifact artifact,
204 } 191 Object data, String desc, Document theme, boolean visible) {
205 192 logger.debug("doHistoricalDischargeDifferenceOut: desc = " + desc);
193
194 HistoricalWQTimerange wqt = (HistoricalWQTimerange) data;
195
196 TimeSeriesCollection tsc = newTimeSeriesCollection(wqt.getTimeranges(),
197 wqt.getDiffs(), theme, desc);
198
199 addAxisDataset(tsc, YAXIS.W.idx, visible);
200 }
206 201
207 /** 202 /**
208 * Creates a new TimeSeriesCollection with a single TimeSeries. The 203 * Creates a new TimeSeriesCollection with a single TimeSeries. The
209 * TimeSeries will consist of two RegularTimePeriods for each W/Q value 204 * TimeSeries will consist of two RegularTimePeriods for each W/Q value
210 * provided by <i>wqt</i>. This has the effect, that the line in the chart 205 * provided by <i>wqt</i>. This has the effect, that the line in the chart
211 * looks like a "step chart". 206 * looks like a "step chart".
212 */ 207 */
213 protected TimeSeriesCollection newTimeSeriesCollection( 208 protected TimeSeriesCollection newTimeSeriesCollection(
214 Timerange[] timeranges, 209 Timerange[] timeranges, double[] values, Document theme, String desc) {
215 double[] values,
216 Document theme,
217 String desc
218 ) {
219 logger.debug("Create new TimeSeriesCollection for: " + desc); 210 logger.debug("Create new TimeSeriesCollection for: " + desc);
220 211
221 TimeSeriesCollection tsc = new TimeSeriesCollection(); 212 TimeSeriesCollection tsc = new TimeSeriesCollection();
222 TimeSeries series = new StyledTimeSeries(desc, theme); 213 TimeSeries series = new StyledTimeSeries(desc, theme);
223 214
224 for (int i = 0, n = timeranges.length; i < n; i++) { 215 for (int i = 0, n = timeranges.length; i < n; i++) {
225 RegularTimePeriod[] rtp = newRegularTimePeriod(timeranges[i]); 216 RegularTimePeriod[] rtp = newRegularTimePeriod(timeranges[i]);
226 217
227 try { 218 try {
247 tsc.addSeries(series); 238 tsc.addSeries(series);
248 239
249 return tsc; 240 return tsc;
250 } 241 }
251 242
252
253 /** 243 /**
254 * Creates an array that consists of two <i>Minute</i> periods [start, end]. 244 * Creates an array that consists of two <i>Minute</i> periods [start, end].
255 * 245 *
256 * @param timerange Supports start and end time. 246 * @param timerange
257 * 247 * Supports start and end time.
248 *
258 * @return an array with two <i>Minute</i> periods [start, end]. 249 * @return an array with two <i>Minute</i> periods [start, end].
259 */ 250 */
260 protected RegularTimePeriod[] newRegularTimePeriod(Timerange timerange) { 251 protected RegularTimePeriod[] newRegularTimePeriod(Timerange timerange) {
261 Date start = new Date(timerange.getStart()); 252 Date start = new Date(timerange.getStart());
262 Date end = new Date(timerange.getEnd() - 1000 * 60 * 60 * 24); 253 Date end = new Date(timerange.getEnd() - 1000 * 60 * 60 * 24);
263 254
264 return new RegularTimePeriod[] { 255 return new RegularTimePeriod[] { new Day(start), new Day(end) };
265 new Day(start),
266 new Day(end)
267 };
268 } 256 }
269 } 257 }
270 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 258 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org