comparison artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.exports;
2
3 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
4 import org.dive4elements.artifactdatabase.state.Facet;
5 import org.dive4elements.river.artifacts.FLYSArtifact;
6 import org.dive4elements.river.artifacts.StaticWKmsArtifact;
7 import org.dive4elements.river.artifacts.WINFOArtifact;
8 import org.dive4elements.river.artifacts.model.FacetTypes;
9 import org.dive4elements.river.artifacts.model.WKms;
10 import org.dive4elements.river.artifacts.model.WQKms;
11 import org.dive4elements.river.jfree.FLYSAnnotation;
12 import org.dive4elements.river.jfree.StickyAxisAnnotation;
13 import org.dive4elements.river.jfree.StyledXYSeries;
14
15 import org.dive4elements.river.utils.FLYSUtils;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.apache.log4j.Logger;
21 import org.jfree.data.xy.XYSeries;
22 import org.w3c.dom.Document;
23
24
25 /**
26 * An OutGenerator that generates discharge curves.
27 *
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
29 */
30 public class ComputedDischargeCurveGenerator
31 extends DischargeCurveGenerator
32 implements FacetTypes
33 {
34 /** The logger used in this generator. */
35 private static Logger logger =
36 Logger.getLogger(ComputedDischargeCurveGenerator.class);
37
38 public static final String I18N_CHART_TITLE =
39 "chart.computed.discharge.curve.title";
40
41 public static final String I18N_CHART_SUBTITLE =
42 "chart.computed.discharge.curve.subtitle";
43
44 public static final String I18N_YAXIS_LABEL =
45 "chart.computed.discharge.curve.yaxis.label";
46
47 public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve";
48 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
49 public static final String I18N_MAINVALUES_Q_LABEL = "Q (Haupt- und Extremwerte)";
50 public static final String I18N_MAINVALUES_W_LABEL = "W (Haupt- und Extremwerte)";
51
52
53 /** Trivial Constructor. */
54 public ComputedDischargeCurveGenerator () {
55 super();
56 }
57
58
59 @Override
60 protected String getDefaultChartTitle() {
61 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
62 }
63
64
65 @Override
66 protected String getDefaultChartSubtitle() {
67 double[] dist = getRange();
68
69 Object[] args = new Object[] {
70 getRiverName(),
71 dist[0]
72 };
73
74 return msg(I18N_CHART_SUBTITLE, "", args);
75 }
76
77
78 @Override
79 protected String getDefaultYAxisLabel(int pos) {
80 FLYSArtifact flys = (FLYSArtifact) master;
81
82 String unit = FLYSUtils.getRiver(flys).getWstUnit().getName();
83
84 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT, new Object[] { unit });
85 }
86
87
88 /**
89 * Process data, build up plot.
90 */
91 @Override
92 public void doOut(
93 ArtifactAndFacet artifactFacet,
94 Document attr,
95 boolean visible
96 ) {
97 String name = artifactFacet.getFacetName();
98
99 logger.debug("ComputedDischargeCurveGenerator.doOut: " + name);
100
101 if (name == null) {
102 logger.warn("Broken facet in computed discharge out generation.");
103 return;
104 }
105
106 //XXX DEAD CODE // Facet facet = artifactFacet.getFacet();
107
108 if (name.equals(COMPUTED_DISCHARGE_Q)) {
109 doQOut((WQKms) artifactFacet.getData(context), artifactFacet, attr, visible);
110 }
111 else if (name.equals(STATIC_WQ)) {
112 doWQOut(artifactFacet.getData(context), artifactFacet, attr, visible);
113 }
114 else if (name.equals(STATIC_WQ_ANNOTATIONS)) {
115 doWQAnnotations(
116 artifactFacet.getData(context),
117 artifactFacet,
118 attr,
119 visible);
120 }
121 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)
122 || name.equals(MAINVALUES_Q)
123 || name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
124 || name.equals(MAINVALUES_W)
125 ) {
126 doAnnotations((FLYSAnnotation)
127 artifactFacet.getData(context), artifactFacet, attr, visible);
128 }
129 else if (name.equals(STATIC_WKMS_INTERPOL) || name.equals(HEIGHTMARKS_POINTS)) {
130 doWAnnotations(
131 artifactFacet.getData(context),
132 artifactFacet,
133 attr,
134 visible);
135 }
136 else if (name.equals(STATIC_WKMS)) {
137 doWAnnotations(
138 artifactFacet.getData(context),
139 artifactFacet,
140 attr,
141 visible);
142 }
143 else if (FacetTypes.IS.MANUALPOINTS(name)) {
144 doPoints(artifactFacet.getData(context),
145 artifactFacet,
146 attr, visible, YAXIS.W.idx);
147 }
148 else if (name.equals(DISCHARGE_CURVE)) {
149 doDischargeOut(
150 (WINFOArtifact) artifactFacet.getArtifact(),
151 artifactFacet.getData(context),
152 artifactFacet.getFacetDescription(),
153 attr,
154 visible);
155 }
156 else {
157 logger.warn("Unknown facet type for computed discharge: " + name);
158 return;
159 }
160 }
161
162
163 /**
164 * Add WQ Data to plot.
165 * @param wqkms data as double[][]
166 */
167 protected void doWQOut(
168 Object wqkms,
169 ArtifactAndFacet aaf,
170 Document theme,
171 boolean visible
172 ) {
173 logger.debug("ComputedDischargeCurveGenerator: doWQOut");
174 double [][] data = (double [][]) wqkms;
175
176 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
177 StyledSeriesBuilder.addPoints(series, data, true);
178
179 addAxisSeries(series, YAXIS.W.idx, visible);
180 }
181
182
183 /**
184 * Add Q-Series to plot.
185 * @param wqkms actual data
186 * @param theme theme to use.
187 */
188 protected void doQOut(
189 WQKms wqkms,
190 ArtifactAndFacet aaf,
191 Document theme,
192 boolean visible
193 ) {
194 logger.debug("ComputedDischargeCurveGenerator: doWQOut");
195 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
196 StyledSeriesBuilder.addPointsQW(series, wqkms);
197
198 addAxisSeries(series, YAXIS.W.idx, visible);
199 }
200
201
202 /**
203 * Add WQ-Annotations to plot.
204 * @param wqkms actual data
205 * @param theme theme to use.
206 */
207 protected void doWQAnnotations(
208 Object wqkms,
209 ArtifactAndFacet aandf,
210 Document theme,
211 boolean visible
212 ) {
213 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>();
214 double [][] data = (double [][]) wqkms;
215 for (int i = 0; i< data[0].length; i++) {
216 // TODO we need linear interpolation?
217 xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(),
218 (float) data[0][i], StickyAxisAnnotation.SimpleAxis.X_AXIS));
219 xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(),
220 (float) data[1][i], StickyAxisAnnotation.SimpleAxis.Y_AXIS));
221 }
222
223 doAnnotations(new FLYSAnnotation(aandf.getFacetDescription(), xy),
224 aandf, theme, visible);
225 }
226
227
228 /**
229 * Add W-Annotations to plot.
230 * @param wqkms actual data (double[][]).
231 * @param theme theme to use.
232 */
233 protected void doWAnnotations(
234 Object wqkms,
235 ArtifactAndFacet aandf,
236 Document theme,
237 boolean visible
238 ) {
239 Facet facet = aandf.getFacet();
240
241 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>();
242 // Try to find them as WKms as well...
243 if (wqkms instanceof double[][]) {
244 logger.debug("its double[][] time, baby");
245 double [][] data = (double [][]) wqkms;
246 // TODO Do we need interpolation?
247 for (int i = 0; i< data[0].length; i++) {
248 xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(),
249 (float) data[1][i], StickyAxisAnnotation.SimpleAxis.Y_AXIS));
250 }
251
252 doAnnotations(new FLYSAnnotation(facet.getDescription(), xy),
253 aandf, theme, visible);
254 }
255 else {
256 logger.debug("its wkms time, baby");
257 WKms data = (WKms) wqkms;
258 // Assume its WKms.
259 // XXX DEAD CODE // double location = getRange()[0];
260 double w = StaticWKmsArtifact.getWAtKmLin(data, getRange()[0]);
261 xy.add(new StickyAxisAnnotation(aandf.getFacetDescription(),
262 (float) w, StickyAxisAnnotation.SimpleAxis.Y_AXIS));
263
264 doAnnotations(new FLYSAnnotation(facet.getDescription(), xy),
265 aandf, theme, visible);
266 }
267 }
268 }
269 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org