Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoProcessor.java @ 9205:3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
author | gernotbelger |
---|---|
date | Mon, 02 Jul 2018 19:01:09 +0200 |
parents | 4f411c6ee3ae |
children | 0fc9c82e744e |
comparison
equal
deleted
inserted
replaced
9204:4f411c6ee3ae | 9205:3dae6b78e1da |
---|---|
66 catch (final Exception e) { | 66 catch (final Exception e) { |
67 log.error(e.getMessage(), e); | 67 log.error(e.getMessage(), e); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 protected static final AbstractCalculationResult getResult(final DiagramGenerator generator, final ArtifactAndFacet bundle) { | |
72 final CallContext context = generator.getContext(); | |
73 final AbstractCalculationResult data = (AbstractCalculationResult) bundle.getData(context); | |
74 if (data == null) { | |
75 // Check has been here before so we keep it for security reasons | |
76 // this should never happen though. | |
77 final String facetName = bundle.getFacetName(); | |
78 throw new IllegalStateException("Data is null for facet: " + facetName); | |
79 } | |
80 | |
81 return data; | |
82 } | |
83 | |
84 protected static final int getDataIndex(final ArtifactAndFacet bundle) { | |
85 return ((SInfoResultFacet) bundle.getFacet()).getDataIndex(); | |
86 } | |
87 | |
71 /** | 88 /** |
72 * @return The axis label | 89 * @return The axis label |
73 */ | 90 */ |
74 protected abstract String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible); | 91 protected abstract String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible); |
75 | 92 |
76 protected final String buildSeriesForType(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible, | 93 protected final String buildSeriesForType(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible, |
77 final IResultType resultType, final Double gapDistance) { | 94 final IResultType resultType, final Double gapDistance) { |
95 | |
96 final AbstractCalculationResult data = getResult(generator, bundle); | |
97 | |
98 final double[][] points = data.getStationPoints(resultType); | |
99 | |
100 return buildSeriesForType(points, generator, bundle, theme, visible, gapDistance); | |
101 } | |
102 | |
103 protected final String buildSeriesForType(final double[][] points, final DiagramGenerator generator, final ArtifactAndFacet bundle, | |
104 final ThemeDocument theme, final boolean visible, final Double gapDistance) { | |
78 final CallContext context = generator.getContext(); | 105 final CallContext context = generator.getContext(); |
79 final Map<String, String> metaData = bundle.getFacet().getMetaData(); | 106 final Map<String, String> metaData = bundle.getFacet().getMetaData(); |
80 | 107 |
81 final Artifact artifact = bundle.getArtifact(); | 108 final Artifact artifact = bundle.getArtifact(); |
82 | 109 |
83 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); | 110 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); |
84 series.putMetaData(metaData, artifact, context); | 111 series.putMetaData(metaData, artifact, context); |
85 | 112 |
86 final String facetName = bundle.getFacetName(); | 113 final String facetName = bundle.getFacetName(); |
87 | 114 |
88 final AbstractCalculationResult data = (AbstractCalculationResult) bundle.getData(context); | 115 final double[][] filteredPoints = filterPoints(points, context, artifact, facetName); |
89 if (data == null) { | |
90 // Check has been here before so we keep it for security reasons | |
91 // this should never happen though. | |
92 throw new IllegalStateException("Data is null for facet: " + facetName); | |
93 } | |
94 | |
95 final double[][] points = generatePoints(context, artifact, data, facetName, resultType); | |
96 | 116 |
97 if (gapDistance == null) | 117 if (gapDistance == null) |
98 StyledSeriesBuilder.addPoints(series, points, true); | 118 StyledSeriesBuilder.addPoints(series, filteredPoints, true); |
99 else | 119 else |
100 StyledSeriesBuilder.addPoints(series, points, true, gapDistance); | 120 StyledSeriesBuilder.addPoints(series, filteredPoints, true, gapDistance); |
101 | 121 |
102 generator.addAxisSeries(series, getAxisName(), visible); | 122 generator.addAxisSeries(series, getAxisName(), visible); |
103 | 123 |
104 return metaData.get("Y"); | 124 return metaData.get("Y"); |
105 } | 125 } |
106 | 126 |
107 protected final String buildSeriesForType1(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, | 127 // protected final String buildSeriesForType1(final DiagramGenerator generator, final ArtifactAndFacet bundle, final |
108 final boolean visible, | 128 // ThemeDocument theme, |
109 final IResultType resultType, final Double gapDistance) { | 129 // final boolean visible, final IResultType resultType, final Double gapDistance) { |
110 final CallContext context = generator.getContext(); | 130 // final CallContext context = generator.getContext(); |
111 final Map<String, String> metaData = bundle.getFacet().getMetaData(); | 131 // final Map<String, String> metaData = bundle.getFacet().getMetaData(); |
112 | 132 // |
113 final Artifact artifact = bundle.getArtifact(); | 133 // final Artifact artifact = bundle.getArtifact(); |
114 | 134 // |
115 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); | 135 // final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); |
116 series.putMetaData(metaData, artifact, context); | 136 // series.putMetaData(metaData, artifact, context); |
117 | 137 // |
118 final String facetName = bundle.getFacetName(); | 138 // final String facetName = bundle.getFacetName(); |
119 | 139 // |
120 final AbstractCalculationResult data = (AbstractCalculationResult) bundle.getData(context); | 140 // final AbstractCalculationResult data = (AbstractCalculationResult) bundle.getData(context); |
121 if (data == null) { | 141 // if (data == null) { |
122 // Check has been here before so we keep it for security reasons | 142 // // Check has been here before so we keep it for security reasons |
123 // this should never happen though. | 143 // // this should never happen though. |
124 throw new IllegalStateException("Data is null for facet: " + facetName); | 144 // throw new IllegalStateException("Data is null for facet: " + facetName); |
125 } | 145 // } |
126 | 146 // |
127 final double[][] points = generatePoints(context, artifact, data, facetName, resultType, bundle.getFacet().getIndex()); | 147 // final double[][] points = generatePoints(context, artifact, data, facetName, resultType, |
128 | 148 // bundle.getFacet().getIndex()); |
129 if (gapDistance == null) | 149 // |
130 StyledSeriesBuilder.addPoints(series, points, true); | 150 // if (gapDistance == null) |
131 else | 151 // StyledSeriesBuilder.addPoints(series, points, true); |
132 StyledSeriesBuilder.addPoints(series, points, true, gapDistance); | 152 // else |
133 | 153 // StyledSeriesBuilder.addPoints(series, points, true, gapDistance); |
134 generator.addAxisSeries(series, getAxisName(), visible); | 154 // |
135 | 155 // generator.addAxisSeries(series, getAxisName(), visible); |
136 return metaData.get("Y"); | 156 // |
137 } | 157 // return metaData.get("Y"); |
158 // } | |
138 | 159 |
139 protected final String buildSeriesForTkh(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, | 160 protected final String buildSeriesForTkh(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, |
140 final boolean visible) { | 161 final boolean visible) { |
141 final CallContext context = generator.getContext(); | 162 |
142 | 163 final AbstractTkhCalculationResult data = (AbstractTkhCalculationResult) getResult(generator, bundle); |
143 final String facetName = bundle.getFacetName(); | |
144 final AbstractTkhCalculationResult data = (AbstractTkhCalculationResult) bundle.getData(context); | |
145 if (data == null) { | |
146 // Check has been here before so we keep it for security reasons | |
147 // this should never happen though. | |
148 throw new IllegalStateException("Data is null for facet: " + facetName); | |
149 } | |
150 | 164 |
151 final StyledXYSeries seriesUp = new StyledXYSeries(bundle.getFacetDescription(), theme); | 165 final StyledXYSeries seriesUp = new StyledXYSeries(bundle.getFacetDescription(), theme); |
152 final double[][] pointsUp = data.getTkhUpPoints(); | 166 final double[][] pointsUp = data.getTkhUpPoints(); |
153 StyledSeriesBuilder.addPoints(seriesUp, pointsUp, true); | 167 StyledSeriesBuilder.addPoints(seriesUp, pointsUp, true); |
154 | 168 |
180 final String river = access.getRiverName(); | 194 final String river = access.getRiverName(); |
181 | 195 |
182 return scales.getRadius(river, start, end); | 196 return scales.getRadius(river, start, end); |
183 } | 197 } |
184 | 198 |
185 private double[][] generatePoints(final CallContext context, final Artifact artifact, final AbstractCalculationResult data, final String facetName, | 199 private double[][] filterPoints(final double[][] points, final CallContext context, final Artifact artifact, final String facetName) { |
186 final IResultType resultType) { | 200 |
187 | |
188 final double[][] points = data.getStationPoints(resultType); | |
189 if (facetName.endsWith(".filtered")) { | 201 if (facetName.endsWith(".filtered")) { |
190 final Double radius = findRadius(context, artifact); | 202 final Double radius = findRadius(context, artifact); |
191 return movingAverage(radius, points); | 203 return movingAverage(radius, points); |
192 } | 204 } |
193 | 205 |
194 return points; | 206 return points; |
195 } | 207 } |
196 | 208 |
197 private double[][] generatePoints(final CallContext context, final Artifact artifact, final AbstractCalculationResult data, final String facetName, | 209 // private double[][] generatePoints(final CallContext context, final Artifact artifact, final AbstractCalculationResult |
198 final IResultType resultType, final int index) { | 210 // data, final String facetName, |
199 | 211 // final IResultType resultType, final int index) { |
200 final double[][] points = data.getStationPoints(resultType, index); | 212 // |
201 if (facetName.endsWith(".filtered")) { | 213 // final double[][] points = data.getStationPoints(resultType, index); |
202 final Double radius = findRadius(context, artifact); | 214 // if (facetName.endsWith(".filtered")) { |
203 return movingAverage(radius, points); | 215 // final Double radius = findRadius(context, artifact); |
204 } | 216 // return movingAverage(radius, points); |
205 | 217 // } |
206 return points; | 218 // |
207 } | 219 // return points; |
220 // } | |
208 | 221 |
209 private double[][] movingAverage(final Double radius, final double[][] points) { | 222 private double[][] movingAverage(final Double radius, final double[][] points) { |
210 | 223 |
211 if (radius == null) | 224 if (radius == null) |
212 return points; | 225 return points; |
229 return generator.msg(this.yAxisLabel, this.yAxisLabel); | 242 return generator.msg(this.yAxisLabel, this.yAxisLabel); |
230 } | 243 } |
231 return generator.msg(this.i18n_axis_label, "MISSING"); | 244 return generator.msg(this.i18n_axis_label, "MISSING"); |
232 } | 245 } |
233 | 246 |
234 // Moved from SInfoLineProcessor: | |
235 protected static final Facet createFacet(final CallContext context, final String hash, final String id, final AbstractCalculationResult result, | 247 protected static final Facet createFacet(final CallContext context, final String hash, final String id, final AbstractCalculationResult result, |
236 final int index, final String axisLabel, final String facetId, final String description) { | 248 final int resultIndex, final String axisLabel, final String facetId, final String description) { |
249 return createFacet(context, hash, id, result, resultIndex, -1, axisLabel, facetId, description); | |
250 } | |
251 | |
252 protected static final Facet createFacet(final CallContext context, final String hash, final String id, final AbstractCalculationResult result, | |
253 final int resultIndex, final int dataIndex, final String axisLabel, final String facetId, final String description) { | |
237 final String facetFlowDepthFilteredDescription = Resources.getMsg(context.getMeta(), description, description, result.getLabel()); | 254 final String facetFlowDepthFilteredDescription = Resources.getMsg(context.getMeta(), description, description, result.getLabel()); |
238 return new SInfoResultFacet(index, facetId, facetFlowDepthFilteredDescription, axisLabel, ComputeType.ADVANCE, id, hash); | 255 return new SInfoResultFacet(resultIndex, dataIndex, facetId, facetFlowDepthFilteredDescription, axisLabel, ComputeType.ADVANCE, id, hash); |
239 } | 256 } |
240 | |
241 } | 257 } |