Mercurial > dive4elements > river
changeset 1643:ff7bffb7d5f0
Let WDifferences-diagram show more than one difference, if asked to.
flys-artifacts/trunk@2830 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 27 Sep 2011 09:35:18 +0000 |
parents | 6c0b79efd2c9 |
children | 2df1f9facd6c |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/DifferenceCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java |
diffstat | 3 files changed, 110 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Sep 27 07:41:21 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Sep 27 09:35:18 2011 +0000 @@ -1,3 +1,15 @@ +2011-09-27 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Improved w-differences diagram generation where multiple differences + can be shown. + + * src/main/java/de/intevation/flys/artifacts/math/DifferenceCurveFacet.java: + New facet type. + + * src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java: + Employ new DifferenceCurveFacet, return CalculationResult that can + store more than one WKms. + 2011-09-27 Ingo Weinzierl <ingo@intevation.de> flys/issue320 (ÜSK:Mapserver hat Probleme beim Shapefilepath mit "../" im Pfad)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/DifferenceCurveFacet.java Tue Sep 27 09:35:18 2011 +0000 @@ -0,0 +1,70 @@ +package de.intevation.flys.artifacts.model; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.artifactdatabase.state.DefaultFacet; +import de.intevation.artifactdatabase.state.Facet; + +import de.intevation.flys.artifacts.WINFOArtifact; + +import de.intevation.flys.artifacts.states.DefaultState.ComputeType; + + +/** + * Facet with the curve of a subtraction of two waterlevel-lines. + */ +public class DifferenceCurveFacet extends WaterlevelFacet { + + private static Logger logger = Logger.getLogger(DifferenceCurveFacet.class); + + + public DifferenceCurveFacet() {;} + + public DifferenceCurveFacet( + int index, + String name, + String description, + ComputeType type, + String stateID, + String hash + + ) { + super(index, name, description, type, stateID, hash); + } + + /** + * Get difference curve data. + * @return a WKms at given index. + */ + public Object getData(Artifact artifact, CallContext context) { + WINFOArtifact winfo = (WINFOArtifact)artifact; + + CalculationResult res = (CalculationResult) + winfo.compute(context, hash, stateID, type, false); + + WKms [] wkms = (WKms [])res.getData(); + + WKms result = wkms[index]; + logger.debug("Got difference curve data (" + result.getName() + + ") at index: " + index); + + return result; + } + + + /** Copy deeply. */ + @Override + public Facet deepCopy() { + WaterlevelFacet copy = new DifferenceCurveFacet(); + copy.set(this); + copy.type = type; + copy.stateID = stateID; + copy.hash = hash; + return copy; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java Tue Sep 27 07:41:21 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java Tue Sep 27 09:35:18 2011 +0000 @@ -1,26 +1,28 @@ package de.intevation.flys.artifacts.states; +import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; -import de.intevation.artifacts.CallContext; +import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifactdatabase.data.StateData; -import de.intevation.artifactdatabase.state.Facet; - +import de.intevation.artifacts.CallContext; import de.intevation.artifacts.Artifact; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.WINFOArtifact; import de.intevation.flys.artifacts.math.WKmsOperation; +import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.DataFacet; +import de.intevation.flys.artifacts.model.DifferenceCurveFacet; import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.WaterlevelFacet; import de.intevation.flys.artifacts.model.WKms; import de.intevation.flys.artifacts.model.WQKms; -import de.intevation.flys.artifacts.model.DataFacet; -import de.intevation.artifactdatabase.data.StateData; - import de.intevation.flys.utils.FLYSUtils; @@ -61,7 +63,9 @@ } - + /** + * Return List of WKms that are difference of pairs. + */ @Override public Object computeAdvance( FLYSArtifact artifact, @@ -90,7 +94,7 @@ ; } - WKms wkms = null; + List<WKms> wkmss = new ArrayList<WKms>(); for(int i = 0; i < datas.length /2; i++) { String uuid1 = WaterlevelSelectState.strip(datas[i+0]).split(";")[0]; @@ -110,27 +114,33 @@ logger.warn("One of the artifacts (2) for diff calculation could not be loaded"); } // TODO: Issue of multiple results in calculation - //WKms wkms = null; String facetName = "diff ()"; if (flys1 != null && flys2 != null) { // TODO Also check size. // TODO Also need index of wqkms. - WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData().getData(); - WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData().getData(); + WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData(). + getData(); + WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData(). + getData(); if (datas.length > 2) { logger.error("Cannot keep more than one calculation."); } - wkms = WKmsOperation.SUBTRACTION.operate(minuend[0], subtrahend[0]); - facetName = "W ("+minuend[0].getName() + ") - W (" + subtrahend[0].getName()+")"; + facetName = "W (" + minuend[0].getName() + ") - W (" + subtrahend[0].getName() + ")"; + WKms wkms = WKmsOperation.SUBTRACTION.operate(minuend[0], subtrahend[0]); + wkms.setName(facetName); + wkmss.add(wkms); logger.debug("WKMSSubtraction happened"); } if (facets != null) { // TODO: pass computetype and state id. //, ComputeType.ADVANCE, getID(), hash)); - facets.add(new DataFacet(W_DIFFERENCES, facetName)); + //facets.add(new DataFacet(W_DIFFERENCES, facetName)); + facets.add(new DifferenceCurveFacet(i, W_DIFFERENCES, facetName, + ComputeType.ADVANCE, id, hash)); + //facets.add(new WaterlevelFacet facets.add(new DataFacet(CSV, "CSV data")); } else { @@ -138,7 +148,10 @@ } } - return wkms; + CalculationResult result = new CalculationResult(); + WKms[] diffs = wkmss.toArray(new WKms[wkmss.size()]); + result.setData(diffs); + return result; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :