comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java @ 1732:1a57027286ce

Handle StaticWKmsArtifacts in WDifferencesState. flys-artifacts/trunk@3017 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 18 Oct 2011 15:26:14 +0000
parents 56953439dcae
children 6f047a407f84
comparison
equal deleted inserted replaced
1731:37606f0ddc1e 1732:1a57027286ce
9 import de.intevation.artifactdatabase.data.StateData; 9 import de.intevation.artifactdatabase.data.StateData;
10 10
11 import de.intevation.artifacts.CallContext; 11 import de.intevation.artifacts.CallContext;
12 import de.intevation.artifacts.Artifact; 12 import de.intevation.artifacts.Artifact;
13 import de.intevation.flys.artifacts.FLYSArtifact; 13 import de.intevation.flys.artifacts.FLYSArtifact;
14 import de.intevation.flys.artifacts.StaticWKmsArtifact;
14 import de.intevation.flys.artifacts.WINFOArtifact; 15 import de.intevation.flys.artifacts.WINFOArtifact;
15 16
16 import de.intevation.flys.artifacts.math.WKmsOperation; 17 import de.intevation.flys.artifacts.math.WKmsOperation;
17 18
18 import de.intevation.flys.artifacts.model.CalculationResult; 19 import de.intevation.flys.artifacts.model.CalculationResult;
61 62
62 return true; 63 return true;
63 } 64 }
64 65
65 66
67 protected WKms getWKms(String mingle, CallContext context) {
68 String[] def = mingle.split(";");
69 String uuid = def[0];
70 String name = def[1];
71 int idx = Integer.parseInt(def[2]);
72
73 if (name.startsWith("staticwkms")) {
74 StaticWKmsArtifact staticWKms =
75 (StaticWKmsArtifact) FLYSUtils.getArtifact(
76 uuid,
77 context);
78 logger.debug("WDifferencesState obtain data from StaticWKms");
79 WKms wkms = staticWKms.getWKms(idx);
80 if (wkms == null)
81 logger.error("No WKms from artifact.");
82 return wkms;
83 }
84
85 WINFOArtifact flys = (WINFOArtifact) FLYSUtils.getArtifact(
86 uuid,
87 context);
88
89 if (flys == null) {
90 logger.warn("One of the artifacts (1) for diff calculation could not be loaded");
91 return null;
92 }
93 else{
94 WQKms[] wqkms = (WQKms[]) flys.getWaterlevelData().
95 getData();
96 if (wqkms == null)
97 logger.warn("not waterlevels in artifact");
98 else if (wqkms.length < idx)
99 logger.warn("not enough waterlevels in artifact");
100 return wqkms[idx];
101 }
102 }
103
104
66 /** 105 /**
67 * Return CalculationResult with Array of WKms that are difference of 106 * Return CalculationResult with Array of WKms that are difference of
68 * Waterlevels. Add respective facets (DifferencesCurveFacet, DataFacet). 107 * Waterlevels. Add respective facets (DifferencesCurveFacet, DataFacet).
69 */ 108 */
70 @Override 109 @Override
73 String hash, 112 String hash,
74 CallContext context, 113 CallContext context,
75 List<Facet> facets, 114 List<Facet> facets,
76 Object old 115 Object old
77 ) { 116 ) {
78 WINFOArtifact winfo = (WINFOArtifact)artifact; 117 WINFOArtifact winfo = (WINFOArtifact) artifact;
79 String id = getID(); 118 String id = getID();
80 119
81 // Load the Artifacts/facets that we want to subtract and display. 120 // Load the Artifacts/facets that we want to subtract and display.
82 // Expected format is: 121 // Expected format is:
83 // [42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;0]#[1231f2-....] 122 // [42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;0]#[1231f2-....]
84 String diffids = winfo.getDataAsString("diffids"); 123 String diffids = winfo.getDataAsString("diffids");
124 logger.debug("WDifferencesState has: " + diffids);
85 String datas[] = diffids.split("#"); 125 String datas[] = diffids.split("#");
86 126
87 // Validate the Data-Strings. 127 // Validate the Data-Strings.
88 for (String s: datas) { 128 for (String s: datas) {
89 if (!WaterlevelSelectState.isValueValid(winfo.getDataAsString("diffids"))) { 129 if (!WaterlevelSelectState.isValueValid(winfo.getDataAsString("diffids"))) {
99 List<WKms> wkmss = new ArrayList<WKms>(); 139 List<WKms> wkmss = new ArrayList<WKms>();
100 140
101 for(int i = 0; i < datas.length; i+=2) { 141 for(int i = 0; i < datas.length; i+=2) {
102 // e.g.: 142 // e.g.:
103 // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1 143 // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1
104 String[] def1 = StringUtil.unbracket(datas[i+0]).split(";"); 144 WKms minuendWKms = getWKms(StringUtil.unbracket(datas[i+0]),
105 String[] def2 = StringUtil.unbracket(datas[i+1]).split(";");
106 String uuid1 = def1[0];
107 String uuid2 = def2[0];
108 int idx1 = Integer.parseInt(def1[2]);
109 int idx2 = Integer.parseInt(def2[2]);
110
111 WINFOArtifact flys1 = (WINFOArtifact) FLYSUtils.getArtifact(
112 uuid1,
113 context); 145 context);
114 WINFOArtifact flys2 = (WINFOArtifact) FLYSUtils.getArtifact( 146 WKms subtrahendWKms = getWKms(StringUtil.unbracket(datas[i+1]),
115 uuid2,
116 context); 147 context);
117 148
118 if (flys1 == null) {
119 logger.warn("One of the artifacts (1) for diff calculation could not be loaded");
120 }
121 if (flys2 == null) {
122 logger.warn("One of the artifacts (2) for diff calculation could not be loaded");
123 }
124 // TODO: Issue of multiple results in calculation
125 String facetName = "diff ()"; 149 String facetName = "diff ()";
126
127 if (flys1 != null && flys2 != null) {
128 WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData().
129 getData();
130 WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData().
131 getData();
132 150
133 facetName = StringUtil.wWrap(minuend[idx1].getName()) 151 if (minuendWKms != null && subtrahendWKms != null) {
134 + " - " + StringUtil.wWrap(subtrahend[idx2].getName()); 152 facetName = StringUtil.wWrap(minuendWKms.getName())
135 WKms wkms = WKmsOperation.SUBTRACTION.operate(minuend[idx1], 153 + " - " + StringUtil.wWrap(subtrahendWKms.getName());
136 subtrahend[idx2]); 154 WKms wkms = WKmsOperation.SUBTRACTION.operate(minuendWKms,
155 subtrahendWKms);
137 wkms.setName(facetName); 156 wkms.setName(facetName);
138 wkmss.add(wkms); 157 wkmss.add(wkms);
139 logger.debug("WKMSSubtraction happened"); 158 logger.debug("WKMSSubtraction happened");
140 } 159 }
141 160
142 if (facets != null) { 161 if (facets != null) {
143 facets.add(new DifferenceCurveFacet(i/2, W_DIFFERENCES, facetName, 162 facets.add(new DifferenceCurveFacet(i/2, W_DIFFERENCES, facetName,
144 ComputeType.ADVANCE, id, hash)); 163 ComputeType.ADVANCE, id, hash));
145 facets.add(new DataFacet(CSV, "CSV data")); 164 facets.add(new DataFacet(CSV, "CSV data"));
165 logger.debug("Adding facets in WDifferencesState.");
146 } 166 }
147 else { 167 else {
148 logger.debug("Not adding facets in WDifferencesState."); 168 logger.debug("Not adding facets in WDifferencesState.");
149 } 169 }
150 } 170 }

http://dive4elements.wald.intevation.org