Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java @ 385:478940d06876
Enabled the WINFO artifact to create duration curves - new OutGenerator, added methods for data computation.
flys-artifacts/trunk@1802 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 03 May 2011 12:05:32 +0000 |
parents | |
children | fc3ac59c3c8b |
comparison
equal
deleted
inserted
replaced
384:88614ddfc1e3 | 385:478940d06876 |
---|---|
1 package de.intevation.flys.exports; | |
2 | |
3 import org.w3c.dom.Document; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.jfree.chart.JFreeChart; | |
8 import org.jfree.chart.axis.NumberAxis; | |
9 import org.jfree.chart.plot.XYPlot; | |
10 import org.jfree.data.xy.XYSeries; | |
11 import org.jfree.data.xy.XYSeriesCollection; | |
12 | |
13 import de.intevation.artifacts.Artifact; | |
14 | |
15 import de.intevation.flys.artifacts.WINFOArtifact; | |
16 import de.intevation.flys.artifacts.model.WQDay; | |
17 | |
18 | |
19 /** | |
20 * An OutGenerator that generates duration curves. | |
21 * | |
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
23 */ | |
24 public class DurationCurveGenerator extends XYChartGenerator { | |
25 | |
26 private static Logger logger = | |
27 Logger.getLogger(DurationCurveGenerator.class); | |
28 | |
29 /** The storage for the W series to be drawn in this chart.*/ | |
30 protected XYSeriesCollection w; | |
31 | |
32 /** The storage for the Q series to be drawn in this chart.*/ | |
33 protected XYSeriesCollection q; | |
34 | |
35 | |
36 public static final String DURATION_CURVE_W = | |
37 "duration_curve.w"; | |
38 | |
39 public static final String DURATION_CURVE_Q = | |
40 "duration_curve.q"; | |
41 | |
42 | |
43 public DurationCurveGenerator() { | |
44 super(); | |
45 | |
46 this.w = new XYSeriesCollection(); | |
47 this.q = new XYSeriesCollection(); | |
48 } | |
49 | |
50 | |
51 protected String getChartTitle() { | |
52 // TODO i18n | |
53 return "Wasserstand für Gewässer"; | |
54 } | |
55 | |
56 | |
57 protected String getXAxisLabel() { | |
58 // TODO i18n | |
59 return "Unterschreitungsdauer [Tagen]"; | |
60 } | |
61 | |
62 | |
63 protected String getYAxisLabel() { | |
64 return "W [NN + m]"; | |
65 } | |
66 | |
67 | |
68 public void addDatasets(JFreeChart chart) { | |
69 XYPlot plot = (XYPlot) chart.getPlot(); | |
70 | |
71 plot.setDataset(0, w); | |
72 plot.setDataset(1, q); | |
73 } | |
74 | |
75 | |
76 protected void adjustAxes(XYPlot plot) { | |
77 super.adjustAxes(plot); | |
78 | |
79 NumberAxis qAxis = new NumberAxis("Q [m³/s]"); | |
80 | |
81 plot.setRangeAxis(2, qAxis); | |
82 plot.mapDatasetToRangeAxis(1, 2); | |
83 } | |
84 | |
85 | |
86 public void doOut(Artifact artifact, String facet, Document attr) { | |
87 logger.debug("DurationCurveGenerator.doOut: " + facet); | |
88 | |
89 if (facet == null || facet.length() == 0) { | |
90 logger.error("No facet given. Cannot create dataset."); | |
91 return; | |
92 } | |
93 | |
94 if (facet.equals(DURATION_CURVE_W)) { | |
95 doWOut(getDurationCurveData(artifact)); | |
96 } | |
97 else if (facet.equals(DURATION_CURVE_Q)) { | |
98 doQOut(getDurationCurveData(artifact)); | |
99 } | |
100 else { | |
101 logger.warn("Unknown facet name: " + facet); | |
102 return; | |
103 } | |
104 } | |
105 | |
106 | |
107 /** | |
108 * Creates the series for a duration curve's W facet. | |
109 * | |
110 * @param wqdays The WQDay store that contains the Ws. | |
111 */ | |
112 protected void doWOut(WQDay wqdays) { | |
113 logger.debug("DurationCurveGenerator.doWOut"); | |
114 | |
115 // TODO find the correct series name | |
116 XYSeries series = new XYSeries("W-1"); | |
117 | |
118 int size = wqdays.size(); | |
119 for (int i = 0; i < size; i++) { | |
120 int day = wqdays.getDay(i); | |
121 double w = wqdays.getW(i); | |
122 | |
123 series.add((double) day, w); | |
124 } | |
125 | |
126 this.w.addSeries(series); | |
127 } | |
128 | |
129 | |
130 /** | |
131 * Creates the series for a duration curve's Q facet. | |
132 * | |
133 * @param wqdays The WQDay store that contains the Qs. | |
134 */ | |
135 protected void doQOut(WQDay wqdays) { | |
136 logger.debug("DurationCurveGenerator.doQOut"); | |
137 | |
138 // TODO find the correct series name | |
139 XYSeries series = new XYSeries("Q-1"); | |
140 | |
141 int size = wqdays.size(); | |
142 for (int i = 0; i < size; i++) { | |
143 int day = wqdays.getDay(i); | |
144 double q = wqdays.getQ(i); | |
145 | |
146 series.add((double) day, q); | |
147 } | |
148 | |
149 this.q.addSeries(series); | |
150 } | |
151 | |
152 | |
153 /** | |
154 * Returns the computed data for a duration curve based on the artifact's | |
155 * computation method. | |
156 * | |
157 * @param artifact The WINFO artifact. | |
158 * | |
159 * @return the computed data for a duration curve's W and Q facet. | |
160 */ | |
161 protected WQDay getDurationCurveData(Artifact artifact) { | |
162 WINFOArtifact winfoArtifact = (WINFOArtifact) artifact; | |
163 return winfoArtifact.getDurationCurveData(); | |
164 } | |
165 } | |
166 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |