comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.artifacts.model.fixings;
2
3 import org.dive4elements.artifacts.Artifact;
4 import org.dive4elements.artifacts.CallContext;
5
6 import org.dive4elements.river.artifacts.FLYSArtifact;
7
8 import org.dive4elements.river.artifacts.access.FixAnalysisAccess;
9
10 import org.dive4elements.river.artifacts.math.fitting.Function;
11 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory;
12
13 import org.dive4elements.river.artifacts.model.CalculationResult;
14 import org.dive4elements.river.artifacts.model.FacetTypes;
15 import org.dive4elements.river.artifacts.model.Parameters;
16
17 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
18
19 import org.apache.log4j.Logger;
20
21 /**
22 * Facet to show the W|Q values.
23 *
24 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
25 */
26 public class FixWQCurveFacet
27 extends FixingsFacet
28 implements FacetTypes {
29
30 /** House logger. */
31 private static Logger logger = Logger.getLogger(FixWQCurveFacet.class);
32
33
34 /** Trivial Constructor. */
35 public FixWQCurveFacet() {
36 }
37
38
39 /**
40 * @param description Description of the facet.
41 */
42 public FixWQCurveFacet(String description) {
43 super(0, FIX_WQ_CURVE, description, ComputeType.ADVANCE, null, null);
44 }
45
46 public FixWQCurveFacet(int index, String description) {
47 super(index, FIX_WQ_CURVE, description, ComputeType.ADVANCE, null, null);
48 }
49
50
51 /**
52 * Returns the data this facet provides at given km, a function.
53 *
54 * @param artifact the owner artifact.
55 * @param context the CallContext.
56 *
57 * @return the data.
58 */
59 @Override
60 public Object getData(Artifact artifact, CallContext context) {
61 logger.debug("getData");
62 if (artifact instanceof FLYSArtifact) {
63 FLYSArtifact flys = (FLYSArtifact)artifact;
64 FixAnalysisAccess access = new FixAnalysisAccess(flys, context);
65
66 CalculationResult res =
67 (CalculationResult) flys.compute(context,
68 ComputeType.ADVANCE,
69 false);
70
71 FixResult result = (FixResult) res.getData();
72 double currentKm = getCurrentKm(context);
73
74 logger.debug("getData: km = " + currentKm);
75
76 String function = access.getFunction();
77 Function ff = FunctionFactory.getInstance().getFunction(function);
78
79 if (ff == null) {
80 logger.warn("getData: ff == null");
81 return null;
82 }
83
84 Parameters params = result.getParameters();
85 String[] paramNames = ff.getParameterNames();
86
87 double [] coeffs = params.interpolate("km", currentKm, paramNames);
88
89 if (coeffs == null) {
90 logger.warn("getData: coeffs == null");
91 return null;
92 }
93
94 org.dive4elements.river.artifacts.math.Function mf =
95 ff.instantiate(coeffs);
96
97 double maxQ = FixFacetUtils.getMaxQ(params, currentKm);
98 logger.debug("getData: maxQ = " + maxQ);
99
100 FixFunction fix = new FixFunction(
101 ff.getName(),
102 ff.getDescription(),
103 mf,
104 maxQ);
105
106 return fix;
107 }
108 else {
109 logger.debug("Not an instance of FLYSArtifact / FixationArtifact.");
110 return null;
111 }
112 }
113
114 /**
115 * Create a deep copy of this Facet.
116 * @return a deep copy.
117 */
118 @Override
119 public FixWQCurveFacet deepCopy() {
120 FixWQCurveFacet copy = new FixWQCurveFacet();
121 copy.set(this);
122 return copy;
123 }
124 }
125 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org