Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java @ 8547:04367906f158
(issue1754) Add distantce handling to WINFO differences state
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 16 Feb 2015 12:55:38 +0100 |
parents | 522f72f43ae6 |
children | fa57a2cb1dfa |
comparison
equal
deleted
inserted
replaced
8546:522f72f43ae6 | 8547:04367906f158 |
---|---|
17 import org.dive4elements.artifactdatabase.state.FacetActivity; | 17 import org.dive4elements.artifactdatabase.state.FacetActivity; |
18 import org.dive4elements.artifactdatabase.data.StateData; | 18 import org.dive4elements.artifactdatabase.data.StateData; |
19 | 19 |
20 import org.dive4elements.artifacts.CallContext; | 20 import org.dive4elements.artifacts.CallContext; |
21 import org.dive4elements.artifacts.Artifact; | 21 import org.dive4elements.artifacts.Artifact; |
22 import org.dive4elements.river.artifacts.access.RangeAccess; | |
22 import org.dive4elements.river.artifacts.ChartArtifact; | 23 import org.dive4elements.river.artifacts.ChartArtifact; |
23 import org.dive4elements.river.artifacts.D4EArtifact; | 24 import org.dive4elements.river.artifacts.D4EArtifact; |
24 import org.dive4elements.river.artifacts.FixationArtifact; | 25 import org.dive4elements.river.artifacts.FixationArtifact; |
25 import org.dive4elements.river.artifacts.MINFOArtifact; | 26 import org.dive4elements.river.artifacts.MINFOArtifact; |
26 import org.dive4elements.river.artifacts.StaticWKmsArtifact; | 27 import org.dive4elements.river.artifacts.StaticWKmsArtifact; |
106 | 107 |
107 | 108 |
108 /** | 109 /** |
109 * Access the data (wkms) of an artifact, coded in mingle. | 110 * Access the data (wkms) of an artifact, coded in mingle. |
110 */ | 111 */ |
111 public WKms getWKms(String mingle, CallContext context) { | 112 public WKms getWKms(String mingle, CallContext context, double from, double to) { |
112 log.debug("WDifferencesState.getWKms " + mingle); | 113 log.debug("WDifferencesState.getWKms " + mingle); |
113 String[] def = mingle.split(";"); | 114 String[] def = mingle.split(";"); |
114 String uuid = def[0]; | 115 String uuid = def[0]; |
115 String name = def[1]; | 116 String name = def[1]; |
116 int idx = Integer.parseInt(def[2]); | 117 int idx = Integer.parseInt(def[2]); |
117 | |
118 if (name.startsWith("staticwkms")) { | |
119 StaticWKmsArtifact staticWKms = | |
120 (StaticWKmsArtifact) RiverUtils.getArtifact( | |
121 uuid, | |
122 context); | |
123 log.debug("WDifferencesState obtain data from StaticWKms"); | |
124 WKms wkms = staticWKms.getWKms(idx); | |
125 if (wkms == null) | |
126 log.error("No WKms from artifact."); | |
127 return wkms; | |
128 } | |
129 | |
130 D4EArtifact d4eArtifact = RiverUtils.getArtifact( | 118 D4EArtifact d4eArtifact = RiverUtils.getArtifact( |
131 uuid, | 119 uuid, |
132 context); | 120 context); |
133 | 121 |
134 if (d4eArtifact == null) { | 122 if (d4eArtifact == null) { |
135 log.warn("One of the artifacts (1) for diff calculation could not be loaded"); | 123 log.warn("One of the artifacts (1) for diff calculation could not be loaded"); |
136 return null; | 124 return null; |
137 } | 125 } |
138 | 126 |
139 if (d4eArtifact instanceof WINFOArtifact) { | 127 if (d4eArtifact instanceof StaticWKmsArtifact) { |
128 StaticWKmsArtifact staticWKms = (StaticWKmsArtifact) d4eArtifact; | |
129 log.debug("WDifferencesState obtain data from StaticWKms"); | |
130 WKms wkms = staticWKms.getWKms(idx, from, to); | |
131 if (wkms == null) { | |
132 log.error("No WKms from Static artifact for this range."); | |
133 return new WQKms(); | |
134 } | |
135 return wkms; | |
136 } else if (d4eArtifact instanceof WINFOArtifact) { | |
140 log.debug("Get WKms from WINFOArtifact"); | 137 log.debug("Get WKms from WINFOArtifact"); |
141 WINFOArtifact flys = (WINFOArtifact) d4eArtifact; | 138 WINFOArtifact flys = (WINFOArtifact) d4eArtifact; |
142 | 139 |
143 WKms[] wkms = (WKms[]) flys.getWaterlevelData(context). | 140 WKms[] wkms = (WKms[]) flys.getWaterlevelData(context). |
144 getData(); | 141 getData(); |
148 else if (wkms.length < idx+1) { | 145 else if (wkms.length < idx+1) { |
149 log.warn("Not enough waterlevels in artifact."); | 146 log.warn("Not enough waterlevels in artifact."); |
150 return new WQKms(); | 147 return new WQKms(); |
151 } | 148 } |
152 return wkms[idx]; | 149 return wkms[idx]; |
153 } | 150 } else if (d4eArtifact instanceof MINFOArtifact) { |
154 else if (d4eArtifact instanceof MINFOArtifact) { | |
155 log.warn("Get WKms from MINFOArtifact not implemented!"); | 151 log.warn("Get WKms from MINFOArtifact not implemented!"); |
156 // CalculationResult r = (CalculationResult) | 152 // CalculationResult r = (CalculationResult) |
157 // d4eArtifact.compute(context, ComputeType.ADVANCE, false); | 153 // d4eArtifact.compute(context, ComputeType.ADVANCE, false); |
158 } | 154 } else if (d4eArtifact instanceof FixationArtifact) { |
159 else if (d4eArtifact instanceof FixationArtifact) { | |
160 log.debug ("Get WKms from FixationArtifact."); | 155 log.debug ("Get WKms from FixationArtifact."); |
161 CalculationResult r = (CalculationResult) | 156 CalculationResult r = (CalculationResult) |
162 d4eArtifact.compute(context, ComputeType.ADVANCE, false); | 157 d4eArtifact.compute(context, ComputeType.ADVANCE, false); |
163 FixRealizingResult frR = (FixRealizingResult) r.getData(); | 158 FixRealizingResult frR = (FixRealizingResult) r.getData(); |
164 return frR.getWQKms()[idx]; | 159 return frR.getWQKms()[idx]; |
186 facets.add(new EmptyFacet()); | 181 facets.add(new EmptyFacet()); |
187 return null; | 182 return null; |
188 } | 183 } |
189 WINFOArtifact winfo = (WINFOArtifact) artifact; | 184 WINFOArtifact winfo = (WINFOArtifact) artifact; |
190 String id = getID(); | 185 String id = getID(); |
191 | 186 RangeAccess rangeAccess = new RangeAccess(artifact); |
187 double from = rangeAccess.getFrom(); | |
188 double to = rangeAccess.getTo(); | |
192 // Load the Artifacts/facets that we want to subtract and display. | 189 // Load the Artifacts/facets that we want to subtract and display. |
193 // Expected format is: | 190 // Expected format is: |
194 // [42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;0]#[1231f2-....] | 191 // [42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;0]#[1231f2-....] |
195 String diffids = winfo.getDataAsString("diffids"); | 192 String diffids = winfo.getDataAsString("diffids"); |
196 log.debug("WDifferencesState has: " + diffids); | 193 log.debug("WDifferencesState has: " + diffids); |
211 | 208 |
212 for(int i = 0; i < datas.length; i+=2) { | 209 for(int i = 0; i < datas.length; i+=2) { |
213 // e.g.: | 210 // e.g.: |
214 // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1 | 211 // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1 |
215 WKms minuendWKms = getWKms(StringUtil.unbracket(datas[i+0]), | 212 WKms minuendWKms = getWKms(StringUtil.unbracket(datas[i+0]), |
216 context); | 213 context, from, to); |
217 WKms subtrahendWKms = getWKms(StringUtil.unbracket(datas[i+1]), | 214 WKms subtrahendWKms = getWKms(StringUtil.unbracket(datas[i+1]), |
218 context); | 215 context, from, to); |
219 | 216 |
220 String facetName = "diff ()"; | 217 String facetName = "diff ()"; |
221 String minName = "min"; | 218 String minName = "min"; |
222 String subName = "sub"; | 219 String subName = "sub"; |
223 | 220 |