# HG changeset patch # User Raimund Renkert # Date 1327657335 0 # Node ID c3e523a7634013c0a296303b7ec4047f0f13f925 # Parent 1d7fb2cabfc7b189967d84599fe80576f75a6bdc Added method that return the differences for a w-differences calculation as string. flys-artifacts/trunk@3783 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 1d7fb2cabfc7 -r c3e523a76340 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Jan 27 07:53:03 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Jan 27 09:42:15 2012 +0000 @@ -1,3 +1,9 @@ +2012-01-27 Raimund Renkert + + * src/main/java/de/intevation/flys/utils/FLYSUtils.java: + New method that creates and returns the chosen differences of w-difference + calculation as string. + 2012-01-27 Raimund Renkert Issue 138: PDF output for calculations. diff -r 1d7fb2cabfc7 -r c3e523a76340 flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java Fri Jan 27 07:53:03 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java Fri Jan 27 09:42:15 2012 +0000 @@ -29,9 +29,16 @@ import de.intevation.flys.artifacts.context.FLYSContext; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.WINFOArtifact; +import de.intevation.flys.artifacts.StaticWKmsArtifact; import de.intevation.flys.artifacts.model.RiverFactory; import de.intevation.flys.artifacts.model.LocationProvider; import de.intevation.flys.artifacts.model.WQ; +import de.intevation.flys.artifacts.model.WKms; +import de.intevation.flys.artifacts.model.WQKms; + +import de.intevation.artifactdatabase.state.State; +import de.intevation.flys.artifacts.states.WaterlevelSelectState; +import de.intevation.flys.artifacts.states.WDifferencesState; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.MainValue; import de.intevation.flys.model.River; @@ -621,5 +628,93 @@ return LocationProvider.getLocation(river, km); } + + + /** + * This method returns the differences for a w-differences calculation. + * + * @param winfo The WINFOArtifact. + * @param context The context. + * + * @return The differences as string separated by semicolon and linebreak. + */ + public static String getWDifferences( + WINFOArtifact winfo, + CallContext context) + { + State state = winfo.getCurrentState(context); + if(state instanceof WDifferencesState) { + String diffids = winfo.getDataAsString("diffids"); + String datas[] = diffids.split("#"); + + // Validate the Data-Strings. + for (String s: datas) { + if (!WaterlevelSelectState.isValueValid(winfo.getDataAsString("diffids"))) { + return ""; + } + } + + if (datas.length < 2) { + return ""; + } + + String diffs = ""; + for(int i = 0; i < datas.length; i+=2) { + // e.g.: + // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1 + WKms minuendWKms = getWKms(StringUtil.unbracket(datas[i+0]), + context); + WKms subtrahendWKms = getWKms(StringUtil.unbracket(datas[i+1]), + context); + if (minuendWKms != null && subtrahendWKms != null) { + diffs += StringUtil.wWrap(minuendWKms.getName()) + + " - " + StringUtil.wWrap(subtrahendWKms.getName()); + } + diffs += ";\n"; + } + return diffs; + } + else { + logger.warn("Not a valid state for differences."); + return ""; + } + } + + + protected static 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); + 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]; + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :