# HG changeset patch # User Sascha L. Teichmann # Date 1328292206 0 # Node ID dd93a8e1377a78fcb541f2a792b67bb8dfa349e3 # Parent eab357067e068579e064cef8d5749f8e33ea00ef First steps to serve the data in cm if we are are gauges only. flys-artifacts/trunk@3910 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Feb 03 15:22:56 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Feb 03 18:03:26 2012 +0000 @@ -8,6 +8,40 @@ 2012-02-03 Sascha L. Teichmann + First steps to serve the data in cm if we are are gauges only. + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: + Fetch map gauge station -> gauge datum from backend for reference curve. + + * src/main/java/de/intevation/flys/artifacts/math/LinearFilterFunction.java: + New. Linear transforms another function. + + * src/main/java/de/intevation/flys/artifacts/math/FilterFunction.java: + New. Allows cascading functions. + + * src/main/java/de/intevation/flys/artifacts/model/WWAxisTypes.java: + New. Classifier what kind of axis types are needed. + + * src/main/java/de/intevation/flys/artifacts/model/NormalizedReferenceCurveFacet.java: + Removed. Is now obsolete. + + * src/main/java/de/intevation/flys/artifacts/model/WW.java: + Stores gauge station kms for start and end km if they are any. + + * src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java: + Should generate a WWAxisTypes classifier via side effect to the + call context. + + * src/main/java/de/intevation/flys/artifacts/model/Calculation5.java: + Figure out for each start/end km if its a gauge station and store this + information in the result WWs. + + * src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java + Uses the WWAxisTypes classifier now to generate the right data. + TODO: Use the blackboard object. + +2012-02-03 Sascha L. Teichmann + * src/main/java/de/intevation/flys/artifacts/states/EnterLocationState.java: Removed superfluous imports. diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Fri Feb 03 15:22:56 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Fri Feb 03 18:03:26 2012 +0000 @@ -681,7 +681,9 @@ return error(new WW[0], "no.wst.for.river"); } - return calc5.calculate(wst); + Map kms2gaugeDatums = r.getGaugeDatumsKMs(); + + return calc5.calculate(wst, kms2gaugeDatums); } diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/FilterFunction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/FilterFunction.java Fri Feb 03 18:03:26 2012 +0000 @@ -0,0 +1,16 @@ +package de.intevation.flys.artifacts.math; + +public class FilterFunction implements Function { + + protected Function parent; + + public FilterFunction(Function parent) { + this.parent = parent; + } + + @Override + public double value(double x) { + return parent.value(x); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/LinearFilterFunction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/LinearFilterFunction.java Fri Feb 03 18:03:26 2012 +0000 @@ -0,0 +1,24 @@ +package de.intevation.flys.artifacts.math; + +public class LinearFilterFunction +extends FilterFunction +{ + protected double m; + protected double b; + + public LinearFilterFunction(double m, double b) { + this(Identity.IDENTITY, m, b); + } + + public LinearFilterFunction(Function parent, double m, double b) { + super(parent); + this.m = m; + this.b = b; + } + + @Override + public double value(double x) { + return super.value(x)*m + b; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation5.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation5.java Fri Feb 03 15:22:56 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation5.java Fri Feb 03 18:03:26 2012 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.artifacts.model; import java.util.ArrayList; +import java.util.Map; import org.apache.log4j.Logger; @@ -21,7 +22,10 @@ this.endKms = endKms; } - public CalculationResult calculate(WstValueTable wst) { + public CalculationResult calculate( + WstValueTable wst, + Map kms2gaugeDatums + ) { ArrayList results = new ArrayList(); int numProblems = numProblems(); @@ -34,8 +38,8 @@ if (wws.length == 2) { WW ww = new WW( generateName(startKm, endKm), - startKm, wws[0], - endKm, wws[1]); + startKm, kms2gaugeDatums.get(startKm), wws[0], + endKm, kms2gaugeDatums.get(endKm), wws[1]); if (newNumProblems > numProblems) { ww.removeNaNs(); diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/NormalizedReferenceCurveFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/NormalizedReferenceCurveFacet.java Fri Feb 03 15:22:56 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -package de.intevation.flys.artifacts.model; - -import de.intevation.artifactdatabase.state.Facet; - -import de.intevation.flys.artifacts.states.DefaultState.ComputeType; - -import de.intevation.flys.artifacts.math.Sub; - -public class NormalizedReferenceCurveFacet -extends ReferenceCurveFacet -{ - public NormalizedReferenceCurveFacet() { - } - - public NormalizedReferenceCurveFacet( - int index, - String name, - String description - ) { - super(index, name, description, ComputeType.ADVANCE, null, null); - } - - public NormalizedReferenceCurveFacet( - int index, - String name, - String description, - ComputeType type, - String stateID, - String hash - ) { - super(index, name, description, type, hash, stateID); - } - - @Override - protected Object getInternalData(WW [] wws) { - return new WW.ApplyFunctionIterator(wws[index]) { - { - function1 = new Sub(ww.minWs()); - function2 = new Sub(ww.minWs2()); - } - }; - } - - /** Copy deeply. */ - @Override - public Facet deepCopy() { - NormalizedReferenceCurveFacet copy = - new NormalizedReferenceCurveFacet(); - copy.set(this); - return copy; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java Fri Feb 03 15:22:56 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java Fri Feb 03 18:03:26 2012 +0000 @@ -1,5 +1,8 @@ package de.intevation.flys.artifacts.model; +import java.util.List; +import java.util.Arrays; + import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifacts.Artifact; @@ -15,6 +18,11 @@ public class ReferenceCurveFacet extends DataFacet { + public static final String BLACK_BOARD_KEY = "reference.curve.axis.scale"; + + public static final List BLACK_BOARD_KEY_LIST = + Arrays.asList(new String [] { BLACK_BOARD_KEY }); + private static Logger log = Logger.getLogger(ReferenceCurveFacet.class); public ReferenceCurveFacet() { @@ -42,18 +50,16 @@ " /stateId: " + stateId); } + return getWW(artifact, context); + } + + protected WW getWW(Artifact artifact, CallContext context) { FLYSArtifact winfo = (FLYSArtifact)artifact; CalculationResult res = (CalculationResult) winfo.compute(context, hash, stateId, type, false); - return getInternalData((WW [])res.getData()); - } - - /** To be overwritten by normalized reference curve. */ - protected Object getInternalData(WW [] wws) { - // Using the ApplyFunctionIterator to unify data processing. - return new WW.ApplyFunctionIterator(wws[index]); + return ((WW [])res.getData())[index]; } @Override @@ -72,5 +78,33 @@ copy.set(this); return copy; } + + @Override + public List getDataProviderKeys(Artifact art) { + return BLACK_BOARD_KEY_LIST; + } + + @Override + public Object provideBlackboardData( + Artifact artifact, + Object key, + Object param, + CallContext context + ) { + if (!key.equals(BLACK_BOARD_KEY)) { + return null; + } + + Object obj = context.getContextValue("reference.curve.axis.scale"); + + if (!(obj instanceof WWAxisTypes)) { + obj = new WWAxisTypes(getWW(artifact, context)); + } + else { + ((WWAxisTypes)obj).classify(getWW(artifact, context)); + } + + return obj; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java Fri Feb 03 15:22:56 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java Fri Feb 03 18:03:26 2012 +0000 @@ -16,9 +16,17 @@ protected WW ww; public ApplyFunctionIterator(WW ww) { + this(ww, Identity.IDENTITY, Identity.IDENTITY); + } + + public ApplyFunctionIterator( + WW ww, + Function function1, + Function function2 + ) { this.ww = ww; - this.function1 = Identity.IDENTITY; - this.function2 = Identity.IDENTITY; + this.function1 = function1; + this.function2 = function2; } public boolean hasNext() { @@ -52,6 +60,9 @@ protected double startKm; protected double endKm; + protected Double startDatum; + protected Double endDatum; + public WW() { } @@ -70,16 +81,20 @@ public WW( String name, - double startKm, + double startKm, + Double startDatum, double [] ws, double endKm, + Double endDatum, double [] ws2 ) { - this.name = name; - this.ws = new TDoubleArrayList(ws); - this.ws2 = new TDoubleArrayList(ws2); - this.startKm = startKm; - this.endKm = endKm; + this.name = name; + this.ws = new TDoubleArrayList(ws); + this.ws2 = new TDoubleArrayList(ws2); + this.startKm = startKm; + this.startDatum = startDatum; + this.endKm = endKm; + this.endDatum = endDatum; } public WW(String name, TDoubleArrayList ws, TDoubleArrayList ws2) { @@ -133,6 +148,30 @@ this.endKm = endKm; } + public Double getStartDatum() { + return startDatum; + } + + public boolean startAtGauge() { + return startDatum != null; + } + + public boolean endAtGauge() { + return endDatum != null; + } + + public void setStartDatum(Double startDatum) { + this.startDatum = startDatum; + } + + public Double getEndDatum() { + return endDatum; + } + + public void setEndDatum(Double endDatum) { + this.endDatum = endDatum; + } + @Override public void removeNaNs() { removeNaNs(new TDoubleArrayList [] { ws, ws2 }); diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWAxisTypes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWAxisTypes.java Fri Feb 03 18:03:26 2012 +0000 @@ -0,0 +1,54 @@ +package de.intevation.flys.artifacts.model; + +import de.intevation.flys.artifacts.math.Function; +import de.intevation.flys.artifacts.math.Identity; +import de.intevation.flys.artifacts.math.LinearFilterFunction; + +public class WWAxisTypes +{ + protected boolean inCm1; + protected boolean inCm2; + + public WWAxisTypes() { + inCm1 = inCm2 = true; + } + + public WWAxisTypes(WW ww) { + this(); + classify(ww); + } + + public void classify(WW ww) { + if (!ww.startAtGauge()) inCm1 = false; + if (!ww.endAtGauge()) inCm2 = false; + } + + public boolean getInCm1() { + return inCm1; + } + + public void setInCm1(boolean inCm1) { + this.inCm1 = inCm1; + } + + public boolean getInCm2() { + return inCm2; + } + + public void setInCm2(boolean inCm2) { + this.inCm2 = inCm2; + } + + public WW.ApplyFunctionIterator transform(WW ww) { + Function function1 = inCm1 + ? new LinearFilterFunction(100d, -ww.getStartDatum()) + : Identity.IDENTITY; + + Function function2 = inCm2 + ? new LinearFilterFunction(100d, -ww.getEndDatum()) + : Identity.IDENTITY; + + return new WW.ApplyFunctionIterator(ww, function1, function2); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r eab357067e06 -r dd93a8e1377a flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java Fri Feb 03 15:22:56 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java Fri Feb 03 18:03:26 2012 +0000 @@ -7,6 +7,7 @@ import de.intevation.flys.artifacts.model.WW.ApplyFunctionIterator; import de.intevation.flys.artifacts.model.WW; +import de.intevation.flys.artifacts.model.WWAxisTypes; import de.intevation.flys.jfree.StyledXYSeries; @@ -178,10 +179,15 @@ Document theme, boolean visible ) { - ApplyFunctionIterator iter = (ApplyFunctionIterator) data; + WW ww = (WW)data; + + // TODO: Fetch from black board instead! + WWAxisTypes wwat = new WWAxisTypes(ww); + + ApplyFunctionIterator iter = wwat.transform(ww); XYSeries series = new StyledXYSeries( - iter.getWW().getName(), false, theme); + ww.getName(), false, theme); double [] values = new double[2];