Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/StaticWQKmsArtifact.java @ 9425:3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
Also allows to have acces to the potentially already computed artifact result via its normal computation cache.
author | gernotbelger |
---|---|
date | Fri, 17 Aug 2018 15:31:02 +0200 |
parents | 23264d1a528f |
children |
comparison
equal
deleted
inserted
replaced
9424:da19f1f58d72 | 9425:3f49835a00c3 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts; | 9 package org.dive4elements.river.artifacts; |
10 | 10 |
11 import java.awt.geom.Point2D; | 11 import java.io.Serializable; |
12 | |
13 import java.util.ArrayList; | 12 import java.util.ArrayList; |
14 import java.util.List; | 13 import java.util.List; |
15 | 14 |
16 import org.apache.log4j.Logger; | 15 import org.apache.log4j.Logger; |
17 | |
18 import org.w3c.dom.Document; | |
19 | |
20 import org.dive4elements.artifactdatabase.state.Facet; | 16 import org.dive4elements.artifactdatabase.state.Facet; |
21 import org.dive4elements.artifactdatabase.state.FacetActivity; | 17 import org.dive4elements.artifactdatabase.state.FacetActivity; |
22 | |
23 import org.dive4elements.artifacts.Artifact; | 18 import org.dive4elements.artifacts.Artifact; |
24 import org.dive4elements.artifacts.ArtifactFactory; | 19 import org.dive4elements.artifacts.ArtifactFactory; |
25 import org.dive4elements.artifacts.CallContext; | 20 import org.dive4elements.artifacts.CallContext; |
26 import org.dive4elements.artifacts.CallMeta; | 21 import org.dive4elements.artifacts.CallMeta; |
27 | |
28 import org.dive4elements.artifacts.common.utils.XMLUtils; | 22 import org.dive4elements.artifacts.common.utils.XMLUtils; |
29 | |
30 import org.dive4elements.river.artifacts.geom.Lines; | |
31 | |
32 import org.dive4elements.river.artifacts.model.FacetTypes; | 23 import org.dive4elements.river.artifacts.model.FacetTypes; |
33 import org.dive4elements.river.model.FastCrossSectionLine; | |
34 import org.dive4elements.river.artifacts.model.WKms; | 24 import org.dive4elements.river.artifacts.model.WKms; |
25 import org.dive4elements.river.artifacts.model.WKmsFactory; | |
35 import org.dive4elements.river.artifacts.model.WQKms; | 26 import org.dive4elements.river.artifacts.model.WQKms; |
36 import org.dive4elements.river.artifacts.model.WKmsFactory; | |
37 import org.dive4elements.river.artifacts.model.WQKmsFactory; | 27 import org.dive4elements.river.artifacts.model.WQKmsFactory; |
38 | |
39 import org.dive4elements.river.artifacts.states.DefaultState; | 28 import org.dive4elements.river.artifacts.states.DefaultState; |
40 | 29 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; |
30 import org.w3c.dom.Document; | |
41 | 31 |
42 /** | 32 /** |
43 * Artifact to access additional "waterlevel/discharge"-type of data, like | 33 * Artifact to access additional "waterlevel/discharge"-type of data, like |
44 * fixation measurements. | 34 * fixation measurements. |
45 * | 35 * |
46 * This artifact neglects (Static)D4EArtifacts capabilities of interaction | 36 * This artifact neglects (Static)D4EArtifacts capabilities of interaction |
47 * with the StateEngine by overriding the getState*-methods. | 37 * with the StateEngine by overriding the getState*-methods. |
48 */ | 38 */ |
49 public class StaticWQKmsArtifact | 39 public class StaticWQKmsArtifact extends StaticD4EArtifact implements FacetTypes, WaterLineArtifact { |
50 extends StaticD4EArtifact | |
51 implements FacetTypes, WaterLineArtifact | |
52 { | |
53 /** The log for this class. */ | 40 /** The log for this class. */ |
54 private static Logger log = | 41 private static Logger log = Logger.getLogger(StaticWQKmsArtifact.class); |
55 Logger.getLogger(StaticWQKmsArtifact.class); | 42 |
56 | 43 public static final String STATIC_STATE_NAME = "state.additional_wqkms.static"; |
57 public static final String STATIC_STATE_NAME = | |
58 "state.additional_wqkms.static"; | |
59 | 44 |
60 private static final String NAME = "staticwqkms"; | 45 private static final String NAME = "staticwqkms"; |
61 | 46 |
62 static { | 47 static { |
63 // TODO: Move to configuration. | 48 // TODO: Move to configuration. |
64 FacetActivity.Registry.getInstance().register( | 49 FacetActivity.Registry.getInstance().register(NAME, new FacetActivity() { |
65 NAME, | 50 @Override |
66 new FacetActivity() { | 51 public Boolean isInitialActive(final Artifact artifact, final Facet facet, final String outputName) { |
67 @Override | 52 final String fname = facet.getName(); |
68 public Boolean isInitialActive( | 53 return (fname.equals(STATIC_WQKMS) || fname.equals(STATIC_WQKMS_W)); |
69 Artifact artifact, | 54 } |
70 Facet facet, | 55 }); |
71 String outputName | |
72 ) { | |
73 String fname = facet.getName(); | |
74 return (fname.equals(STATIC_WQKMS) | |
75 || fname.equals(STATIC_WQKMS_W)); | |
76 }}); | |
77 } | 56 } |
78 | 57 |
79 /** | 58 /** |
80 * Trivial Constructor. | 59 * Trivial Constructor. |
81 */ | 60 */ |
82 public StaticWQKmsArtifact() { | 61 public StaticWQKmsArtifact() { |
83 log.debug("StaticWQKmsArtifact.StaticWQKmsArtifact"); | 62 log.debug("StaticWQKmsArtifact.StaticWQKmsArtifact"); |
84 } | 63 } |
85 | |
86 | 64 |
87 /** | 65 /** |
88 * Gets called from factory, to set things up. | 66 * Gets called from factory, to set things up. |
89 * | 67 * |
90 * If the id's string starts with official- it will be treated as | 68 * If the id's string starts with official- it will be treated as |
91 * an Artifact containing official data for the according special | 69 * an Artifact containing official data for the according special |
92 * case handling. | 70 * case handling. |
93 */ | 71 */ |
94 @Override | 72 @Override |
95 public void setup( | 73 public void setup(final String identifier, final ArtifactFactory factory, final Object context, final CallMeta callMeta, final Document data, |
96 String identifier, | 74 final List<Class> loadFacets) { |
97 ArtifactFactory factory, | |
98 Object context, | |
99 CallMeta callMeta, | |
100 Document data, | |
101 List<Class> loadFacets) | |
102 { | |
103 log.debug("StaticWQKmsArtifact.setup"); | 75 log.debug("StaticWQKmsArtifact.setup"); |
104 | 76 |
105 // Store the 'ids' (from datacage). | 77 // Store the 'ids' (from datacage). |
106 if (log.isDebugEnabled()) { | 78 if (log.isDebugEnabled()) { |
107 log.debug("StaticWQKmsArtifact.setup" + XMLUtils.toString(data)); | 79 log.debug("StaticWQKmsArtifact.setup" + XMLUtils.toString(data)); |
108 } | 80 } |
109 | 81 |
110 String code = getDatacageIDValue(data); | 82 final String code = getDatacageIDValue(data); |
111 addStringData("ids", code); | 83 addStringData("ids", code); |
112 if (code != null) { | 84 if (code != null) { |
113 String [] parts = code.split("-"); | 85 final String[] parts = code.split("-"); |
114 | 86 |
115 if (parts.length >= 1) { | 87 if (parts.length >= 1) { |
116 boolean official = parts[0].toLowerCase() | 88 final boolean official = parts[0].toLowerCase().startsWith("official"); |
117 .startsWith("official"); | |
118 addStringData("official", official ? "1" : "0"); | 89 addStringData("official", official ? "1" : "0"); |
119 } | 90 } |
120 | 91 |
121 if (parts.length >= 4) { | 92 if (parts.length >= 4) { |
122 int col = Integer.parseInt(parts[2]); | 93 final int col = Integer.parseInt(parts[2]); |
123 int wst = Integer.parseInt(parts[3]); | 94 final int wst = Integer.parseInt(parts[3]); |
124 | 95 |
125 addStringData("col_pos", parts[2]); | 96 addStringData("col_pos", parts[2]); |
126 addStringData("wst_id", parts[3]); | 97 addStringData("wst_id", parts[3]); |
127 } | 98 } |
128 } | 99 } |
129 | 100 |
130 // Do this AFTER we have set the col_pos etc. | 101 // Do this AFTER we have set the col_pos etc. |
131 super.setup(identifier, factory, context, callMeta, data, loadFacets); | 102 super.setup(identifier, factory, context, callMeta, data, loadFacets); |
132 } | 103 } |
133 | 104 |
134 | |
135 /** | 105 /** |
136 * Called via setup. | 106 * Called via setup. |
137 * | 107 * |
138 * @param artifact The master-artifact. | 108 * @param artifact |
139 */ | 109 * The master-artifact. |
140 @Override | 110 */ |
141 protected void initialize( | 111 @Override |
142 Artifact artifact, | 112 protected void initialize(final Artifact artifact, final Object context, final CallMeta meta) { |
143 Object context, | |
144 CallMeta meta) | |
145 { | |
146 log.debug("StaticWQKmsArtifact.initialize"); | 113 log.debug("StaticWQKmsArtifact.initialize"); |
147 D4EArtifact flys = (D4EArtifact) artifact; | 114 final D4EArtifact flys = (D4EArtifact) artifact; |
148 // TODO: The river is of no interest, so far., also use importData | 115 // TODO: The river is of no interest, so far., also use importData |
149 importData(flys, "river"); | 116 importData(flys, "river"); |
150 | 117 |
151 List<Facet> fs = new ArrayList<Facet>(); | 118 final List<Facet> fs = new ArrayList<>(); |
152 | 119 |
153 DefaultState state = (DefaultState) getCurrentState(context); | 120 final DefaultState state = (DefaultState) getCurrentState(context); |
154 state.computeInit(this, hash(), context, meta, fs); | 121 state.computeInit(this, hash(), context, meta, fs); |
155 if (!fs.isEmpty()) { | 122 if (!fs.isEmpty()) { |
156 log.debug("Facets to add in StaticWQKmsArtifact.initialize ."); | 123 log.debug("Facets to add in StaticWQKmsArtifact.initialize ."); |
157 addFacets(getCurrentStateId(), fs); | 124 addFacets(getCurrentStateId(), fs); |
158 } | 125 } else { |
159 else { | 126 log.debug("No facets to add in StaticWQKmsArtifact.initialize (" + state.getID() + ")."); |
160 log.debug("No facets to add in StaticWQKmsArtifact.initialize (" | 127 } |
161 + state.getID() + ")."); | 128 } |
162 } | |
163 } | |
164 | |
165 | 129 |
166 /** | 130 /** |
167 * Get WQKms from factory. | 131 * Get WQKms from factory. |
132 * | |
168 * @return WQKms according to parameterization (can be null); | 133 * @return WQKms according to parameterization (can be null); |
169 */ | 134 */ |
170 public WQKms getWQKms() { | 135 public WQKms getWQKms() { |
171 log.debug("StaticWQKmsArtifact.getWQKms"); | 136 log.debug("StaticWQKmsArtifact.getWQKms"); |
172 | 137 |
173 int col = Integer.parseInt(getDataAsString("col_pos")); | 138 final int col = Integer.parseInt(getDataAsString("col_pos")); |
174 int wst = Integer.parseInt(getDataAsString("wst_id")); | 139 final int wst = Integer.parseInt(getDataAsString("wst_id")); |
175 | 140 |
176 /** TODO do not run twice against db to do this. */ | 141 /** TODO do not run twice against db to do this. */ |
177 String wkmsName = WKmsFactory.getWKmsName(col, wst); | 142 final String wkmsName = WKmsFactory.getWKmsName(col, wst); |
178 | 143 |
179 WQKms res = WQKmsFactory.getWQKms(col, wst); | 144 final WQKms res = WQKmsFactory.getWQKms(col, wst); |
180 res.setName(wkmsName); | 145 res.setName(wkmsName); |
181 return res; | 146 return res; |
182 } | 147 } |
183 | 148 |
184 /** | 149 /** |
185 * Get WQKms from factory. | 150 * Get WQKms from factory. |
151 * | |
186 * @return WQKms according to parameterization (can be null); | 152 * @return WQKms according to parameterization (can be null); |
187 */ | 153 */ |
188 public WQKms getWQKms(final double from, final double to) { | 154 public WQKms getWQKms(final double from, final double to) { |
189 log.debug("StaticWQKmsArtifact.getWQKms"); | 155 log.debug("StaticWQKmsArtifact.getWQKms"); |
190 | 156 |
191 int col = Integer.parseInt(getDataAsString("col_pos")); | 157 final int col = Integer.parseInt(getDataAsString("col_pos")); |
192 int wst = Integer.parseInt(getDataAsString("wst_id")); | 158 final int wst = Integer.parseInt(getDataAsString("wst_id")); |
193 | 159 |
194 /** TODO do not run twice against db to do this. */ | 160 /** TODO do not run twice against db to do this. */ |
195 String wkmsName = WKmsFactory.getWKmsName(col, wst); | 161 final String wkmsName = WKmsFactory.getWKmsName(col, wst); |
196 | 162 |
197 WQKms res = WQKmsFactory.getWQKms(col, wst, from, to); | 163 final WQKms res = WQKmsFactory.getWQKms(col, wst, from, to); |
198 res.setName(wkmsName); | 164 res.setName(wkmsName); |
199 return res; | 165 return res; |
200 } | 166 } |
201 | 167 |
202 /** Return specific name. */ | 168 /** Return specific name. */ |
203 @Override | 169 @Override |
204 public String getName() { | 170 public String getName() { |
205 return NAME; | 171 return NAME; |
206 } | 172 } |
207 | 173 |
208 | |
209 /** | 174 /** |
210 * Get points of line describing the surface of water at cross section. | 175 * Get points of line describing the surface of water at cross section. |
211 * | 176 * |
212 * @param idx Index of facet and in wkms array. | 177 * @param idx |
213 * @param csl FastCrossSectionLine to compute water surface agains. | 178 * Index of facet and in wkms array. |
214 * @param next The km of the next crosssectionline. | 179 * @param csl |
215 * @param prev The km of the previous crosssectionline. | 180 * FastCrossSectionLine to compute water surface agains. |
216 * @param context Ignored in this implementation. | 181 * @param next |
182 * The km of the next crosssectionline. | |
183 * @param prev | |
184 * The km of the previous crosssectionline. | |
185 * @param context | |
186 * Ignored in this implementation. | |
217 * | 187 * |
218 * @return an array holding coordinates of points of surface of water ( | 188 * @return an array holding coordinates of points of surface of water ( |
219 * in the form {{x1, x2}, {y1, y2}} ). | 189 * in the form {{x1, x2}, {y1, y2}} ). |
220 */ | 190 */ |
221 @Override | 191 @Override |
222 public Lines.LineData getWaterLines(int idx, FastCrossSectionLine csl, | 192 public double getWaterLevel(final ComputeType type, final String hash, final String stateId, final double currentKm, final Serializable waterLineIndex, |
223 double next, double prev, CallContext context | 193 final double nextKm, final double prevKm, final CallContext context) { |
224 ) { | 194 |
225 log.debug("getWaterLines(" + idx + ")/" + identifier()); | 195 final WKms wkms = getWQKms(); |
226 | |
227 List<Point2D> points = csl.getPoints(); | |
228 | |
229 WKms wkms = getWQKms(); | |
230 | |
231 double km = csl.getKm(); | |
232 | 196 |
233 // Find W at km. | 197 // Find W at km. |
234 double wAtKm; | 198 final double wAtKm = StaticWKmsArtifact.getWAtKm(wkms, currentKm); |
235 | 199 |
236 // If heightmarks, only deliver if data snaps. | 200 if (Double.isNaN(wAtKm)) { |
237 /* | 201 log.warn("Waterlevel at km " + currentKm + " unknown."); |
238 if (getDataAsString(DATA_HEIGHT_TYPE) != null && | 202 return Double.NaN; |
239 getDataAsString(DATA_HEIGHT_TYPE).equals("true")) { | 203 } |
240 wAtKm = getWAtCloseKm(wkms, km, next, prev); | 204 |
241 } | 205 return wAtKm; |
242 else { | |
243 */ | |
244 wAtKm = StaticWKmsArtifact.getWAtKm(wkms, km); | |
245 //} | |
246 | |
247 if (wAtKm == -1 || Double.isNaN(wAtKm)) { | |
248 log.warn("Waterlevel at km " + km + " unknown."); | |
249 return new Lines.LineData(new double[][] {{}}, 0d, 0d); | |
250 } | |
251 | |
252 return Lines.createWaterLines(points, wAtKm); | |
253 } | 206 } |
254 // TODO implement deepCopy. | 207 // TODO implement deepCopy. |
255 } | 208 } |
256 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |