Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCurveFacet.java @ 4357:11cf29eb002c
FacetTypes: New type: exreme_wq_curve_base (for the Stuetz-Q-Poits).
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 02 Nov 2012 11:58:11 +0100 |
parents | b0173cdbbe51 |
children | 2f01b47aa5c2 |
line wrap: on
line source
package de.intevation.flys.artifacts.model.extreme; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.access.ExtremeAccess; import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.DataFacet; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.states.DefaultState.ComputeType; import de.intevation.flys.utils.KMIndex; import de.intevation.flys.utils.DoubleUtil; import org.apache.log4j.Logger; /** * Facet to show the W|Q values. */ public class ExtremeCurveFacet extends DataFacet implements FacetTypes { /** House logger. */ private static Logger logger = Logger.getLogger(ExtremeCurveFacet.class); /** Trivial Constructor. */ public ExtremeCurveFacet() { } /** * @param description Description of the facet. */ public ExtremeCurveFacet(String description) { super(0, EXTREME_WQ_CURVE, description, ComputeType.ADVANCE, null, null); } public ExtremeCurveFacet(int index, String description) { super(index, EXTREME_WQ_CURVE, description, ComputeType.ADVANCE, null, null); } /** * Returns the data (a curve/function) this facet provides at km given in context. * * @param artifact the owner artifact. * @param context the CallContext. * * @return the data. */ @Override public Object getData(Artifact artifact, CallContext context) { logger.debug("ExtremeCurveFacet.getData"); if (artifact instanceof FLYSArtifact) { FLYSArtifact flys = (FLYSArtifact)artifact; CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); ExtremeResult result = (ExtremeResult) res.getData(); double currentKm = ((Double)context.getContextValue("currentKm")).doubleValue(); KMIndex<Curve> curves = result.getCurves(); KMIndex.Entry<Curve> curveEntry = curves.search(currentKm); if (curveEntry != null) { logger.debug("A curve at km = " + currentKm); Curve c = curveEntry.getValue(); // Find segment in which the curr. km is located. ExtremeAccess access = new ExtremeAccess(flys); double[] ds = access.getValuesForRange(currentKm); if (ds != null) { double m = DoubleUtil.maxInArray(ds); // Add 5 percent. m *= 1.05d; c.setSuggestedMaxQ(m); } return c; } else { logger.debug("No curve at km = " + currentKm); return null; } } else { logger.debug("Not an instance of FLYSArtifact / WINFOArtifact."); return null; } } /** * Create a deep copy of this Facet. * @return a deep copy. */ @Override public ExtremeCurveFacet deepCopy() { ExtremeCurveFacet copy = new ExtremeCurveFacet(); copy.set(this); return copy; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :