Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixAnalysisCompute.java @ 6844:437d056ce426
Part of flys/issue1168: Make facet names unique. It should help but there must be bug before the facet generation.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 15 Aug 2013 18:56:20 +0200 |
parents | a0078e5e3b39 |
children | b87b20c71407 |
comparison
equal
deleted
inserted
replaced
6843:2e002f989c24 | 6844:437d056ce426 |
---|---|
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.states.fixation; | 9 package org.dive4elements.river.artifacts.states.fixation; |
10 | 10 |
11 import java.text.DateFormat; | 11 import java.text.DateFormat; |
12 import java.util.Collection; | |
12 import java.util.Date; | 13 import java.util.Date; |
14 import java.util.HashMap; | |
13 import java.util.List; | 15 import java.util.List; |
16 import java.util.Map; | |
14 | 17 |
15 import org.apache.log4j.Logger; | 18 import org.apache.log4j.Logger; |
16 | 19 |
17 import org.dive4elements.artifactdatabase.state.Facet; | 20 import org.dive4elements.artifactdatabase.state.Facet; |
18 import org.dive4elements.artifactdatabase.state.FacetActivity; | 21 import org.dive4elements.artifactdatabase.state.FacetActivity; |
39 import org.dive4elements.river.artifacts.model.fixings.FixOutlierFacet; | 42 import org.dive4elements.river.artifacts.model.fixings.FixOutlierFacet; |
40 import org.dive4elements.river.artifacts.model.fixings.FixReferenceEventsFacet; | 43 import org.dive4elements.river.artifacts.model.fixings.FixReferenceEventsFacet; |
41 import org.dive4elements.river.artifacts.model.fixings.FixWQCurveFacet; | 44 import org.dive4elements.river.artifacts.model.fixings.FixWQCurveFacet; |
42 import org.dive4elements.river.artifacts.resources.Resources; | 45 import org.dive4elements.river.artifacts.resources.Resources; |
43 import org.dive4elements.river.artifacts.states.DefaultState; | 46 import org.dive4elements.river.artifacts.states.DefaultState; |
47 import org.dive4elements.river.utils.Formatter; | |
44 import org.dive4elements.river.utils.IdGenerator; | 48 import org.dive4elements.river.utils.IdGenerator; |
45 | 49 |
46 /** | 50 /** |
47 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 51 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
48 */ | 52 */ |
169 int sectorMask = fr.getUsedSectorsInAnalysisPeriods(); | 173 int sectorMask = fr.getUsedSectorsInAnalysisPeriods(); |
170 | 174 |
171 int qsS = access.getQSectorStart(); | 175 int qsS = access.getQSectorStart(); |
172 int qsE = access.getQSectorEnd(); | 176 int qsE = access.getQSectorEnd(); |
173 | 177 |
174 // TODO: i18n | 178 DateFormat df = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy"); |
175 DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); | 179 DateFormat lf = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyy'T'HH:mm"); |
176 | 180 |
177 DateRange [] periods = access.getAnalysisPeriods(); | 181 DateRange [] periods = access.getAnalysisPeriods(); |
178 | 182 |
179 for (int i = 0; i < periods.length; i++) { | 183 for (int i = 0; i < periods.length; i++) { |
180 DateRange period = periods[i]; | 184 DateRange period = periods[i]; |
181 String startDate = df.format(period.getFrom()); | 185 String startDate = df.format(period.getFrom()); |
182 String endDate = df.format(period.getTo()); | 186 String endDate = df.format(period.getTo()); |
183 | 187 |
184 for (int j = qsS; j <= qsE; j++) { | 188 for (int j = qsS; j <= qsE; j++) { |
185 | 189 |
186 // Only emit facets for sectors that really have data. | 190 // Only emit facets for sectors that really have data. |
187 if ((sectorMask & (1 << j)) == 0) { | 191 if ((sectorMask & (1 << j)) == 0) { |
231 String eventDesc = | 235 String eventDesc = |
232 Resources.getMsg(context.getMeta(), | 236 Resources.getMsg(context.getMeta(), |
233 I18N_ANALYSIS, | 237 I18N_ANALYSIS, |
234 I18N_ANALYSIS); | 238 I18N_ANALYSIS); |
235 | 239 |
240 Collection<Date> aeds = fr.getAnalysisEventsDates(i); | |
241 UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, aeds); | |
242 | |
236 int k = 0; | 243 int k = 0; |
237 for (Date d: fr.getAnalysisEventsDates(i)) { | 244 for (Date d: aeds) { |
238 int anaNdx = i << 8; | 245 int anaNdx = i << 8; |
239 anaNdx = anaNdx | k; | 246 anaNdx = anaNdx | k; |
240 facets.add(new FixAnalysisEventsFacet(anaNdx, | 247 facets.add(new FixAnalysisEventsFacet(anaNdx, |
241 FIX_ANALYSIS_EVENTS_DWT, | 248 FIX_ANALYSIS_EVENTS_DWT, |
242 eventDesc + (i+1) + " - " + df.format(d))); | 249 eventDesc + (i+1) + " - " + cf.format(d))); |
243 facets.add(new FixLongitudinalAnalysisFacet(anaNdx, | 250 facets.add(new FixLongitudinalAnalysisFacet(anaNdx, |
244 FIX_ANALYSIS_EVENTS_LS, | 251 FIX_ANALYSIS_EVENTS_LS, |
245 eventDesc + (i+1) + " - " + df.format(d))); | 252 eventDesc + (i+1) + " - " + cf.format(d))); |
246 facets.add(new FixAnalysisEventsFacet(anaNdx, | 253 facets.add(new FixAnalysisEventsFacet(anaNdx, |
247 FIX_ANALYSIS_EVENTS_WQ, | 254 FIX_ANALYSIS_EVENTS_WQ, |
248 eventDesc + (i+1) +" - " + df.format(d))); | 255 eventDesc + (i+1) +" - " + cf.format(d))); |
249 k++; | 256 k++; |
250 } | 257 } |
251 } | 258 } |
252 | 259 |
253 IdGenerator idg = new IdGenerator(maxId + 1); | 260 IdGenerator idg = new IdGenerator(maxId + 1); |
257 I18N_REFERENCEPERIOD_SHORT); | 264 I18N_REFERENCEPERIOD_SHORT); |
258 String i18n_dev = Resources.getMsg(context.getMeta(), | 265 String i18n_dev = Resources.getMsg(context.getMeta(), |
259 I18N_REFERENCEDEVIATION, | 266 I18N_REFERENCEDEVIATION, |
260 I18N_REFERENCEDEVIATION); | 267 I18N_REFERENCEDEVIATION); |
261 | 268 |
269 Collection<Date> reds = fr.getReferenceEventsDates(); | |
270 UniqueDateFormatter cf = new UniqueDateFormatter(df, lf, reds); | |
271 | |
262 int i = 0; | 272 int i = 0; |
263 for (Date d: fr.getReferenceEventsDates()) { | 273 for (Date d: reds) { |
264 int refNdx = idg.next() << 8; | 274 int refNdx = idg.next() << 8; |
265 refNdx |= i; | 275 refNdx |= i; |
266 facets.add(new FixReferenceEventsFacet(refNdx, | 276 facets.add(new FixReferenceEventsFacet(refNdx, |
267 FIX_REFERENCE_EVENTS_DWT, | 277 FIX_REFERENCE_EVENTS_DWT, |
268 i18n_ref + " - " + df.format(d))); | 278 i18n_ref + " - " + cf.format(d))); |
269 refNdx = idg.next() << 8; | 279 refNdx = idg.next() << 8; |
270 refNdx = refNdx | i; | 280 refNdx = refNdx | i; |
271 facets.add(new FixLongitudinalReferenceFacet(refNdx, | 281 facets.add(new FixLongitudinalReferenceFacet(refNdx, |
272 FIX_REFERENCE_EVENTS_LS, | 282 FIX_REFERENCE_EVENTS_LS, |
273 i18n_ref + " - " + df.format(d))); | 283 i18n_ref + " - " + cf.format(d))); |
274 refNdx = idg.next() << 8; | 284 refNdx = idg.next() << 8; |
275 refNdx |= i; | 285 refNdx |= i; |
276 facets.add(new FixReferenceEventsFacet(refNdx, | 286 facets.add(new FixReferenceEventsFacet(refNdx, |
277 FIX_REFERENCE_EVENTS_WQ, | 287 FIX_REFERENCE_EVENTS_WQ, |
278 i18n_ref + " - " + df.format(d))); | 288 i18n_ref + " - " + cf.format(d))); |
279 i++; | 289 i++; |
280 } | 290 } |
281 | |
282 | 291 |
283 facets.add(new FixLongitudinalDeviationFacet(idg.next(), | 292 facets.add(new FixLongitudinalDeviationFacet(idg.next(), |
284 FIX_DEVIATION_LS, | 293 FIX_DEVIATION_LS, |
285 i18n_dev)); | 294 i18n_dev)); |
286 | 295 |
331 Resources.getMsg(context.getMeta(), | 340 Resources.getMsg(context.getMeta(), |
332 I18N_DEVIATION, | 341 I18N_DEVIATION, |
333 I18N_DEVIATION))); | 342 I18N_DEVIATION))); |
334 return res; | 343 return res; |
335 } | 344 } |
345 | |
346 /** Little hack to format dates unique if they collide. */ | |
347 private static class UniqueDateFormatter { | |
348 | |
349 private DateFormat df; | |
350 private DateFormat lf; | |
351 private Map<String, int[]> collisions; | |
352 | |
353 UniqueDateFormatter( | |
354 DateFormat df, | |
355 DateFormat lf, | |
356 Collection<Date> dates | |
357 ) { | |
358 this.df = df; | |
359 this.lf = lf; | |
360 collisions = build(dates); | |
361 } | |
362 | |
363 private Map<String, int []> build(Collection<Date> dates) { | |
364 Map<String, int []> collisions = new HashMap<String, int[]>(); | |
365 for (Date d: dates) { | |
366 String s = df.format(d); | |
367 int [] count = collisions.get(s); | |
368 if (count == null) { | |
369 collisions.put(s, count = new int[1]); | |
370 } | |
371 if (++count[0] > 1) { | |
372 log.debug("date collsion found: " + d); | |
373 } | |
374 } | |
375 return collisions; | |
376 } | |
377 | |
378 String format(Date date) { | |
379 String s = df.format(date); | |
380 int [] count = collisions.get(s); | |
381 return count == null || count[0] < 2 | |
382 ? s | |
383 : lf.format(date); | |
384 } | |
385 } // class UniqueDateFormatter | |
336 } | 386 } |
337 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 387 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |