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