comparison flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java @ 696:708b270dfd30 facets-slt

OutGenerators use now facets to fetch necessary data. flys-artifacts/branches/facets-slt@2140 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 17 Jun 2011 09:19:43 +0000
parents 45cd58a2a2bb
children eab5e5089d77
comparison
equal deleted inserted replaced
695:45cd58a2a2bb 696:708b270dfd30
16 16
17 import de.intevation.artifacts.Artifact; 17 import de.intevation.artifacts.Artifact;
18 18
19 import de.intevation.artifactdatabase.state.Facet; 19 import de.intevation.artifactdatabase.state.Facet;
20 20
21 import de.intevation.flys.model.River; 21 import de.intevation.flys.artifacts.FLYSArtifact;
22 22 import de.intevation.flys.artifacts.model.FacetTypes;
23 import de.intevation.flys.artifacts.WINFOArtifact;
24 import de.intevation.flys.artifacts.model.WQDay; 23 import de.intevation.flys.artifacts.model.WQDay;
25 import de.intevation.flys.artifacts.resources.Resources; 24 import de.intevation.flys.artifacts.resources.Resources;
26 25
27 26
28 /** 27 /**
29 * An OutGenerator that generates duration curves. 28 * An OutGenerator that generates duration curves.
30 * 29 *
31 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 30 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
32 */ 31 */
33 public class DurationCurveGenerator extends XYChartGenerator { 32 public class DurationCurveGenerator
34 33 extends XYChartGenerator
35 public static final String I18N_DURATION_W = "chart.duration.curve.curve.w"; 34 implements FacetTypes
36 public static final String I18N_DURATION_Q = "chart.duration.curve.curve.q"; 35 {
37
38 private static Logger logger = 36 private static Logger logger =
39 Logger.getLogger(DurationCurveGenerator.class); 37 Logger.getLogger(DurationCurveGenerator.class);
40 38
41 /** 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.*/
42 protected XYSeriesCollection w; 40 protected XYSeriesCollection w;
43 41
44 /** The storage for the Q series to be drawn in this chart.*/ 42 /** The storage for the Q series to be drawn in this chart.*/
45 protected XYSeriesCollection q; 43 protected XYSeriesCollection q;
46 44
47 45
48 public static final String DURATION_CURVE_W = 46 public static final String I18N_DURATION_W =
49 "duration_curve.w"; 47 "chart.duration.curve.curve.w";
50 48
51 public static final String DURATION_CURVE_Q = 49 public static final String I18N_DURATION_Q =
52 "duration_curve.q"; 50 "chart.duration.curve.curve.q";
53 51
54 public static final String I18N_CHART_TITLE = 52 public static final String I18N_CHART_TITLE =
55 "chart.duration.curve.title"; 53 "chart.duration.curve.title";
56 54
57 public static final String I18N_CHART_SUBTITLE = 55 public static final String I18N_CHART_SUBTITLE =
159 } 157 }
160 158
161 159
162 @Override 160 @Override
163 public void doOut(Artifact artifact, Facet facet, Document attr) { 161 public void doOut(Artifact artifact, Facet facet, Document attr) {
164 String name = facet.getName(); 162 String name = facet != null ? facet.getName() : null;
165 163
166 logger.debug("DurationCurveGenerator.doOut: " + name); 164 logger.debug("DurationCurveGenerator.doOut: " + name);
167 165
168 if (name == null || name.length() == 0) { 166 if (name == null || name.length() == 0) {
169 logger.error("No facet given. Cannot create dataset."); 167 logger.error("No facet given. Cannot create dataset.");
170 return; 168 return;
171 } 169 }
172 170
173 WINFOArtifact winfo = (WINFOArtifact) artifact; 171 FLYSArtifact flys = (FLYSArtifact) artifact;
174 River river = winfo.getRiver(); 172 Facet f = flys.getNativeFacet(facet);
175 173
176 if (name.equals(DURATION_CURVE_W)) { 174 if (name.equals(DURATION_W)) {
177 doWOut(getDurationCurveData(artifact), river.getName()); 175 doWOut((WQDay) f.getData(artifact, context));
178 } 176 }
179 else if (name.equals(DURATION_CURVE_Q)) { 177 else if (name.equals(DURATION_Q)) {
180 doQOut(getDurationCurveData(artifact), river.getName()); 178 doQOut((WQDay) f.getData(artifact, context));
181 } 179 }
182 else { 180 else {
183 logger.warn("Unknown facet name: " + name); 181 logger.warn("Unknown facet name: " + name);
184 return; 182 return;
185 } 183 }
190 * Creates the series for a duration curve's W facet. 188 * Creates the series for a duration curve's W facet.
191 * 189 *
192 * @param wqdays The WQDay store that contains the Ws. 190 * @param wqdays The WQDay store that contains the Ws.
193 * @param river The name of the river. 191 * @param river The name of the river.
194 */ 192 */
195 protected void doWOut(WQDay wqdays, String river) { 193 protected void doWOut(WQDay wqdays) {
196 logger.debug("DurationCurveGenerator.doWOut"); 194 logger.debug("DurationCurveGenerator.doWOut");
197 195
198 // TODO find the correct series name 196 // TODO find the correct series name
199 XYSeries series = new XYSeries( 197 XYSeries series = new XYSeries(
200 getSeriesName(river, DURATION_CURVE_W)); 198 getSeriesName(getRiverName(), DURATION_W));
201 199
202 int size = wqdays.size(); 200 int size = wqdays.size();
203 for (int i = 0; i < size; i++) { 201 for (int i = 0; i < size; i++) {
204 int day = wqdays.getDay(i); 202 int day = wqdays.getDay(i);
205 double w = wqdays.getW(i); 203 double w = wqdays.getW(i);
215 * Creates the series for a duration curve's Q facet. 213 * Creates the series for a duration curve's Q facet.
216 * 214 *
217 * @param wqdays The WQDay store that contains the Qs. 215 * @param wqdays The WQDay store that contains the Qs.
218 * @param river The name of the river. 216 * @param river The name of the river.
219 */ 217 */
220 protected void doQOut(WQDay wqdays, String river) { 218 protected void doQOut(WQDay wqdays) {
221 logger.debug("DurationCurveGenerator.doQOut"); 219 logger.debug("DurationCurveGenerator.doQOut");
222 220
223 // TODO find the correct series name 221 // TODO find the correct series name
224 XYSeries series = new XYSeries( 222 XYSeries series = new XYSeries(
225 getSeriesName(river, DURATION_CURVE_Q)); 223 getSeriesName(getRiverName(), DURATION_Q));
226 224
227 int size = wqdays.size(); 225 int size = wqdays.size();
228 for (int i = 0; i < size; i++) { 226 for (int i = 0; i < size; i++) {
229 int day = wqdays.getDay(i); 227 int day = wqdays.getDay(i);
230 double q = wqdays.getQ(i); 228 double q = wqdays.getQ(i);
234 232
235 this.q.addSeries(series); 233 this.q.addSeries(series);
236 } 234 }
237 235
238 236
239 /**
240 * Returns the computed data for a duration curve based on the artifact's
241 * computation method.
242 *
243 * @param artifact The WINFO artifact.
244 *
245 * @return the computed data for a duration curve's W and Q facet.
246 */
247 protected WQDay getDurationCurveData(Artifact artifact) {
248 WINFOArtifact winfoArtifact = (WINFOArtifact) artifact;
249 return winfoArtifact.getDurationCurveData();
250 }
251
252
253 protected String getSeriesName(String river, String type) { 237 protected String getSeriesName(String river, String type) {
254 Object[] args = new Object[] { river }; 238 Object[] args = new Object[] { river };
255 239
256 if (type == null || type.length() == 0) { 240 if (type == null || type.length() == 0) {
257 logger.warn("No duration curve type given."); 241 logger.warn("No duration curve type given.");
258 return "n/a"; 242 return "n/a";
259 } 243 }
260 else if (type.equals(DURATION_CURVE_W)) { 244 else if (type.equals(DURATION_W)) {
261 return Resources.getMsg( 245 return Resources.getMsg(
262 context.getMeta(), 246 context.getMeta(),
263 I18N_DURATION_W, 247 I18N_DURATION_W,
264 "W", 248 "W",
265 args); 249 args);
266 } 250 }
267 else if (type.equals(DURATION_CURVE_Q)) { 251 else if (type.equals(DURATION_Q)) {
268 return Resources.getMsg( 252 return Resources.getMsg(
269 context.getMeta(), 253 context.getMeta(),
270 I18N_DURATION_Q, 254 I18N_DURATION_Q,
271 "W", 255 "W",
272 args); 256 args);

http://dive4elements.wald.intevation.org