annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionArtifact.java @ 9202:b4402594213b

More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
author mschaefer
date Mon, 02 Jul 2018 07:33:53 +0200
parents f9bb5d0a6ff3
children 0fc9c82e744e
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.collision;
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.ArrayList;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
14 import java.util.List;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
15
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
16 import org.apache.log4j.Logger;
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.DefaultOutput;
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.artifactdatabase.state.FacetActivity;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
20 import org.dive4elements.artifacts.Artifact;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
21 import org.dive4elements.artifacts.ArtifactFactory;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
22 import org.dive4elements.artifacts.CallMeta;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
23 import org.dive4elements.artifacts.common.utils.XMLUtils;
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.AbstractStaticStateArtifact;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
25 import org.dive4elements.river.artifacts.D4EArtifact;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
26 import org.dive4elements.river.artifacts.model.FacetTypes;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
27 import org.dive4elements.river.artifacts.sinfo.common.CollisionCountProcessor;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
28 import org.dive4elements.river.artifacts.states.StaticState;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
29 import org.w3c.dom.Document;
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 /**
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
32 * Display of a river bed collision data series loaded from database
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
33 *
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
34 * @author Matthias Schäfer
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 */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
37 public class CollisionArtifact extends AbstractStaticStateArtifact implements FacetTypes {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
38
9157
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9125
diff changeset
39 private static final long serialVersionUID = 1L;
f9bb5d0a6ff3 Added the S-Info collision calculation and chart output
mschaefer
parents: 9125
diff changeset
40
9125
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
41 /** The log for this class. */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
42 private static Logger log = Logger.getLogger(CollisionArtifact.class);
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 /** Artifact name. */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
45 private static final String NAME = "collision";
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
46
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
47 static {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
48 // TODO: Move to configuration.
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
49 FacetActivity.Registry.getInstance().register(NAME, FacetActivity.INACTIVE);
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 static final String STATIC_STATE_NAME = "state.collision.static";
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
53
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 * Trivial Constructor.
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
56 */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
57 public CollisionArtifact() {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
58 log.debug("new CollisionArtifact");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
59 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
60
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
61 @Override
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
62 public String getName() {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
63 return NAME;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
64 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
65
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 * Gets called from factory, to set things up.
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
68 */
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
69 @Override
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
70 public void setup(final String identifier, final ArtifactFactory factory, final Object context, final CallMeta callMeta, final Document data,
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
71 final List<Class> loadFacets) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
72
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
73 log.debug("CollisionArtifact.setup");
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 if (log.isDebugEnabled()) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
76 log.debug(XMLUtils.toString(data));
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
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
79 final String code = getDatacageIDValue(data);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
80 final String[] parts = code.split("-");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
81 if (parts.length >= 2)
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
82 addStringData("collision_id", parts[1]);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
83 if (parts.length >= 3)
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
84 addStringData("year", parts[2]);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
85 else
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
86 addStringData("year", "jahr?");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
87 String seriesName;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
88 if (parts.length >= 4)
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
89 seriesName = parts[3];
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
90 else
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
91 seriesName = "name?";
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
92
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
93 createFacets(callMeta, code, seriesName, getDataAsString("year"));
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
94
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
95 super.setup(identifier, factory, context, callMeta, data, loadFacets);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
96 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
97
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
98 private void createFacets(final CallMeta callMeta, final String code, final String seriesName, final String year) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
99 if (code == null)
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
100 return;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
101 final String[] parts = code.split("-");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
102 if (parts.length < 2) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
103 log.error("Invalid datacage ID '" + code + "'");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
104 return;
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
105 }
9202
b4402594213b More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents: 9157
diff changeset
106 final ArrayList<Facet> facets = new ArrayList<>(1);
9125
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
107 facets.add(CollisionCountProcessor.createFacet(callMeta, year));
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
108 // facets.add(CollisionGaugeWProcessor.createFacet(callMeta, seriesName)); //REMARK gauge_w is the cm above gauge datum,
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
109 // therefore only useful with transformation to NHN
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
110 addFacets(STATIC_STATE_NAME, facets);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
111 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
112
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
113 @Override
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
114 protected void initStaticState() {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
115
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
116 log.debug("initStaticState " + getName() + " " + identifier());
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
117
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
118 final StaticState state = new StaticState(STATIC_STATE_NAME);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
119 final DefaultOutput output = new DefaultOutput("general", "general", "image/png", "chart");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
120
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
121 final List<Facet> facets = getFacets(STATIC_STATE_NAME);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
122 output.addFacets(facets);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
123 state.addOutput(output);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
124
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
125 setStaticState(state);
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
126 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
127
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
128 @Override
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
129 protected void initialize(final Artifact artifact, final Object context, final CallMeta meta) {
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
130 // do not clone facets, etc. from master artifact
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
131
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
132 log.debug("initialize");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
133 importData((D4EArtifact) artifact, "river");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
134 importData((D4EArtifact) artifact, "ld_from");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
135 importData((D4EArtifact) artifact, "ld_to");
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
136
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
137 log.debug("ld_from " + getDataAsString("ld_from"));
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
138 log.debug("ld_to " + getDataAsString("ld_to"));
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
139 }
820ae41c81b6 Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff changeset
140 }

http://dive4elements.wald.intevation.org