comparison flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java @ 682:591249171c32

#77 The curves in a duration chart will have names now. flys-artifacts/trunk@2115 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 14 Jun 2011 15:34:27 +0000
parents bc1e4878d7e3
children eab5e5089d77
comparison
equal deleted inserted replaced
681:dda282dcc44f 682:591249171c32
14 import org.jfree.data.xy.XYSeries; 14 import org.jfree.data.xy.XYSeries;
15 import org.jfree.data.xy.XYSeriesCollection; 15 import org.jfree.data.xy.XYSeriesCollection;
16 16
17 import de.intevation.artifacts.Artifact; 17 import de.intevation.artifacts.Artifact;
18 18
19 import de.intevation.flys.model.River;
20
19 import de.intevation.flys.artifacts.WINFOArtifact; 21 import de.intevation.flys.artifacts.WINFOArtifact;
20 import de.intevation.flys.artifacts.model.WQDay; 22 import de.intevation.flys.artifacts.model.WQDay;
23 import de.intevation.flys.artifacts.resources.Resources;
21 24
22 25
23 /** 26 /**
24 * An OutGenerator that generates duration curves. 27 * An OutGenerator that generates duration curves.
25 * 28 *
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
27 */ 30 */
28 public class DurationCurveGenerator extends XYChartGenerator { 31 public class DurationCurveGenerator extends XYChartGenerator {
29 32
33 public static final String I18N_DURATION_W = "chart.duration.curve.curve.w";
34 public static final String I18N_DURATION_Q = "chart.duration.curve.curve.q";
35
30 private static Logger logger = 36 private static Logger logger =
31 Logger.getLogger(DurationCurveGenerator.class); 37 Logger.getLogger(DurationCurveGenerator.class);
32 38
33 /** The storage for the W series to be drawn in this chart.*/ 39 /** The storage for the W series to be drawn in this chart.*/
34 protected XYSeriesCollection w; 40 protected XYSeriesCollection w;
157 if (facet == null || facet.length() == 0) { 163 if (facet == null || facet.length() == 0) {
158 logger.error("No facet given. Cannot create dataset."); 164 logger.error("No facet given. Cannot create dataset.");
159 return; 165 return;
160 } 166 }
161 167
168 WINFOArtifact winfo = (WINFOArtifact) artifact;
169 River river = winfo.getRiver();
170
162 if (facet.equals(DURATION_CURVE_W)) { 171 if (facet.equals(DURATION_CURVE_W)) {
163 doWOut(getDurationCurveData(artifact)); 172 doWOut(getDurationCurveData(artifact), river.getName());
164 } 173 }
165 else if (facet.equals(DURATION_CURVE_Q)) { 174 else if (facet.equals(DURATION_CURVE_Q)) {
166 doQOut(getDurationCurveData(artifact)); 175 doQOut(getDurationCurveData(artifact), river.getName());
167 } 176 }
168 else { 177 else {
169 logger.warn("Unknown facet name: " + facet); 178 logger.warn("Unknown facet name: " + facet);
170 return; 179 return;
171 } 180 }
174 183
175 /** 184 /**
176 * Creates the series for a duration curve's W facet. 185 * Creates the series for a duration curve's W facet.
177 * 186 *
178 * @param wqdays The WQDay store that contains the Ws. 187 * @param wqdays The WQDay store that contains the Ws.
188 * @param river The name of the river.
179 */ 189 */
180 protected void doWOut(WQDay wqdays) { 190 protected void doWOut(WQDay wqdays, String river) {
181 logger.debug("DurationCurveGenerator.doWOut"); 191 logger.debug("DurationCurveGenerator.doWOut");
182 192
183 // TODO find the correct series name 193 // TODO find the correct series name
184 XYSeries series = new XYSeries("W-1"); 194 XYSeries series = new XYSeries(
195 getSeriesName(river, DURATION_CURVE_W));
185 196
186 int size = wqdays.size(); 197 int size = wqdays.size();
187 for (int i = 0; i < size; i++) { 198 for (int i = 0; i < size; i++) {
188 int day = wqdays.getDay(i); 199 int day = wqdays.getDay(i);
189 double w = wqdays.getW(i); 200 double w = wqdays.getW(i);
197 208
198 /** 209 /**
199 * Creates the series for a duration curve's Q facet. 210 * Creates the series for a duration curve's Q facet.
200 * 211 *
201 * @param wqdays The WQDay store that contains the Qs. 212 * @param wqdays The WQDay store that contains the Qs.
213 * @param river The name of the river.
202 */ 214 */
203 protected void doQOut(WQDay wqdays) { 215 protected void doQOut(WQDay wqdays, String river) {
204 logger.debug("DurationCurveGenerator.doQOut"); 216 logger.debug("DurationCurveGenerator.doQOut");
205 217
206 // TODO find the correct series name 218 // TODO find the correct series name
207 XYSeries series = new XYSeries("Q-1"); 219 XYSeries series = new XYSeries(
220 getSeriesName(river, DURATION_CURVE_Q));
208 221
209 int size = wqdays.size(); 222 int size = wqdays.size();
210 for (int i = 0; i < size; i++) { 223 for (int i = 0; i < size; i++) {
211 int day = wqdays.getDay(i); 224 int day = wqdays.getDay(i);
212 double q = wqdays.getQ(i); 225 double q = wqdays.getQ(i);
228 */ 241 */
229 protected WQDay getDurationCurveData(Artifact artifact) { 242 protected WQDay getDurationCurveData(Artifact artifact) {
230 WINFOArtifact winfoArtifact = (WINFOArtifact) artifact; 243 WINFOArtifact winfoArtifact = (WINFOArtifact) artifact;
231 return winfoArtifact.getDurationCurveData(); 244 return winfoArtifact.getDurationCurveData();
232 } 245 }
246
247
248 protected String getSeriesName(String river, String type) {
249 Object[] args = new Object[] { river };
250
251 if (type == null || type.length() == 0) {
252 logger.warn("No duration curve type given.");
253 return "n/a";
254 }
255 else if (type.equals(DURATION_CURVE_W)) {
256 return Resources.getMsg(
257 context.getMeta(),
258 I18N_DURATION_W,
259 "W",
260 args);
261 }
262 else if (type.equals(DURATION_CURVE_Q)) {
263 return Resources.getMsg(
264 context.getMeta(),
265 I18N_DURATION_Q,
266 "W",
267 args);
268 }
269
270 logger.warn("Could not determine chart curve type: " + type);
271 return type;
272 }
233 } 273 }
234 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 274 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org