comparison flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java @ 704:eab5e5089d77

Merged revisions 2127-2133,2136-2137,2140,2143-2144,2146,2150-2151,2153-2154 via svnmerge from svn+ssh://teichmann@thoe/home/projects/Geospatial/bsh-generischer-viewer/Material/SVN/flys-artifacts/branches/facets-slt ........ r2127 | ingo | 2011-06-16 09:50:56 +0200 (Do, 16 Jun 2011) | 1 line Added a compute() method to WINFOArtifact which acts as a dispatcher for different computations. It triggers a calculation based on ComputeCallbacks that are generated by the current states. ........ r2128 | ingo | 2011-06-16 10:25:06 +0200 (Do, 16 Jun 2011) | 1 line Moved Waterlevel state into the correct package. ........ r2129 | ingo | 2011-06-16 10:43:58 +0200 (Do, 16 Jun 2011) | 1 line Added two more compute() methods to ComputeCallback to distinguish between different phases of the artifact. ........ r2130 | ingo | 2011-06-16 10:57:05 +0200 (Do, 16 Jun 2011) | 1 line Use enums to dispatch computeFeed() and computeAdvance(). ........ r2131 | ingo | 2011-06-16 11:04:59 +0200 (Do, 16 Jun 2011) | 1 line Store facets for each state. ........ r2132 | ingo | 2011-06-16 12:05:44 +0200 (Do, 16 Jun 2011) | 1 line Generated facets for each output aspect. ........ r2133 | ingo | 2011-06-16 15:24:00 +0200 (Do, 16 Jun 2011) | 1 line Write computed facets into artifacts describe document. ........ r2136 | ingo | 2011-06-16 16:10:49 +0200 (Do, 16 Jun 2011) | 1 line Add index and description of facets to collections describe document. ........ r2137 | ingo | 2011-06-16 16:31:41 +0200 (Do, 16 Jun 2011) | 1 line OutGenerators doOut() takes a facet object now instead of just its name. ........ r2140 | ingo | 2011-06-17 11:19:43 +0200 (Fr, 17 Jun 2011) | 1 line OutGenerators use now facets to fetch necessary data. ........ r2143 | teichmann | 2011-06-17 12:40:54 +0200 (Fr, 17 Jun 2011) | 1 line Removed ComputeCallback because this was thought too complicated. Fixed issue with facets not be re-generated if same state is entered again. ........ r2144 | teichmann | 2011-06-17 13:08:31 +0200 (Fr, 17 Jun 2011) | 1 line make getGauges() more robust ........ r2146 | teichmann | 2011-06-17 13:23:57 +0200 (Fr, 17 Jun 2011) | 1 line mico opt: inter cmps are faster than str cmps. ........ r2150 | teichmann | 2011-06-17 15:10:20 +0200 (Fr, 17 Jun 2011) | 1 line call computeAdvance() if we want to advance. ........ r2151 | teichmann | 2011-06-17 15:45:50 +0200 (Fr, 17 Jun 2011) | 1 line Base WST/CSV exports on facets. TODO: generate the facets. ........ r2153 | teichmann | 2011-06-17 16:03:29 +0200 (Fr, 17 Jun 2011) | 1 line Add facet to access raw computed data. ........ r2154 | teichmann | 2011-06-17 16:37:09 +0200 (Fr, 17 Jun 2011) | 1 line Generate data facets for the computed states. ........ flys-artifacts/trunk@2156 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 17 Jun 2011 16:17:03 +0000
parents 591249171c32 708b270dfd30
children 5f5e67aceb8c
comparison
equal deleted inserted replaced
685:d45c3ddaed1b 704:eab5e5089d77
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; 19 import de.intevation.artifactdatabase.state.Facet;
20 20
21 import de.intevation.flys.artifacts.WINFOArtifact; 21 import de.intevation.flys.artifacts.FLYSArtifact;
22 import de.intevation.flys.artifacts.model.FacetTypes;
22 import de.intevation.flys.artifacts.model.WQDay; 23 import de.intevation.flys.artifacts.model.WQDay;
23 import de.intevation.flys.artifacts.resources.Resources; 24 import de.intevation.flys.artifacts.resources.Resources;
24 25
25 26
26 /** 27 /**
27 * An OutGenerator that generates duration curves. 28 * An OutGenerator that generates duration curves.
28 * 29 *
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 30 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
30 */ 31 */
31 public class DurationCurveGenerator extends XYChartGenerator { 32 public class DurationCurveGenerator
32 33 extends XYChartGenerator
33 public static final String I18N_DURATION_W = "chart.duration.curve.curve.w"; 34 implements FacetTypes
34 public static final String I18N_DURATION_Q = "chart.duration.curve.curve.q"; 35 {
35
36 private static Logger logger = 36 private static Logger logger =
37 Logger.getLogger(DurationCurveGenerator.class); 37 Logger.getLogger(DurationCurveGenerator.class);
38 38
39 /** 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.*/
40 protected XYSeriesCollection w; 40 protected XYSeriesCollection w;
41 41
42 /** 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.*/
43 protected XYSeriesCollection q; 43 protected XYSeriesCollection q;
44 44
45 45
46 public static final String DURATION_CURVE_W = 46 public static final String I18N_DURATION_W =
47 "duration_curve.w"; 47 "chart.duration.curve.curve.w";
48 48
49 public static final String DURATION_CURVE_Q = 49 public static final String I18N_DURATION_Q =
50 "duration_curve.q"; 50 "chart.duration.curve.curve.q";
51 51
52 public static final String I18N_CHART_TITLE = 52 public static final String I18N_CHART_TITLE =
53 "chart.duration.curve.title"; 53 "chart.duration.curve.title";
54 54
55 public static final String I18N_CHART_SUBTITLE = 55 public static final String I18N_CHART_SUBTITLE =
155 plot.setRangeAxis(1, qAxis); 155 plot.setRangeAxis(1, qAxis);
156 plot.mapDatasetToRangeAxis(1, 1); 156 plot.mapDatasetToRangeAxis(1, 1);
157 } 157 }
158 158
159 159
160 public void doOut(Artifact artifact, String facet, Document attr) { 160 @Override
161 logger.debug("DurationCurveGenerator.doOut: " + facet); 161 public void doOut(Artifact artifact, Facet facet, Document attr) {
162 162 String name = facet != null ? facet.getName() : null;
163 if (facet == null || facet.length() == 0) { 163
164 logger.debug("DurationCurveGenerator.doOut: " + name);
165
166 if (name == null || name.length() == 0) {
164 logger.error("No facet given. Cannot create dataset."); 167 logger.error("No facet given. Cannot create dataset.");
165 return; 168 return;
166 } 169 }
167 170
168 WINFOArtifact winfo = (WINFOArtifact) artifact; 171 FLYSArtifact flys = (FLYSArtifact) artifact;
169 River river = winfo.getRiver(); 172 Facet f = flys.getNativeFacet(facet);
170 173
171 if (facet.equals(DURATION_CURVE_W)) { 174 if (name.equals(DURATION_W)) {
172 doWOut(getDurationCurveData(artifact), river.getName()); 175 doWOut((WQDay) f.getData(artifact, context));
173 } 176 }
174 else if (facet.equals(DURATION_CURVE_Q)) { 177 else if (name.equals(DURATION_Q)) {
175 doQOut(getDurationCurveData(artifact), river.getName()); 178 doQOut((WQDay) f.getData(artifact, context));
176 } 179 }
177 else { 180 else {
178 logger.warn("Unknown facet name: " + facet); 181 logger.warn("Unknown facet name: " + name);
179 return; 182 return;
180 } 183 }
181 } 184 }
182 185
183 186
185 * Creates the series for a duration curve's W facet. 188 * Creates the series for a duration curve's W facet.
186 * 189 *
187 * @param wqdays The WQDay store that contains the Ws. 190 * @param wqdays The WQDay store that contains the Ws.
188 * @param river The name of the river. 191 * @param river The name of the river.
189 */ 192 */
190 protected void doWOut(WQDay wqdays, String river) { 193 protected void doWOut(WQDay wqdays) {
191 logger.debug("DurationCurveGenerator.doWOut"); 194 logger.debug("DurationCurveGenerator.doWOut");
192 195
193 // TODO find the correct series name 196 // TODO find the correct series name
194 XYSeries series = new XYSeries( 197 XYSeries series = new XYSeries(
195 getSeriesName(river, DURATION_CURVE_W)); 198 getSeriesName(getRiverName(), DURATION_W));
196 199
197 int size = wqdays.size(); 200 int size = wqdays.size();
198 for (int i = 0; i < size; i++) { 201 for (int i = 0; i < size; i++) {
199 int day = wqdays.getDay(i); 202 int day = wqdays.getDay(i);
200 double w = wqdays.getW(i); 203 double w = wqdays.getW(i);
210 * Creates the series for a duration curve's Q facet. 213 * Creates the series for a duration curve's Q facet.
211 * 214 *
212 * @param wqdays The WQDay store that contains the Qs. 215 * @param wqdays The WQDay store that contains the Qs.
213 * @param river The name of the river. 216 * @param river The name of the river.
214 */ 217 */
215 protected void doQOut(WQDay wqdays, String river) { 218 protected void doQOut(WQDay wqdays) {
216 logger.debug("DurationCurveGenerator.doQOut"); 219 logger.debug("DurationCurveGenerator.doQOut");
217 220
218 // TODO find the correct series name 221 // TODO find the correct series name
219 XYSeries series = new XYSeries( 222 XYSeries series = new XYSeries(
220 getSeriesName(river, DURATION_CURVE_Q)); 223 getSeriesName(getRiverName(), DURATION_Q));
221 224
222 int size = wqdays.size(); 225 int size = wqdays.size();
223 for (int i = 0; i < size; i++) { 226 for (int i = 0; i < size; i++) {
224 int day = wqdays.getDay(i); 227 int day = wqdays.getDay(i);
225 double q = wqdays.getQ(i); 228 double q = wqdays.getQ(i);
229 232
230 this.q.addSeries(series); 233 this.q.addSeries(series);
231 } 234 }
232 235
233 236
234 /**
235 * Returns the computed data for a duration curve based on the artifact's
236 * computation method.
237 *
238 * @param artifact The WINFO artifact.
239 *
240 * @return the computed data for a duration curve's W and Q facet.
241 */
242 protected WQDay getDurationCurveData(Artifact artifact) {
243 WINFOArtifact winfoArtifact = (WINFOArtifact) artifact;
244 return winfoArtifact.getDurationCurveData();
245 }
246
247
248 protected String getSeriesName(String river, String type) { 237 protected String getSeriesName(String river, String type) {
249 Object[] args = new Object[] { river }; 238 Object[] args = new Object[] { river };
250 239
251 if (type == null || type.length() == 0) { 240 if (type == null || type.length() == 0) {
252 logger.warn("No duration curve type given."); 241 logger.warn("No duration curve type given.");
253 return "n/a"; 242 return "n/a";
254 } 243 }
255 else if (type.equals(DURATION_CURVE_W)) { 244 else if (type.equals(DURATION_W)) {
256 return Resources.getMsg( 245 return Resources.getMsg(
257 context.getMeta(), 246 context.getMeta(),
258 I18N_DURATION_W, 247 I18N_DURATION_W,
259 "W", 248 "W",
260 args); 249 args);
261 } 250 }
262 else if (type.equals(DURATION_CURVE_Q)) { 251 else if (type.equals(DURATION_Q)) {
263 return Resources.getMsg( 252 return Resources.getMsg(
264 context.getMeta(), 253 context.getMeta(),
265 I18N_DURATION_Q, 254 I18N_DURATION_Q,
266 "W", 255 "W",
267 args); 256 args);

http://dive4elements.wald.intevation.org