Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java @ 3035:b388d888330d
Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
flys-artifacts/trunk@4604 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 06 Jun 2012 11:35:32 +0000 |
parents | 77b5f5a26700 |
children | 1fbf8462f808 |
comparison
equal
deleted
inserted
replaced
3034:842502b3913a | 3035:b388d888330d |
---|---|
3 import org.apache.log4j.Logger; | 3 import org.apache.log4j.Logger; |
4 | 4 |
5 import de.intevation.artifacts.Artifact; | 5 import de.intevation.artifacts.Artifact; |
6 import de.intevation.artifacts.CallContext; | 6 import de.intevation.artifacts.CallContext; |
7 | 7 |
8 import de.intevation.flys.utils.KMIndex; | |
9 | |
8 import de.intevation.flys.artifacts.FLYSArtifact; | 10 import de.intevation.flys.artifacts.FLYSArtifact; |
11 import de.intevation.flys.artifacts.FixationArtifactAccess; | |
12 | |
9 import de.intevation.flys.artifacts.model.FacetTypes; | 13 import de.intevation.flys.artifacts.model.FacetTypes; |
10 import de.intevation.flys.artifacts.model.DataFacet; | 14 import de.intevation.flys.artifacts.model.DataFacet; |
15 import de.intevation.flys.artifacts.model.CalculationResult; | |
16 import de.intevation.flys.artifacts.model.Parameters; | |
17 | |
18 import de.intevation.flys.artifacts.math.fitting.FunctionFactory; | |
19 import de.intevation.flys.artifacts.math.fitting.Function; | |
11 | 20 |
12 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | 21 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; |
13 | 22 |
14 | 23 |
15 /** | 24 /** |
46 * @return the data. | 55 * @return the data. |
47 */ | 56 */ |
48 @Override | 57 @Override |
49 public Object getData(Artifact artifact, CallContext context) { | 58 public Object getData(Artifact artifact, CallContext context) { |
50 logger.debug("FixWQCurveFacet.getData"); | 59 logger.debug("FixWQCurveFacet.getData"); |
51 return null; | 60 if (artifact instanceof FLYSArtifact) { |
61 FLYSArtifact flys = (FLYSArtifact)artifact; | |
62 FixationArtifactAccess access = new FixationArtifactAccess(flys); | |
63 | |
64 CalculationResult res = | |
65 (CalculationResult) flys.compute(context, | |
66 ComputeType.ADVANCE, | |
67 false); | |
68 | |
69 FixResult result = (FixResult) res.getData(); | |
70 | |
71 double km = access.getCurrentKm(); | |
72 | |
73 String function = access.getFunction(); | |
74 Function ff = FunctionFactory.getInstance().getFunction(function); | |
75 | |
76 Parameters params = result.getParameters(); | |
77 int row = params.binarySearch("km", km, Math.pow(10, -4)); | |
78 String[] paramNames = ff.getParameterNames(); | |
79 int[] paramInd = params.columnIndices(paramNames); | |
80 double[] coeffs = new double[paramNames.length]; | |
81 params.get(row, paramInd, coeffs); | |
82 | |
83 de.intevation.flys.artifacts.math.Function mf = | |
84 ff.instantiate(coeffs); | |
85 | |
86 double maxQ = getMaxQ(result, km); | |
87 | |
88 FixFunction fix = new FixFunction( | |
89 ff.getName(), | |
90 ff.getDescription(), | |
91 mf, | |
92 maxQ); | |
93 | |
94 return fix; | |
95 } | |
96 else { | |
97 logger.debug("Not an instance of FixationArtifact."); | |
98 return null; | |
99 } | |
52 } | 100 } |
53 | 101 |
102 | |
103 protected double getMaxQ(FixResult result, double km) { | |
104 double maxQ = 0; | |
105 | |
106 KMIndex<QW []> kmQWRef = result.getReferenced(); | |
107 | |
108 QW[] qwRef = kmQWRef.binarySearch(km).getValue(); | |
109 if (qwRef != null) { | |
110 for (int i = 0; i < qwRef.length; i++) { | |
111 if (qwRef[i].getQ() > maxQ) { | |
112 maxQ = qwRef[i].getQ(); | |
113 } | |
114 } | |
115 } | |
116 | |
117 KMIndex<AnalysisPeriod []> kmQWDAna = result.getAnalysisPeriods(); | |
118 AnalysisPeriod[] periods = kmQWDAna.binarySearch(km).getValue(); | |
119 | |
120 if(periods != null) { | |
121 for (int i = 0; i < periods.length; i++) { | |
122 QWD[] qwdAna = periods[i].getQWDs(); | |
123 if (qwdAna != null) { | |
124 for (int j = 0; j < qwdAna.length; j++) { | |
125 if (qwdAna[j].getQ() > maxQ) { | |
126 maxQ = qwdAna[j].getQ(); | |
127 } | |
128 } | |
129 } | |
130 } | |
131 } | |
132 return maxQ; | |
133 } | |
54 | 134 |
55 /** | 135 /** |
56 * Create a deep copy of this Facet. | 136 * Create a deep copy of this Facet. |
57 * @return a deep copy. | 137 * @return a deep copy. |
58 */ | 138 */ |