Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/CollisionArtifact.java @ 9341:c9a4eb3afa4a
Facet filter added for S-Info collision and flood duration, db loaded artifacts renamed to predefined..
author | mschaefer |
---|---|
date | Mon, 30 Jul 2018 13:40:33 +0200 |
parents | 0fc9c82e744e |
children |
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.states.StaticState; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
28 import org.w3c.dom.Document; |
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 * 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
|
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 CollisionArtifact extends AbstractStaticStateArtifact implements FacetTypes { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
37 |
9157
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9125
diff
changeset
|
38 private static final long serialVersionUID = 1L; |
f9bb5d0a6ff3
Added the S-Info collision calculation and chart output
mschaefer
parents:
9125
diff
changeset
|
39 |
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
40 /** The log for this class. */ |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
41 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
|
42 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
43 /** Artifact name. */ |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
44 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
|
45 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
46 static { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
47 // TODO: Move to configuration. |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
48 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
|
49 } |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
50 |
9341
c9a4eb3afa4a
Facet filter added for S-Info collision and flood duration, db loaded artifacts renamed to predefined..
mschaefer
parents:
9215
diff
changeset
|
51 public static final String STATIC_STATE_NAME = "state.predefined_collision.static"; |
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
52 |
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 * Trivial Constructor. |
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 public CollisionArtifact() { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
57 log.debug("new CollisionArtifact"); |
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 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
60 @Override |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
61 public String getName() { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
62 return NAME; |
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 |
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 * 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
|
67 */ |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
68 @Override |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
69 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
|
70 final List<Class> loadFacets) { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
71 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
72 log.debug("CollisionArtifact.setup"); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
73 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
74 if (log.isDebugEnabled()) { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
75 log.debug(XMLUtils.toString(data)); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
76 } |
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 final String code = getDatacageIDValue(data); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
79 final String[] parts = code.split("-"); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
80 if (parts.length >= 2) |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
81 addStringData("collision_id", parts[1]); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
82 if (parts.length >= 3) |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
83 addStringData("year", parts[2]); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
84 else |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
85 addStringData("year", "jahr?"); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
86 String seriesName; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
87 if (parts.length >= 4) |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
88 seriesName = parts[3]; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
89 else |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
90 seriesName = "name?"; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
91 |
9215 | 92 // if different facet wanted, e.g. for each year use different facetIndex |
93 // if multiple Result treated, get each Result from data | |
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
94 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
|
95 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
96 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
|
97 } |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
98 |
9215 | 99 private void createFacets(final CallMeta callMeta, final String code, final String seriesName, final String yearForName) { |
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
100 if (code == null) |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
101 return; |
9215 | 102 |
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
103 final String[] parts = code.split("-"); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
104 if (parts.length < 2) { |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
105 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
|
106 return; |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
107 } |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9157
diff
changeset
|
108 final ArrayList<Facet> facets = new ArrayList<>(1); |
9215 | 109 facets.add(CollisionCountProcessor.createFacet(0, callMeta, yearForName)); |
9125
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
110 // 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
|
111 // 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
|
112 addFacets(STATIC_STATE_NAME, facets); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
113 } |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
114 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
115 @Override |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
116 protected void initStaticState() { |
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 log.debug("initStaticState " + getName() + " " + identifier()); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
119 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
120 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
|
121 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
|
122 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
123 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
|
124 output.addFacets(facets); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
125 state.addOutput(output); |
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 setStaticState(state); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
128 } |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
129 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
130 @Override |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
131 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
|
132 // 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
|
133 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
134 log.debug("initialize"); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
135 importData((D4EArtifact) artifact, "river"); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
136 importData((D4EArtifact) artifact, "ld_from"); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
137 importData((D4EArtifact) artifact, "ld_to"); |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
138 |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
139 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
|
140 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
|
141 } |
820ae41c81b6
Fixed adding missing files for the river bed collision counts selectable in the datacage
mschaefer
parents:
diff
changeset
|
142 } |