# HG changeset patch # User Felix Wolfsteller # Date 1318951574 0 # Node ID 1a57027286ce4fd8a419d14865cac422c92b0dd9 # Parent 37606f0ddc1e1495722f5529d5c6a07514b6c17a Handle StaticWKmsArtifacts in WDifferencesState. flys-artifacts/trunk@3017 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 37606f0ddc1e -r 1a57027286ce flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Oct 18 15:22:33 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Oct 18 15:26:14 2011 +0000 @@ -1,3 +1,11 @@ +2011-10-18 Felix Wolfsteller + + Refactored WDifferencesState to deal with WKms of different + artifacts (in principle). + + * src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java: + Handle case where WKms come from StaticWKmsArtifact. + 2011-10-18 Felix Wolfsteller Adjusted Datacage-Configuration to fetch "extra longitudinal...." diff -r 37606f0ddc1e -r 1a57027286ce flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java Tue Oct 18 15:22:33 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java Tue Oct 18 15:26:14 2011 +0000 @@ -11,6 +11,7 @@ import de.intevation.artifacts.CallContext; import de.intevation.artifacts.Artifact; import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.StaticWKmsArtifact; import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.math.WKmsOperation; @@ -63,6 +64,44 @@ } + protected WKms getWKms(String mingle, CallContext context) { + String[] def = mingle.split(";"); + String uuid = def[0]; + String name = def[1]; + int idx = Integer.parseInt(def[2]); + + if (name.startsWith("staticwkms")) { + StaticWKmsArtifact staticWKms = + (StaticWKmsArtifact) FLYSUtils.getArtifact( + uuid, + context); + logger.debug("WDifferencesState obtain data from StaticWKms"); + WKms wkms = staticWKms.getWKms(idx); + if (wkms == null) + logger.error("No WKms from artifact."); + return wkms; + } + + WINFOArtifact flys = (WINFOArtifact) FLYSUtils.getArtifact( + uuid, + context); + + if (flys == null) { + logger.warn("One of the artifacts (1) for diff calculation could not be loaded"); + return null; + } + else{ + WQKms[] wqkms = (WQKms[]) flys.getWaterlevelData(). + getData(); + if (wqkms == null) + logger.warn("not waterlevels in artifact"); + else if (wqkms.length < idx) + logger.warn("not enough waterlevels in artifact"); + return wqkms[idx]; + } + } + + /** * Return CalculationResult with Array of WKms that are difference of * Waterlevels. Add respective facets (DifferencesCurveFacet, DataFacet). @@ -75,13 +114,14 @@ List facets, Object old ) { - WINFOArtifact winfo = (WINFOArtifact)artifact; + WINFOArtifact winfo = (WINFOArtifact) artifact; String id = getID(); // Load the Artifacts/facets that we want to subtract and display. // Expected format is: // [42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;0]#[1231f2-....] String diffids = winfo.getDataAsString("diffids"); + logger.debug("WDifferencesState has: " + diffids); String datas[] = diffids.split("#"); // Validate the Data-Strings. @@ -101,39 +141,18 @@ for(int i = 0; i < datas.length; i+=2) { // e.g.: // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1 - String[] def1 = StringUtil.unbracket(datas[i+0]).split(";"); - String[] def2 = StringUtil.unbracket(datas[i+1]).split(";"); - String uuid1 = def1[0]; - String uuid2 = def2[0]; - int idx1 = Integer.parseInt(def1[2]); - int idx2 = Integer.parseInt(def2[2]); - - WINFOArtifact flys1 = (WINFOArtifact) FLYSUtils.getArtifact( - uuid1, - context); - WINFOArtifact flys2 = (WINFOArtifact) FLYSUtils.getArtifact( - uuid2, + WKms minuendWKms = getWKms(StringUtil.unbracket(datas[i+0]), context); - - if (flys1 == null) { - logger.warn("One of the artifacts (1) for diff calculation could not be loaded"); - } - if (flys2 == null) { - logger.warn("One of the artifacts (2) for diff calculation could not be loaded"); - } - // TODO: Issue of multiple results in calculation + WKms subtrahendWKms = getWKms(StringUtil.unbracket(datas[i+1]), + context); + String facetName = "diff ()"; - - if (flys1 != null && flys2 != null) { - WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData(). - getData(); - WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData(). - getData(); - facetName = StringUtil.wWrap(minuend[idx1].getName()) - + " - " + StringUtil.wWrap(subtrahend[idx2].getName()); - WKms wkms = WKmsOperation.SUBTRACTION.operate(minuend[idx1], - subtrahend[idx2]); + if (minuendWKms != null && subtrahendWKms != null) { + facetName = StringUtil.wWrap(minuendWKms.getName()) + + " - " + StringUtil.wWrap(subtrahendWKms.getName()); + WKms wkms = WKmsOperation.SUBTRACTION.operate(minuendWKms, + subtrahendWKms); wkms.setName(facetName); wkmss.add(wkms); logger.debug("WKMSSubtraction happened"); @@ -143,6 +162,7 @@ facets.add(new DifferenceCurveFacet(i/2, W_DIFFERENCES, facetName, ComputeType.ADVANCE, id, hash)); facets.add(new DataFacet(CSV, "CSV data")); + logger.debug("Adding facets in WDifferencesState."); } else { logger.debug("Not adding facets in WDifferencesState.");