Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/CollisionCalcProcessor.java @ 9195:a4121ec450d6
'ca.'-issue
ExportContextCSV+PDF separated
uinfo.inundationduration url export
author | gernotbelger |
---|---|
date | Fri, 29 Jun 2018 14:52:54 +0200 |
parents | f9bb5d0a6ff3 |
children | 6393e05a9610 |
rev | line source |
---|---|
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
2 * Software engineering by |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
5 * |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
8 * documentation coming with Dive4Elements River for details. |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
9 */ |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
10 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
11 package org.dive4elements.river.artifacts.sinfo.common; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
12 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
13 import java.util.HashSet; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
14 import java.util.Map; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
15 import java.util.Set; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
16 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
18 import org.dive4elements.artifactdatabase.state.Facet; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
19 import org.dive4elements.artifacts.Artifact; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
20 import org.dive4elements.artifacts.CallContext; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
21 import org.dive4elements.river.artifacts.common.AbstractCalculationResult; |
9195 | 22 import org.dive4elements.river.artifacts.common.IResultType; |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
23 import org.dive4elements.river.artifacts.resources.Resources; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
24 import org.dive4elements.river.artifacts.sinfo.collision.CollisionCalcFacet; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
25 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
26 import org.dive4elements.river.exports.DiagramGenerator; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
27 import org.dive4elements.river.exports.StyledSeriesBuilder; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
28 import org.dive4elements.river.jfree.StyledXYSeries; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
29 import org.dive4elements.river.themes.ThemeDocument; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
30 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
31 /** |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
32 * Processor to generate the facet and data series of calculated bed collision counts |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
33 * |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
34 * @author Matthias Schäfer |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
35 * |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
36 */ |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
37 public final class CollisionCalcProcessor extends AbstractSInfoProcessor { |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
38 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
39 public static final String FACET_COLLISION_CALC_COUNT = "sinfo_facet_collision_calc_count"; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
40 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
41 private static final String I18N_AXIS_LABEL = "chart.collision_count.section.yaxis.label"; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
42 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
43 private static final String I18N_SERIES_NAME_PATTERN = "collision.count.title"; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
44 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
45 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
46 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
47 static { |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
48 HANDLED_FACET_TYPES.add(FACET_COLLISION_CALC_COUNT); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
49 } |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
50 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
51 public CollisionCalcProcessor() { |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
52 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
53 } |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
54 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
55 @Override |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
56 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
57 |
9195 | 58 return buildSeriesForType(generator, bundle, theme, visible, SInfoResultType.collisionCount); |
59 } | |
60 | |
61 // FIXME: move to super classs and use in many implementations | |
62 protected final String buildSeriesForType(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible, | |
63 final IResultType resultType) { | |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
64 final CallContext context = generator.getContext(); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
65 final Map<String, String> metaData = bundle.getFacet().getMetaData(); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
66 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
67 final Artifact artifact = bundle.getArtifact(); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
68 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
69 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
70 series.putMetaData(metaData, artifact, context); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
71 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
72 final String facetName = bundle.getFacetName(); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
73 |
9195 | 74 final AbstractCalculationResult data = (AbstractCalculationResult) bundle.getData(context); |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
75 if (data == null) { |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
76 // Check has been here before so we keep it for security reasons |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
77 // this should never happen though. |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
78 throw new IllegalStateException("Data is null for facet: " + facetName); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
79 } |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
80 |
9195 | 81 final double[][] points = data.getStationPoints(resultType); |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
82 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
83 StyledSeriesBuilder.addPoints(series, points, true); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
84 generator.addAxisSeries(series, getAxisName(), visible); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
85 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
86 return metaData.get("Y"); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
87 } |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
88 |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
89 public static final Facet createFacet(final CallContext context, final String hash, final String id, final AbstractCalculationResult result, |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
90 final int index) { |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
91 final String facetDescription = Resources.getMsg(context.getMeta(), I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, result.getLabel()); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
92 return new CollisionCalcFacet(index, FACET_COLLISION_CALC_COUNT, facetDescription, I18N_AXIS_LABEL, ComputeType.ADVANCE, id, hash); |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
93 } |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
diff
changeset
|
94 } |