Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java @ 2758:b05faaa9099b
Create points for ref.curve in facet, handle these in generator.
flys-artifacts/trunk@4493 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 24 May 2012 04:41:57 +0000 |
parents | 94c6f4ad9b98 |
children | 23b4ff116015 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java Thu May 24 04:38:49 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java Thu May 24 04:41:57 2012 +0000 @@ -12,7 +12,8 @@ import de.intevation.flys.artifacts.StaticWKmsArtifact; import de.intevation.flys.artifacts.math.Linear; import de.intevation.flys.artifacts.model.FacetTypes; -import de.intevation.flys.artifacts.model.RelativePointFacet; +import de.intevation.flys.artifacts.model.DurationCurveFacet; +import de.intevation.flys.artifacts.model.ReferenceCurveFacet; import de.intevation.flys.artifacts.model.WQDay; /** @@ -37,22 +38,13 @@ } - /** - * Returns the data this facet requires. - * - * @param artifact the owner artifact. - * @param context the CallContext (ignored). - * - * @return the data. - */ - @Override - public Object getData(Artifact artifact, CallContext context) { - // Find out whether we live in a duration curve context, there we would - // provide only a single point. + protected Point2D calculateDurationCurvePoint(CallContext context, + StaticWKmsArtifact artifact) + { Object wqdays = null; double km = 0d; List<DataProvider> providers = context. - getDataProvider("durationcurve"); + getDataProvider(DurationCurveFacet.BB_DURATIONCURVE); if (providers.size() < 1) { logger.warn("Could not find durationcurve data provider."); } @@ -76,12 +68,9 @@ km = Double.valueOf(dckm); } - StaticWKmsArtifact staticData = - (StaticWKmsArtifact) artifact; - if (wqdays != null) { // Which W at this km? - double w = staticData.getWAtKmLin(staticData.getWKms(0), km); + double w = artifact.getWAtKmLin(artifact.getWKms(0), km); if (w == -1) { logger.warn("w is -1, already bad sign!"); } @@ -112,7 +101,67 @@ return new Point2D.Double((double) day, w); } logger.warn("not wqkms / w / day found"); - + // TODO better signal failure. + return new Point2D.Double(0d, 0d); + //return null; + } + + + /** + * Calculate a reference curve point, that is, a point made of + * the Ws from start and end km param of the reference curve. + */ + public Point2D calculateReferenceCurvePoint(CallContext context, + StaticWKmsArtifact artifact) { + List<DataProvider> providers = context. + getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM); + if (providers.size() < 1) { + logger.warn("Could not find reference curve startkm data provider."); + } + + Double start = (Double) providers.get(0). + provideData(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM, null, context); + + providers = context. + getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS); + if (providers.size() < 1) { + logger.warn("Could not find reference curve endkms data provider."); + } + double[] ends = (double[]) providers.get(0). + provideData(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS, null, context); + + logger.debug("Got s " + start + " e " + ends); + double startW = artifact.getWAtKmLin(artifact.getWKms(0), start.doubleValue()); + // TODO handle multiple ends. + double endW = artifact.getWAtKmLin(artifact.getWKms(0), ends[0]); + logger.debug("Gotw s " + startW + " e " + endW); + return new Point2D.Double(startW, endW); + } + + + /** + * Returns the data this facet requires. + * + * @param artifact the owner artifact. + * @param context the CallContext (ignored). + * + * @return the data. + */ + @Override + public Object getData(Artifact artifact, CallContext context) { + StaticWKmsArtifact staticData = (StaticWKmsArtifact) artifact; + // Find out whether we live in a duration curve context, there we would + // provide only a single point. + + if (context.getDataProvider( + DurationCurveFacet.BB_DURATIONCURVE_KM).size() > 0) { + return calculateDurationCurvePoint(context, staticData); + } + else if (context.getDataProvider( + ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM).size() > 0) { + return calculateReferenceCurvePoint(context, staticData); + } + // TODO better signal failure. return new Point2D.Double(0d, 0d); }