Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java @ 9595:9b39cfd39e59
Softwaretests...20181219 6.2.2: Sinfo/Ued Haupt-/Extremwerte queried for the current chart km instead of only the first in range
author | mschaefer |
---|---|
date | Tue, 05 Feb 2019 15:31:13 +0100 |
parents | 9b8e8fc1f408 |
children |
rev | line source |
---|---|
9398
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
2 * Software engineering by |
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
9252 | 5 * |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; | |
11 | |
12 import java.awt.Font; | |
13 import java.awt.geom.Point2D; | |
9268
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
14 import java.io.OutputStream; |
9252 | 15 |
16 import org.apache.log4j.Logger; | |
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
18 import org.dive4elements.artifacts.CallContext; | |
9595
9b39cfd39e59
Softwaretests...20181219 6.2.2: Sinfo/Ued Haupt-/Extremwerte queried for the current chart km instead of only the first in range
mschaefer
parents:
9556
diff
changeset
|
19 import org.dive4elements.river.artifacts.MainValuesArtifact; |
9252 | 20 import org.dive4elements.river.artifacts.model.FacetTypes; |
21 import org.dive4elements.river.artifacts.model.WQDay; | |
22 import org.dive4elements.river.exports.IdentifiableNumberAxis; | |
23 import org.dive4elements.river.exports.XYChartGenerator; | |
9268
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
24 import org.dive4elements.river.exports.fixings.FixChartGenerator; |
9252 | 25 import org.dive4elements.river.jfree.Bounds; |
26 import org.dive4elements.river.jfree.RiverAnnotation; | |
27 import org.dive4elements.river.jfree.StyledXYSeries; | |
28 import org.dive4elements.river.themes.ThemeDocument; | |
29 import org.jfree.chart.axis.NumberAxis; | |
30 import org.jfree.chart.axis.ValueAxis; | |
31 import org.jfree.chart.plot.XYPlot; | |
32 import org.jfree.data.Range; | |
33 import org.jfree.data.xy.XYSeries; | |
9268
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
34 import org.w3c.dom.Document; |
9252 | 35 |
36 /** | |
9398
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
37 * An OutGenerator that generates flood duration curves. |
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
38 * (based upon a copy of DurationCurveGenerator) |
9252 | 39 */ |
9265 | 40 public class FloodDurationCurveGenerator extends XYChartGenerator implements FacetTypes { |
9252 | 41 public static enum YAXIS { |
9265 | 42 W(0), Q(1); |
9252 | 43 public int idx; |
9265 | 44 |
9252 | 45 private YAXIS(final int c) { |
46 this.idx = c; | |
47 } | |
48 } | |
49 | |
50 /** Local log. */ | |
9265 | 51 private static Logger log = Logger.getLogger(FloodDurationCurveGenerator.class); |
9252 | 52 |
9265 | 53 private static final String I18N_CHART_TITLE = "sinfo.chart.flood_duration.curve.section.title"; |
9252 | 54 |
9265 | 55 private static final String I18N_CHART_SUBTITLE = "chart.duration.curve.subtitle"; |
9252 | 56 |
9265 | 57 private static final String I18N_XAXIS_LABEL = "sinfo.chart.flood_duration.curve.xaxis.label"; |
9252 | 58 |
9265 | 59 private static final String I18N_YAXIS_LABEL_W = "chart.duration.curve.yaxis.label.w"; |
9252 | 60 |
9312 | 61 private static final String I18N_YAXIS_LABEL_Q = "common.export.csv.header.q"; |
9265 | 62 |
63 private static final String I18N_CHART_TITLE_DEFAULT = "Dauerlinie"; | |
64 | |
65 private static final String I18N_XAXIS_LABEL_DEFAULT = "Überflutungsdauer [d/a]"; | |
9252 | 66 |
67 public FloodDurationCurveGenerator() { | |
68 super(); | |
69 } | |
70 | |
9268
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
71 @Override |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
72 public void init(final String outName, final Document request, final OutputStream out, final CallContext context) { |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
73 super.init(outName, request, out, context); |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
74 |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
75 FixChartGenerator.initCurrentKm(request, context); |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
76 } |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
77 |
9252 | 78 /** |
79 * Create Axis for given index. | |
9265 | 80 * |
9252 | 81 * @return axis with according internationalized label. |
82 */ | |
83 @Override | |
84 protected NumberAxis createYAxis(final int index) { | |
85 final Font labelFont = new Font("Tahoma", Font.BOLD, 14); | |
9265 | 86 final String label = getYAxisLabel(index); |
9252 | 87 |
88 final NumberAxis axis = createNumberAxis(index, label); | |
89 if (index == YAXIS.W.idx) { | |
90 axis.setAutoRangeIncludesZero(false); | |
91 } | |
92 axis.setLabelFont(labelFont); | |
93 return axis; | |
94 } | |
95 | |
96 @Override | |
97 protected String getDefaultChartTitle(final CallContext context) { | |
98 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | |
99 } | |
100 | |
101 @Override | |
9268
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
102 protected String getChartSubtitle(final CallContext context) { |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
103 // REMARK: can't use getDeaultChartSubtitle, because the standard implementation of getChartSubtitle will |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
104 // always use the subtitle from the settings, which will automatically be set during init. |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
105 final double currentKm = FixChartGenerator.getCurrentKm(context); |
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
106 return msg(I18N_CHART_SUBTITLE, "", getRiverName(), currentKm); |
9252 | 107 } |
108 | |
109 @Override | |
110 protected String getDefaultXAxisLabel(final CallContext context) { | |
111 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | |
112 } | |
113 | |
114 @Override | |
115 protected String getDefaultYAxisLabel(final int index) { | |
116 | |
117 String label = "default"; | |
118 if (index == YAXIS.W.idx) { | |
119 label = msg(I18N_YAXIS_LABEL_W, I18N_YAXIS_LABEL_W, getRiverUnit()); | |
9265 | 120 } else if (index == YAXIS.Q.idx) { |
9252 | 121 label = msg(I18N_YAXIS_LABEL_Q); |
122 } | |
123 return label; | |
124 } | |
125 | |
126 @Override | |
127 protected boolean zoomX(final XYPlot plot, final ValueAxis axis, final Bounds bounds, final Range x) { | |
128 | |
129 final boolean zoomin = super.zoom(plot, axis, bounds, x); | |
130 if (!zoomin) | |
131 axis.setLowerBound(0d); | |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
132 axis.setUpperBound(364); |
9252 | 133 return zoomin; |
134 } | |
135 | |
136 /** | |
137 * This method overrides the method in the parent class to set the lower | |
138 * bounds of the Q axis to 0. This axis should never display negative | |
139 * values on its own. | |
140 */ | |
141 @Override | |
142 protected boolean zoomY(final XYPlot plot, final ValueAxis axis, final Bounds bounds, final Range x) { | |
143 | |
144 final boolean zoomin = super.zoom(plot, axis, bounds, x); | |
145 if (!zoomin && axis instanceof IdentifiableNumberAxis) { | |
146 final String id = ((IdentifiableNumberAxis) axis).getId(); | |
147 if (YAXIS.Q.toString().equals(id)) | |
148 axis.setLowerBound(0d); | |
149 } | |
150 return zoomin; | |
151 } | |
152 | |
153 @Override | |
154 public void doOut(final ArtifactAndFacet artifactFacet, final ThemeDocument attr, final boolean visible) { | |
155 | |
156 final String name = artifactFacet.getFacetName(); | |
157 | |
158 log.debug("FloodDurationCurveGenerator.doOut: " + name); | |
159 | |
160 if (name == null || name.length() == 0) { | |
161 log.error("No facet given. Cannot create dataset."); | |
162 return; | |
163 } | |
164 | |
165 final CallContext context = getContext(); | |
166 | |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
167 // TODO: mainvalues.q |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
168 // TODO: mainvalues.w |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
169 // } else if (name.equals(MAINVALUES_Q) || name.equals(MAINVALUES_W)) { |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
170 // doAnnotations((RiverAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
171 |
9252 | 172 if (name.equals(DURATION_W)) { |
9265 | 173 doWOut((WQDay) (artifactFacet.getData(context)), artifactFacet, attr, visible); |
9312 | 174 } else if (name.equals(DURATION_Q)) { |
9265 | 175 doQOut((WQDay) artifactFacet.getData(context), artifactFacet, attr, visible); |
9312 | 176 } else if (name.equals(FloodDurationCurveProcessor.FACET_FLOOD_DURATION_MAINVALUES_Q) |
9259
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
177 || name.equals(FloodDurationCurveProcessor.FACET_FLOOD_DURATION_MAINVALUES_W)) { |
9252 | 178 doAnnotations((RiverAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
179 } else if (FloodDurationCurveProcessor.isInfrastructureFacet(name) && (artifactFacet.getData(context) != null)) { |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
180 doAnnotations((RiverAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
181 } else if (name.equals(MAINVALUES_Q) || name.equals(MAINVALUES_W)) { |
9595
9b39cfd39e59
Softwaretests...20181219 6.2.2: Sinfo/Ued Haupt-/Extremwerte queried for the current chart km instead of only the first in range
mschaefer
parents:
9556
diff
changeset
|
182 final MainValuesArtifact mva = new MainValuesArtifactWrapper((MainValuesArtifact) artifactFacet.getArtifact()); |
9b39cfd39e59
Softwaretests...20181219 6.2.2: Sinfo/Ued Haupt-/Extremwerte queried for the current chart km instead of only the first in range
mschaefer
parents:
9556
diff
changeset
|
183 if (context.getContextValue("currentKm") != null) |
9b39cfd39e59
Softwaretests...20181219 6.2.2: Sinfo/Ued Haupt-/Extremwerte queried for the current chart km instead of only the first in range
mschaefer
parents:
9556
diff
changeset
|
184 mva.addStringData("ld_locations", context.getContextValue("currentKm").toString()); |
9b39cfd39e59
Softwaretests...20181219 6.2.2: Sinfo/Ued Haupt-/Extremwerte queried for the current chart km instead of only the first in range
mschaefer
parents:
9556
diff
changeset
|
185 final ArtifactAndFacet mvaf = new ArtifactAndFacet(mva, artifactFacet.getFacet()); |
9b39cfd39e59
Softwaretests...20181219 6.2.2: Sinfo/Ued Haupt-/Extremwerte queried for the current chart km instead of only the first in range
mschaefer
parents:
9556
diff
changeset
|
186 doAnnotations((RiverAnnotation) mvaf.getData(context), mvaf, attr, visible); |
9252 | 187 } |
9259
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
188 // else if (name.equals(RELATIVE_POINT)) { |
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
189 // doPointOut((Point2D) artifactFacet.getData(context), artifactFacet, attr, visible); |
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
190 // } |
9252 | 191 else if (FacetTypes.IS.MANUALPOINTS(name)) { |
192 doPoints(artifactFacet.getData(context), artifactFacet, attr, visible, YAXIS.W.idx); | |
9312 | 193 } else { |
9252 | 194 log.warn("Unknown facet name: " + name); |
195 return; | |
196 } | |
197 } | |
198 | |
199 /** | |
200 * Creates the series for a duration curve's W facet. | |
201 * | |
9265 | 202 * @param wqdays |
203 * The WQDay store that contains the Ws. | |
9252 | 204 * @param theme |
205 */ | |
206 protected void doWOut(final WQDay wqdays, final ArtifactAndFacet aaf, final ThemeDocument theme, final boolean visible) { | |
207 | |
208 // log.debug("DurationCurveGenerator.doWOut"); | |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
209 final XYSeries series = new StyledXYSeries(aaf.getFacetName(), aaf.getFacetDescription(), theme); |
9252 | 210 final int size = wqdays.size(); |
211 for (int i = 0; i < size; i++) { | |
9265 | 212 final int day = wqdays.getDay(i); |
9252 | 213 final double w = wqdays.getW(i); |
214 series.add(day, w); | |
215 } | |
216 addAxisSeries(series, YAXIS.W.idx, visible); | |
217 } | |
218 | |
219 protected void doPointOut(final Point2D point, final ArtifactAndFacet aandf, final ThemeDocument theme, final boolean visible) { | |
220 | |
221 // log.debug("DurationCurveGenerator.doPointOut"); | |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
222 final XYSeries series = new StyledXYSeries(aandf.getFacetName(), aandf.getFacetDescription(), theme); |
9252 | 223 series.add(point.getX(), point.getY()); |
224 addAxisSeries(series, YAXIS.W.idx, visible); | |
225 } | |
226 | |
227 /** | |
228 * Creates the series for a duration curve's Q facet. | |
229 * | |
9265 | 230 * @param wqdays |
231 * The WQDay store that contains the Qs. | |
9252 | 232 * @param theme |
233 */ | |
234 protected void doQOut(final WQDay wqdays, final ArtifactAndFacet aaf, final ThemeDocument theme, final boolean visible) { | |
235 | |
236 // log.debug("DurationCurveGenerator.doQOut"); | |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
237 final XYSeries series = new StyledXYSeries(aaf.getFacetName(), aaf.getFacetDescription(), theme); |
9252 | 238 final int size = wqdays.size(); |
239 for (int i = 0; i < size; i++) { | |
9265 | 240 final int day = wqdays.getDay(i); |
9252 | 241 final double q = wqdays.getQ(i); |
242 series.add(day, q); | |
243 } | |
244 addAxisSeries(series, YAXIS.Q.idx, visible); | |
245 } | |
246 | |
247 @Override | |
248 protected YAxisWalker getYAxisWalker() { | |
249 return new YAxisWalker() { | |
250 @Override | |
251 public int length() { | |
252 return YAXIS.values().length; | |
253 } | |
254 | |
255 @Override | |
256 public String getId(final int idx) { | |
257 final YAXIS[] yaxes = YAXIS.values(); | |
258 return yaxes[idx].toString(); | |
259 } | |
260 }; | |
261 } | |
262 | |
263 // MainValue-Annotations should be visualized by | |
264 // a line that goes to the curve itself. | |
9265 | 265 } |