teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.model.extreme; felix@4314: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.CallContext; felix@4314: teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; felix@4314: teichmann@5831: import org.dive4elements.river.artifacts.access.ExtremeAccess; felix@4314: teichmann@5831: import org.dive4elements.river.artifacts.model.CalculationResult; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.fixings.FixingsFacet; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; teichmann@5831: teichmann@5831: import org.dive4elements.river.utils.KMIndex; teichmann@5831: import org.dive4elements.river.utils.DoubleUtil; felix@4314: felix@4314: import org.apache.log4j.Logger; felix@4314: felix@4314: /** felix@4314: * Facet to show the W|Q values. felix@4314: */ felix@4314: public class ExtremeCurveFacet bjoern@4442: extends FixingsFacet felix@4314: implements FacetTypes { felix@4314: teichmann@8202: /** House log. */ teichmann@8202: private static Logger log = Logger.getLogger(ExtremeCurveFacet.class); felix@4314: felix@4314: felix@4314: /** Trivial Constructor. */ felix@4314: public ExtremeCurveFacet() { felix@4314: } felix@4314: felix@4314: felix@4314: /** felix@4314: * @param description Description of the facet. felix@4314: */ felix@4314: public ExtremeCurveFacet(String description) { tom@8856: super(0, EXTREME_WQ_CURVE, description, tom@8856: ComputeType.ADVANCE, null, null); felix@4314: } felix@4314: felix@4358: /** felix@4358: * @param description Description of the facet. felix@4358: * @param showBase if true, gimme different name. felix@4358: */ felix@4358: public ExtremeCurveFacet(String description, boolean showBase) { tom@8856: super(0, EXTREME_WQ_CURVE_BASE, description, tom@8856: ComputeType.ADVANCE, null, null); felix@4358: if (!showBase) { felix@4358: this.name = EXTREME_WQ_CURVE; felix@4358: } felix@4358: } felix@4358: felix@4314: felix@4314: public ExtremeCurveFacet(int index, String description) { tom@8856: super(index, EXTREME_WQ_CURVE, description, tom@8856: ComputeType.ADVANCE, null, null); felix@4314: } felix@4314: felix@4314: felix@4314: /** tom@8856: * Returns the data (curve) this facet provides at km given in context. felix@4314: * felix@4314: * @param artifact the owner artifact. felix@4314: * @param context the CallContext. felix@4314: * felix@4314: * @return the data. felix@4314: */ felix@4314: @Override felix@4314: public Object getData(Artifact artifact, CallContext context) { teichmann@8202: log.debug("ExtremeCurveFacet.getData"); teichmann@5867: if (artifact instanceof D4EArtifact) { teichmann@5867: D4EArtifact flys = (D4EArtifact)artifact; felix@4314: CalculationResult res = felix@4314: (CalculationResult) flys.compute(context, felix@4314: ComputeType.ADVANCE, felix@4314: false); felix@4314: felix@4314: ExtremeResult result = (ExtremeResult) res.getData(); bjoern@4442: double currentKm = getCurrentKm(context); felix@4314: felix@4314: KMIndex curves = result.getCurves(); felix@4314: felix@4314: KMIndex.Entry curveEntry = curves.search(currentKm); felix@4314: felix@4314: if (curveEntry != null) { teichmann@8202: log.debug("A curve at km = " + currentKm); felix@4336: Curve c = curveEntry.getValue(); felix@4336: // Find segment in which the curr. km is located. teichmann@6101: ExtremeAccess access = new ExtremeAccess(flys); felix@4338: felix@4336: double[] ds = access.getValuesForRange(currentKm); felix@4336: felix@4336: if (ds != null) { felix@4336: double m = DoubleUtil.maxInArray(ds); felix@4336: // Add 5 percent. felix@4336: m *= 1.05d; felix@4336: c.setSuggestedMaxQ(m); felix@4336: } felix@4336: felix@4336: return c; felix@4314: } felix@4314: else { teichmann@8202: log.debug("No curve at km = " + currentKm); felix@4314: return null; felix@4314: } felix@4314: } felix@4314: else { teichmann@8202: log.debug("Not an instance of D4EArtifact / WINFOArtifact."); felix@4314: return null; felix@4314: } felix@4314: } felix@4314: felix@4314: felix@4314: /** felix@4314: * Create a deep copy of this Facet. felix@4314: * @return a deep copy. felix@4314: */ felix@4314: @Override felix@4314: public ExtremeCurveFacet deepCopy() { felix@4314: ExtremeCurveFacet copy = new ExtremeCurveFacet(); felix@4314: copy.set(this); felix@4314: return copy; felix@4314: } felix@4314: } felix@4314: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :