Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/CollisionCountProcessor.java @ 9166:3ead6937ae7c
Fixed data datatype to avoid cast exceptions
author | mschaefer |
---|---|
date | Wed, 20 Jun 2018 13:08:14 +0200 |
parents | f9bb5d0a6ff3 |
children | a4121ec450d6 |
rev | line source |
---|---|
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
2 * Software engineering by |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
5 * |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
8 * documentation coming with Dive4Elements River for details. |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
9 */ |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
10 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
11 package org.dive4elements.river.artifacts.sinfo.common; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
12 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
13 import java.util.HashSet; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
14 import java.util.Map; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
15 import java.util.Set; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
16 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
18 import org.dive4elements.artifactdatabase.state.Facet; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
19 import org.dive4elements.artifacts.Artifact; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
20 import org.dive4elements.artifacts.CallContext; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
21 import org.dive4elements.artifacts.CallMeta; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
22 import org.dive4elements.river.artifacts.resources.Resources; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
23 import org.dive4elements.river.artifacts.sinfo.collision.CollisionFacet; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
24 import org.dive4elements.river.artifacts.sinfo.collision.CollisionQueryCalculationResult; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
25 import org.dive4elements.river.exports.DiagramGenerator; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
26 import org.dive4elements.river.exports.StyledSeriesBuilder; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
27 import org.dive4elements.river.jfree.StyledXYSeries; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
28 import org.dive4elements.river.themes.ThemeDocument; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
29 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
30 /** |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
31 * Processor to generate a data series for bed collision count data loaded from the database |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
32 * |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
33 * @author Matthias Schäfer |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
34 * |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
35 */ |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
36 public class CollisionCountProcessor extends AbstractSInfoProcessor { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
37 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
38 // private final static Logger log = Logger.getLogger(CollisionCountProcessor.class); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
39 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
40 public static final String FACET_COLLISION_COUNT = "sinfo_facet_collision_count"; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
41 |
9126 | 42 private static final String I18N_AXIS_LABEL = "chart.collision_count.section.yaxis.label"; |
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
43 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
44 private static final String I18N_SERIES_NAME_PATTERN = "collision.count.title"; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
45 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
46 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
47 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
48 static { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
49 HANDLED_FACET_TYPES.add(FACET_COLLISION_COUNT); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
50 } |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
51 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
52 public CollisionCountProcessor() { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
53 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
54 } |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
55 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
56 @Override |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
57 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
58 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
59 final CallContext context = generator.getContext(); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
60 final Map<String, String> metaData = bundle.getFacet().getMetaData(); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
61 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
62 final Artifact artifact = bundle.getArtifact(); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
63 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
64 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
65 series.putMetaData(metaData, artifact, context); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
66 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
67 final String facetName = bundle.getFacetName(); |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9126
diff
changeset
|
68 |
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
69 final CollisionQueryCalculationResult data = (CollisionQueryCalculationResult) bundle.getData(context); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
70 if (data == null) { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
71 // Check has been here before so we keep it for security reasons |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
72 // this should never happen though. |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
73 throw new IllegalStateException("Data is null for facet: " + facetName); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
74 } |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
75 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
76 final double[][] points = data.getStationPoints(SInfoResultType.collisionCount); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
77 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
78 StyledSeriesBuilder.addPoints(series, points, true); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
79 generator.addAxisSeries(series, getAxisName(), visible); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
80 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
81 return metaData.get("Y"); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
82 } |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
83 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
84 public static Facet createFacet(final CallMeta callMeta, final String seriesName) { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
85 return new CollisionFacet(FACET_COLLISION_COUNT, |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
86 Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, seriesName), I18N_AXIS_LABEL); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
87 } |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9126
diff
changeset
|
88 |
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
89 } |