comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 704:eab5e5089d77

Merged revisions 2127-2133,2136-2137,2140,2143-2144,2146,2150-2151,2153-2154 via svnmerge from svn+ssh://teichmann@thoe/home/projects/Geospatial/bsh-generischer-viewer/Material/SVN/flys-artifacts/branches/facets-slt ........ r2127 | ingo | 2011-06-16 09:50:56 +0200 (Do, 16 Jun 2011) | 1 line Added a compute() method to WINFOArtifact which acts as a dispatcher for different computations. It triggers a calculation based on ComputeCallbacks that are generated by the current states. ........ r2128 | ingo | 2011-06-16 10:25:06 +0200 (Do, 16 Jun 2011) | 1 line Moved Waterlevel state into the correct package. ........ r2129 | ingo | 2011-06-16 10:43:58 +0200 (Do, 16 Jun 2011) | 1 line Added two more compute() methods to ComputeCallback to distinguish between different phases of the artifact. ........ r2130 | ingo | 2011-06-16 10:57:05 +0200 (Do, 16 Jun 2011) | 1 line Use enums to dispatch computeFeed() and computeAdvance(). ........ r2131 | ingo | 2011-06-16 11:04:59 +0200 (Do, 16 Jun 2011) | 1 line Store facets for each state. ........ r2132 | ingo | 2011-06-16 12:05:44 +0200 (Do, 16 Jun 2011) | 1 line Generated facets for each output aspect. ........ r2133 | ingo | 2011-06-16 15:24:00 +0200 (Do, 16 Jun 2011) | 1 line Write computed facets into artifacts describe document. ........ r2136 | ingo | 2011-06-16 16:10:49 +0200 (Do, 16 Jun 2011) | 1 line Add index and description of facets to collections describe document. ........ r2137 | ingo | 2011-06-16 16:31:41 +0200 (Do, 16 Jun 2011) | 1 line OutGenerators doOut() takes a facet object now instead of just its name. ........ r2140 | ingo | 2011-06-17 11:19:43 +0200 (Fr, 17 Jun 2011) | 1 line OutGenerators use now facets to fetch necessary data. ........ r2143 | teichmann | 2011-06-17 12:40:54 +0200 (Fr, 17 Jun 2011) | 1 line Removed ComputeCallback because this was thought too complicated. Fixed issue with facets not be re-generated if same state is entered again. ........ r2144 | teichmann | 2011-06-17 13:08:31 +0200 (Fr, 17 Jun 2011) | 1 line make getGauges() more robust ........ r2146 | teichmann | 2011-06-17 13:23:57 +0200 (Fr, 17 Jun 2011) | 1 line mico opt: inter cmps are faster than str cmps. ........ r2150 | teichmann | 2011-06-17 15:10:20 +0200 (Fr, 17 Jun 2011) | 1 line call computeAdvance() if we want to advance. ........ r2151 | teichmann | 2011-06-17 15:45:50 +0200 (Fr, 17 Jun 2011) | 1 line Base WST/CSV exports on facets. TODO: generate the facets. ........ r2153 | teichmann | 2011-06-17 16:03:29 +0200 (Fr, 17 Jun 2011) | 1 line Add facet to access raw computed data. ........ r2154 | teichmann | 2011-06-17 16:37:09 +0200 (Fr, 17 Jun 2011) | 1 line Generate data facets for the computed states. ........ flys-artifacts/trunk@2156 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 17 Jun 2011 16:17:03 +0000
parents 19a3185822a4 708b270dfd30
children 853dceead0f4
comparison
equal deleted inserted replaced
685:d45c3ddaed1b 704:eab5e5089d77
1 package de.intevation.flys.artifacts; 1 package de.intevation.flys.artifacts;
2 2
3 import java.util.ArrayList;
4 import java.util.HashSet;
3 import java.util.List; 5 import java.util.List;
6 import java.util.Map;
7 import java.util.Set;
4 8
5 import org.w3c.dom.Document; 9 import org.w3c.dom.Document;
6 import org.w3c.dom.Element; 10 import org.w3c.dom.Element;
7 import org.w3c.dom.Node; 11 import org.w3c.dom.Node;
8 12
10 14
11 import de.intevation.artifacts.ArtifactNamespaceContext; 15 import de.intevation.artifacts.ArtifactNamespaceContext;
12 import de.intevation.artifacts.CallContext; 16 import de.intevation.artifacts.CallContext;
13 17
14 import de.intevation.artifactdatabase.ProtocolUtils; 18 import de.intevation.artifactdatabase.ProtocolUtils;
19 import de.intevation.artifactdatabase.state.DefaultOutput;
20 import de.intevation.artifactdatabase.state.Facet;
15 import de.intevation.artifactdatabase.state.Output; 21 import de.intevation.artifactdatabase.state.Output;
16 import de.intevation.artifactdatabase.state.State; 22 import de.intevation.artifactdatabase.state.State;
17 import de.intevation.artifactdatabase.state.StateEngine; 23 import de.intevation.artifactdatabase.state.StateEngine;
18 import de.intevation.artifactdatabase.transition.TransitionEngine; 24 import de.intevation.artifactdatabase.transition.TransitionEngine;
19 25
23 import de.intevation.flys.model.River; 29 import de.intevation.flys.model.River;
24 30
25 import de.intevation.flys.artifacts.states.DefaultState; 31 import de.intevation.flys.artifacts.states.DefaultState;
26 import de.intevation.flys.artifacts.context.FLYSContext; 32 import de.intevation.flys.artifacts.context.FLYSContext;
27 33
34 import de.intevation.flys.artifacts.model.DischargeTables;
28 import de.intevation.flys.artifacts.model.MainValuesFactory; 35 import de.intevation.flys.artifacts.model.MainValuesFactory;
29 import de.intevation.flys.artifacts.model.WQDay; 36 import de.intevation.flys.artifacts.model.WQDay;
30 import de.intevation.flys.artifacts.model.WQKms; 37 import de.intevation.flys.artifacts.model.WQKms;
31 import de.intevation.flys.artifacts.model.WstValueTable; 38 import de.intevation.flys.artifacts.model.WstValueTable;
32 import de.intevation.flys.artifacts.model.WstValueTableFactory; 39 import de.intevation.flys.artifacts.model.WstValueTableFactory;
175 StateEngine engine = (StateEngine) flysContext.get( 182 StateEngine engine = (StateEngine) flysContext.get(
176 FLYSContext.STATE_ENGINE_KEY); 183 FLYSContext.STATE_ENGINE_KEY);
177 184
178 for (String stateId: stateIds) { 185 for (String stateId: stateIds) {
179 logger.debug("Append output modes for state: " + stateId); 186 logger.debug("Append output modes for state: " + stateId);
180 State state = engine.getState(stateId); 187 DefaultState state = (DefaultState) engine.getState(stateId);
181 188
182 List<Output> list = state.getOutputs(); 189 List<Output> list = state.getOutputs();
183 if (list == null || list.size() == 0) { 190 if (list == null || list.size() == 0) {
184 logger.debug("-> No output modes for this state."); 191 logger.debug("-> No output modes for this state.");
185 continue; 192 continue;
186 } 193 }
187 194
188 ProtocolUtils.appendOutputModes(creator, outs, list); 195 List<Facet> fs = facets.get(stateId);
196 if (fs == null || fs.size() == 0) {
197 logger.debug("No facets found.");
198 continue;
199 }
200
201 logger.debug("Found " + fs.size() + " facets in previous states.");
202
203 List<Output> generated = generateOutputs(list, fs);
204
205 ProtocolUtils.appendOutputModes(creator, outs, generated);
189 } 206 }
190 207
191 try { 208 try {
192 DefaultState cur = (DefaultState) getCurrentState(context); 209 DefaultState cur = (DefaultState) getCurrentState(context);
193 if (cur.validate(this, context)) { 210 if (cur.validate(this, context)) {
194 List<Output> list = cur.getOutputs(); 211 List<Output> list = cur.getOutputs();
195 if (list != null && list.size() > 0) { 212 if (list != null && list.size() > 0) {
196 logger.debug( 213 logger.debug(
197 "Append output modes for state: " + cur.getID()); 214 "Append output modes for state: " + cur.getID());
198 215
199 ProtocolUtils.appendOutputModes(creator, outs, list); 216 List<Facet> fs = facets.get(cur.getID());
217 if (fs != null && fs.size() > 0) {
218 List<Output> generated = generateOutputs(list, fs);
219
220 logger.debug("Found " + fs.size() + " current facets.");
221
222 ProtocolUtils.appendOutputModes(
223 creator, outs, generated);
224 }
225 else {
226 logger.debug("No facets found for the current state.");
227 }
228
200 } 229 }
201 } 230 }
202 } 231 }
203 catch (IllegalArgumentException iae) { 232 catch (IllegalArgumentException iae) {
204 // state is not valid, so we do not append its outputs. 233 // state is not valid, so we do not append its outputs.
205 } 234 }
235 }
236
237
238 protected List<Output> generateOutputs(List<Output> list, List<Facet> fs) {
239 List<Output> generated = new ArrayList<Output>();
240
241 for (Output out: list) {
242 Output o = new DefaultOutput(
243 out.getName(),
244 out.getDescription(),
245 out.getMimeType());
246
247 Set<String> outtype = new HashSet<String>();
248
249 for (Facet f: out.getFacets()) {
250 outtype.add(f.getName());
251 }
252
253 for (Facet f: fs) {
254 String type = f.getName();
255
256 if(outtype.contains(type)) {
257 o.addFacet(f);
258 }
259 }
260
261 generated.add(o);
262 }
263
264 return generated;
206 } 265 }
207 266
208 267
209 /** 268 /**
210 * This method appends the static data - that has already been inserted by 269 * This method appends the static data - that has already been inserted by
378 return calculation.calculate(wst); 437 return calculation.calculate(wst);
379 } 438 }
380 439
381 440
382 /** 441 /**
442 * Returns the data that is used to create discharge curves.
443 *
444 * @return a map where the key is the name of the gauge and a double[][]
445 * which are the values.
446 */
447 public Map<String, double[][]> getDischargeCurveData() {
448 River river = getRiver();
449 List<Gauge> gauges = getGauges();
450
451 if (gauges == null) {
452 logger.warn("No gauges found for the current kilometer range.");
453 return null;
454 }
455
456 int num = gauges.size();
457
458 logger.debug("Found " + num + " gauges.");
459
460 String[] gaugeNames = new String[num];
461
462 for (int i = 0; i < num; i++) {
463 gaugeNames[i] = gauges.get(i).getName();
464 }
465
466 DischargeTables dt = new DischargeTables(river.getName(), gaugeNames);
467
468 return dt.getValues(100d);
469 }
470
471
472 /**
383 * Returns the data that is computed by a discharge curve computation. 473 * Returns the data that is computed by a discharge curve computation.
384 * 474 *
385 * @return the data computed by a discharge curve computation. 475 * @return the data computed by a discharge curve computation.
386 */ 476 */
387 public WQKms getComputedDischargeCurveData() 477 public WQKms getComputedDischargeCurveData()

http://dive4elements.wald.intevation.org