Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixAnalysisCompute.java @ 9082:42c15e2f95fb
2.3.4.1.4 Wasserstand falsche Einheit
FixAnalysis PDF start
author | gernotbelger |
---|---|
date | Fri, 25 May 2018 10:44:24 +0200 |
parents | 5e38e2924c07 |
children | ddcd52d239cd |
comparison
equal
deleted
inserted
replaced
9081:a0feac6ea1ba | 9082:42c15e2f95fb |
---|---|
12 import java.util.Collection; | 12 import java.util.Collection; |
13 import java.util.Date; | 13 import java.util.Date; |
14 import java.util.List; | 14 import java.util.List; |
15 | 15 |
16 import org.apache.log4j.Logger; | 16 import org.apache.log4j.Logger; |
17 | |
18 import org.dive4elements.artifactdatabase.state.Facet; | 17 import org.dive4elements.artifactdatabase.state.Facet; |
19 import org.dive4elements.artifactdatabase.state.FacetActivity; | 18 import org.dive4elements.artifactdatabase.state.FacetActivity; |
20 import org.dive4elements.artifacts.Artifact; | 19 import org.dive4elements.artifacts.Artifact; |
21 import org.dive4elements.artifacts.CallContext; | 20 import org.dive4elements.artifacts.CallContext; |
22 import org.dive4elements.river.artifacts.D4EArtifact; | 21 import org.dive4elements.river.artifacts.D4EArtifact; |
47 import org.dive4elements.river.utils.UniqueDateFormatter; | 46 import org.dive4elements.river.utils.UniqueDateFormatter; |
48 | 47 |
49 /** | 48 /** |
50 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 49 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
51 */ | 50 */ |
52 public class FixAnalysisCompute | 51 public class FixAnalysisCompute extends DefaultState implements FacetTypes { |
53 extends DefaultState | |
54 implements FacetTypes | |
55 { | |
56 /** The log used in this class. */ | 52 /** The log used in this class. */ |
57 private static Logger log = Logger.getLogger(FixAnalysisCompute.class); | 53 private static Logger log = Logger.getLogger(FixAnalysisCompute.class); |
58 | 54 |
59 private static final String I18N_REFERENCEPERIOD_SHORT = | 55 private static final String I18N_REFERENCEPERIOD_SHORT = "fix.reference.period.event.short"; |
60 "fix.reference.period.event.short"; | |
61 | 56 |
62 private static final String I18N_ANALYSISPERIODS = "fix.analysis.periods"; | 57 private static final String I18N_ANALYSISPERIODS = "fix.analysis.periods"; |
63 | 58 |
64 private static final String I18N_DERIVATIVE = "fix.derivative"; | 59 private static final String I18N_DERIVATIVE = "fix.derivative"; |
65 | 60 |
67 | 62 |
68 private static final String I18N_ANALYSIS = "fix.analysis.short"; | 63 private static final String I18N_ANALYSIS = "fix.analysis.short"; |
69 | 64 |
70 private static final String I18N_DEVIATION = "fix.deviation"; | 65 private static final String I18N_DEVIATION = "fix.deviation"; |
71 | 66 |
72 private static final String I18N_REFERENCEDEVIATION = | 67 private static final String I18N_REFERENCEDEVIATION = "fix.reference.deviation"; |
73 "fix.reference.deviation"; | 68 |
74 | 69 private static final String I18N_REFERENCEPERIOD = "state.fix.analysis.referenceperiod"; |
75 private static final String I18N_REFERENCEPERIOD = | 70 |
76 "state.fix.analysis.referenceperiod"; | 71 public static final String[] SECTOR_LABELS = { "fix.mnq", "fix.mq", "fix.mhq", "fix.hq5" }; |
77 | |
78 public static final String [] SECTOR_LABELS = { | |
79 "fix.mnq", | |
80 "fix.mq", | |
81 "fix.mhq", | |
82 "fix.hq5" | |
83 }; | |
84 | 72 |
85 static { | 73 static { |
86 // Active/deactivate facets. | 74 // Active/deactivate facets. |
87 FacetActivity.Registry.getInstance().register( | 75 FacetActivity.Registry.getInstance().register("fixanalysis", new FacetActivity() { |
88 "fixanalysis", | 76 @Override |
89 new FacetActivity() { | 77 public Boolean isInitialActive(final Artifact artifact, final Facet facet, final String output) { |
90 @Override | 78 if (output.contains(FacetTypes.ChartType.FLSC.toString())) { |
91 public Boolean isInitialActive( | 79 // Longitudinal section chart |
92 Artifact artifact, | 80 final String name = facet.getName(); |
93 Facet facet, | 81 |
94 String output | 82 if (name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_DWT) || name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_LS) |
95 ) { | 83 || name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_WQ) || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_DWT) |
96 if ( | 84 || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_LS) || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_WQ)) { |
97 output.contains(FacetTypes.ChartType.FLSC.toString()) | |
98 ) { | |
99 // Longitudinal section chart | |
100 String name = facet.getName(); | |
101 | |
102 if (name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_DWT) | |
103 || name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_LS) | |
104 || name.contains(FacetTypes.FIX_ANALYSIS_EVENTS_WQ) | |
105 || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_DWT) | |
106 || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_LS) | |
107 || name.contains(FacetTypes.FIX_REFERENCE_EVENTS_WQ) | |
108 ) { | |
109 return Boolean.FALSE; | |
110 } | |
111 } | |
112 if (output.contains(FacetTypes.ChartType.FDWC.toString()) | |
113 && facet.getName().contains( | |
114 FacetTypes.FIX_SECTOR_AVERAGE_DWT)) { | |
115 return Boolean.FALSE; | 85 return Boolean.FALSE; |
116 } | 86 } |
117 | 87 } |
118 return Boolean.TRUE; | 88 if (output.contains(FacetTypes.ChartType.FDWC.toString()) && facet.getName().contains(FacetTypes.FIX_SECTOR_AVERAGE_DWT)) { |
119 } | 89 return Boolean.FALSE; |
120 }); | 90 } |
91 | |
92 return Boolean.TRUE; | |
93 } | |
94 }); | |
121 } | 95 } |
122 | |
123 | 96 |
124 /** | 97 /** |
125 * The default constructor that initializes an empty State object. | 98 * The default constructor that initializes an empty State object. |
126 */ | 99 */ |
127 public FixAnalysisCompute() { | 100 public FixAnalysisCompute() { |
128 } | 101 } |
129 | 102 |
130 | |
131 @Override | 103 @Override |
132 public Object computeAdvance( | 104 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
133 D4EArtifact artifact, | |
134 String hash, | |
135 CallContext context, | |
136 List<Facet> facets, | |
137 Object old | |
138 ) { | |
139 log.debug("FixAnalysisCompute.computeAdvance"); | 105 log.debug("FixAnalysisCompute.computeAdvance"); |
140 | 106 |
141 CalculationResult res; | 107 CalculationResult res; |
142 | 108 |
143 FixAnalysisAccess access = new FixAnalysisAccess(artifact); | 109 final FixAnalysisAccess access = new FixAnalysisAccess(artifact); |
144 | 110 |
145 if (old instanceof CalculationResult) { | 111 if (old instanceof CalculationResult) { |
146 res = (CalculationResult)old; | 112 res = (CalculationResult) old; |
147 } | 113 } else { |
148 else { | 114 final FixAnalysisCalculation calc = new FixAnalysisCalculation(access); |
149 FixAnalysisCalculation calc = new FixAnalysisCalculation(access); | |
150 res = calc.calculate(); | 115 res = calc.calculate(); |
151 } | 116 } |
152 | 117 |
153 if (facets == null) { | 118 if (facets == null) { |
154 return res; | 119 return res; |
155 } | 120 } |
156 | 121 |
157 if (res.getReport().hasProblems()) { | 122 if (res.getReport().hasProblems()) { |
158 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); | 123 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); |
159 } | 124 } |
160 | 125 |
161 FixAnalysisResult fr = (FixAnalysisResult)res.getData(); | 126 final FixAnalysisResult fr = (FixAnalysisResult) res.getData(); |
162 if (fr == null) { | 127 if (fr == null) { |
163 return res; | 128 return res; |
164 } | 129 } |
165 | 130 |
166 facets.add( | 131 facets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, this.id)); |
167 new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | 132 facets.add(new DataFacet(FIX_PARAMETERS, "parameters", ComputeType.ADVANCE, hash, this.id)); |
168 facets.add( | 133 facets.add(new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, this.id)); |
169 new DataFacet( | 134 facets.add(new DataFacet(PDF, "PDF data", ComputeType.ADVANCE, hash, this.id)); |
170 FIX_PARAMETERS, "parameters", ComputeType.ADVANCE, hash, id)); | |
171 facets.add( | |
172 new DataFacet(AT, "AT data", ComputeType.ADVANCE, hash, id)); | |
173 | 135 |
174 int maxId = -100; | 136 int maxId = -100; |
175 | 137 |
176 int sectorMask = fr.getUsedSectorsInAnalysisPeriods(); | 138 final int sectorMask = fr.getUsedSectorsInAnalysisPeriods(); |
177 | 139 |
178 int qsS = access.getQSectorStart(); | 140 final int qsS = access.getQSectorStart(); |
179 int qsE = access.getQSectorEnd(); | 141 final int qsE = access.getQSectorEnd(); |
180 | 142 |
181 DateFormat df = Formatter.getDateFormatter( | 143 final DateFormat df = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy"); |
182 context.getMeta(), "dd.MM.yyyy"); | 144 final DateFormat lf = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy'T'HH:mm"); |
183 DateFormat lf = Formatter.getDateFormatter( | 145 |
184 context.getMeta(), "dd.MM.yyyy'T'HH:mm"); | 146 final DateRange[] periods = access.getAnalysisPeriods(); |
185 | |
186 DateRange [] periods = access.getAnalysisPeriods(); | |
187 | 147 |
188 for (int i = 0; i < periods.length; i++) { | 148 for (int i = 0; i < periods.length; i++) { |
189 DateRange period = periods[i]; | 149 final DateRange period = periods[i]; |
190 String startDate = df.format(period.getFrom()); | 150 final String startDate = df.format(period.getFrom()); |
191 String endDate = df.format(period.getTo()); | 151 final String endDate = df.format(period.getTo()); |
192 | 152 |
193 for (int j = qsS; j <= qsE; j++) { | 153 for (int j = qsS; j <= qsE; j++) { |
194 | 154 |
195 // Only emit facets for sectors that really have data. | 155 // Only emit facets for sectors that really have data. |
196 if ((sectorMask & (1 << j)) == 0) { | 156 if ((sectorMask & (1 << j)) == 0) { |
197 continue; | 157 continue; |
198 } | 158 } |
199 | 159 |
200 String sector = SECTOR_LABELS[j]; | 160 final String sector = SECTOR_LABELS[j]; |
201 String description = "\u0394W (" + | 161 final String description = "\u0394W (" + Resources.getMsg(context.getMeta(), sector, sector) + ")"; |
202 Resources.getMsg(context.getMeta(), | 162 |
203 sector, | 163 final int sectorNdx = j - qsS; |
204 sector) + | |
205 ")"; | |
206 | |
207 int sectorNdx = j - qsS; | |
208 int facetNdx = i << 2; | 164 int facetNdx = i << 2; |
209 facetNdx = facetNdx | j; | 165 facetNdx = facetNdx | j; |
210 | 166 |
211 if (facetNdx > maxId) { | 167 if (facetNdx > maxId) { |
212 maxId = facetNdx; | 168 maxId = facetNdx; |
213 } | 169 } |
214 | 170 |
171 facets.add(new FixAvSectorFacet(facetNdx, FIX_SECTOR_AVERAGE_DWT + "_" + sectorNdx, description)); | |
215 facets.add( | 172 facets.add( |
216 new FixAvSectorFacet( | 173 new FixLongitudinalAvSectorFacet(facetNdx, FIX_SECTOR_AVERAGE_LS + "_" + sectorNdx, description + ":" + startDate + " - " + endDate)); |
217 facetNdx, | |
218 FIX_SECTOR_AVERAGE_DWT + "_" + sectorNdx, | |
219 description)); | |
220 facets.add( | |
221 new FixLongitudinalAvSectorFacet( | |
222 facetNdx, | |
223 FIX_SECTOR_AVERAGE_LS + "_" + sectorNdx, | |
224 description + ":" + startDate + " - " + endDate)); | |
225 // TODO: i18n | 174 // TODO: i18n |
226 String dev = "Abweichung: " + description; | 175 final String dev = "Abweichung: " + description; |
227 facets.add( | 176 facets.add(new FixLongitudinalAvSectorFacet(facetNdx, FIX_SECTOR_AVERAGE_LS_DEVIATION + "_" + sectorNdx, dev)); |
228 new FixLongitudinalAvSectorFacet( | 177 facets.add(new FixAvSectorFacet(facetNdx, FIX_SECTOR_AVERAGE_WQ + "_" + sectorNdx, description)); |
229 facetNdx, | |
230 FIX_SECTOR_AVERAGE_LS_DEVIATION + "_" + sectorNdx, | |
231 dev)); | |
232 facets.add( | |
233 new FixAvSectorFacet( | |
234 facetNdx, | |
235 FIX_SECTOR_AVERAGE_WQ + "_" + sectorNdx, | |
236 description)); | |
237 | 178 |
238 } | 179 } |
239 | 180 |
240 String eventDesc = | 181 final String eventDesc = Resources.getMsg(context.getMeta(), I18N_ANALYSIS, I18N_ANALYSIS); |
241 Resources.getMsg(context.getMeta(), | 182 |
242 I18N_ANALYSIS, | 183 final Collection<Date> aeds = fr.getAnalysisEventsDates(i); |
243 I18N_ANALYSIS); | 184 final UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, aeds); |
244 | |
245 Collection<Date> aeds = fr.getAnalysisEventsDates(i); | |
246 UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, aeds); | |
247 | 185 |
248 int k = 0; | 186 int k = 0; |
249 for (Date d: aeds) { | 187 for (final Date d : aeds) { |
250 int anaNdx = i << 8; | 188 int anaNdx = i << 8; |
251 anaNdx = anaNdx | k; | 189 anaNdx = anaNdx | k; |
252 facets.add(new FixAnalysisEventsFacet(anaNdx, | 190 facets.add(new FixAnalysisEventsFacet(anaNdx, FIX_ANALYSIS_EVENTS_DWT, eventDesc + (i + 1) + " - " + cf.format(d))); |
253 FIX_ANALYSIS_EVENTS_DWT, | 191 facets.add(new FixLongitudinalAnalysisFacet(anaNdx, FIX_ANALYSIS_EVENTS_LS, eventDesc + (i + 1) + " - " + cf.format(d))); |
254 eventDesc + (i+1) + " - " + cf.format(d))); | 192 facets.add(new FixAnalysisEventsFacet(anaNdx, FIX_ANALYSIS_EVENTS_WQ, eventDesc + (i + 1) + " - " + cf.format(d))); |
255 facets.add(new FixLongitudinalAnalysisFacet(anaNdx, | |
256 FIX_ANALYSIS_EVENTS_LS, | |
257 eventDesc + (i+1) + " - " + cf.format(d))); | |
258 facets.add(new FixAnalysisEventsFacet(anaNdx, | |
259 FIX_ANALYSIS_EVENTS_WQ, | |
260 eventDesc + (i+1) +" - " + cf.format(d))); | |
261 k++; | 193 k++; |
262 } | 194 } |
263 } | 195 } |
264 | 196 |
265 IdGenerator idg = new IdGenerator(maxId + 1); | 197 final IdGenerator idg = new IdGenerator(maxId + 1); |
266 | 198 |
267 String i18n_ref = Resources.getMsg(context.getMeta(), | 199 final String i18n_ref = Resources.getMsg(context.getMeta(), I18N_REFERENCEPERIOD_SHORT, I18N_REFERENCEPERIOD_SHORT); |
268 I18N_REFERENCEPERIOD_SHORT, | 200 final String i18n_dev = Resources.getMsg(context.getMeta(), I18N_REFERENCEDEVIATION, I18N_REFERENCEDEVIATION); |
269 I18N_REFERENCEPERIOD_SHORT); | 201 |
270 String i18n_dev = Resources.getMsg(context.getMeta(), | 202 final Collection<Date> reds = fr.getReferenceEventsDates(); |
271 I18N_REFERENCEDEVIATION, | 203 final UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, reds); |
272 I18N_REFERENCEDEVIATION); | |
273 | |
274 Collection<Date> reds = fr.getReferenceEventsDates(); | |
275 UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, reds); | |
276 | 204 |
277 int i = 0; | 205 int i = 0; |
278 for (Date d: reds) { | 206 for (final Date d : reds) { |
279 int refNdx = idg.next() << 8; | 207 int refNdx = idg.next() << 8; |
280 refNdx |= i; | 208 refNdx |= i; |
281 facets.add(new FixReferenceEventsFacet(refNdx, | 209 facets.add(new FixReferenceEventsFacet(refNdx, FIX_REFERENCE_EVENTS_DWT, i18n_ref + " - " + cf.format(d))); |
282 FIX_REFERENCE_EVENTS_DWT, | |
283 i18n_ref + " - " + cf.format(d))); | |
284 refNdx = idg.next() << 8; | 210 refNdx = idg.next() << 8; |
285 refNdx = refNdx | i; | 211 refNdx = refNdx | i; |
286 facets.add(new FixLongitudinalReferenceFacet(refNdx, | 212 facets.add(new FixLongitudinalReferenceFacet(refNdx, FIX_REFERENCE_EVENTS_LS, i18n_ref + " - " + cf.format(d))); |
287 FIX_REFERENCE_EVENTS_LS, | |
288 i18n_ref + " - " + cf.format(d))); | |
289 refNdx = idg.next() << 8; | 213 refNdx = idg.next() << 8; |
290 refNdx |= i; | 214 refNdx |= i; |
291 facets.add(new FixReferenceEventsFacet(refNdx, | 215 facets.add(new FixReferenceEventsFacet(refNdx, FIX_REFERENCE_EVENTS_WQ, i18n_ref + " - " + cf.format(d))); |
292 FIX_REFERENCE_EVENTS_WQ, | |
293 i18n_ref + " - " + cf.format(d))); | |
294 i++; | 216 i++; |
295 } | 217 } |
296 | 218 |
297 facets.add(new FixLongitudinalDeviationFacet(idg.next(), | 219 facets.add(new FixLongitudinalDeviationFacet(idg.next(), FIX_DEVIATION_LS, i18n_dev)); |
298 FIX_DEVIATION_LS, | 220 |
299 i18n_dev)); | 221 final String i18n_ana = Resources.getMsg(context.getMeta(), I18N_ANALYSISPERIODS, I18N_ANALYSISPERIODS); |
300 | 222 facets.add(new FixAnalysisPeriodsFacet(idg.next(), FIX_ANALYSIS_PERIODS_DWT, i18n_ana)); |
301 String i18n_ana = Resources.getMsg(context.getMeta(), | 223 facets.add(new FixAnalysisPeriodsFacet(idg.next(), FIX_ANALYSIS_PERIODS_LS, i18n_ana)); |
302 I18N_ANALYSISPERIODS, | 224 facets.add(new FixAnalysisPeriodsFacet(idg.next(), FIX_ANALYSIS_PERIODS_WQ, i18n_ana)); |
303 I18N_ANALYSISPERIODS); | 225 |
304 facets.add(new FixAnalysisPeriodsFacet(idg.next(), | 226 final String i18n_refp = Resources.getMsg(context.getMeta(), I18N_REFERENCEPERIOD, I18N_REFERENCEPERIOD); |
305 FIX_ANALYSIS_PERIODS_DWT, | 227 facets.add(new DataFacet(idg.next(), FIX_REFERENCE_PERIOD_DWT, i18n_refp, ComputeType.ADVANCE, null, null)); |
306 i18n_ana)); | |
307 facets.add(new FixAnalysisPeriodsFacet(idg.next(), | |
308 FIX_ANALYSIS_PERIODS_LS, | |
309 i18n_ana)); | |
310 facets.add(new FixAnalysisPeriodsFacet(idg.next(), | |
311 FIX_ANALYSIS_PERIODS_WQ, | |
312 i18n_ana)); | |
313 | |
314 String i18n_refp = Resources.getMsg(context.getMeta(), | |
315 I18N_REFERENCEPERIOD, | |
316 I18N_REFERENCEPERIOD); | |
317 facets.add(new DataFacet(idg.next(), | |
318 FIX_REFERENCE_PERIOD_DWT, | |
319 i18n_refp, | |
320 ComputeType.ADVANCE, null, null)); | |
321 | 228 |
322 facets.add(new FixWQCurveFacet(idg.next(), "W/Q")); | 229 facets.add(new FixWQCurveFacet(idg.next(), "W/Q")); |
323 | 230 |
324 Boolean preprocessing = access.getPreprocessing(); | 231 final Boolean preprocessing = access.getPreprocessing(); |
325 | 232 |
326 if (preprocessing != null && preprocessing) { | 233 if (preprocessing != null && preprocessing) { |
327 facets.add(new FixOutlierFacet( | 234 facets.add(new FixOutlierFacet(idg.next(), FIX_OUTLIER, Resources.getMsg(context.getMeta(), I18N_OUTLIER, I18N_OUTLIER))); |
328 idg.next(), | 235 } |
329 FIX_OUTLIER, | 236 |
330 Resources.getMsg( | 237 facets.add(new FixDerivateFacet(idg.next(), FIX_DERIVATE_CURVE, Resources.getMsg(context.getMeta(), I18N_DERIVATIVE, I18N_DERIVATIVE))); |
331 context.getMeta(), I18N_OUTLIER, I18N_OUTLIER))); | 238 |
332 } | 239 facets.add(new FixDeviationFacet(idg.next(), FIX_DEVIATION_DWT, Resources.getMsg(context.getMeta(), I18N_DEVIATION, I18N_DEVIATION))); |
333 | |
334 facets.add(new FixDerivateFacet( | |
335 idg.next(), | |
336 FIX_DERIVATE_CURVE, | |
337 Resources.getMsg( | |
338 context.getMeta(), | |
339 I18N_DERIVATIVE, | |
340 I18N_DERIVATIVE))); | |
341 | |
342 facets.add(new FixDeviationFacet( | |
343 idg.next(), | |
344 FIX_DEVIATION_DWT, | |
345 Resources.getMsg(context.getMeta(), | |
346 I18N_DEVIATION, | |
347 I18N_DEVIATION))); | |
348 return res; | 240 return res; |
349 } | 241 } |
350 } | 242 } |
351 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 243 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |