view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationMainValuesQFacet.java @ 9257:ef7b65576d4b

Added W and Q main values to S-Info flood duration curve chart
author mschaefer
date Fri, 13 Jul 2018 18:38:05 +0200
parents
children 66b003701546
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.artifacts.sinfo.flood_duration;

import org.apache.log4j.Logger;
import org.dive4elements.artifactdatabase.state.DefaultFacet;
import org.dive4elements.artifacts.Artifact;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.model.CalculationResult;
import org.dive4elements.river.artifacts.model.WQDay;
import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
import org.dive4elements.river.jfree.StickyAxisAnnotation;


/**
 * Facet to show Main Q Values.
 */
public class FloodDurationMainValuesQFacet extends DefaultFacet {

    /** Own log. */
    private static Logger log = Logger.getLogger(FloodDurationMainValuesQFacet.class);

    /** Trivial Constructor. */
    public FloodDurationMainValuesQFacet(final String name, final String description) {
        this.description = description;
        this.name        = name;
        this.index       = 0;
    }

    /**
     * Set the hit-point in Q where a line drawn from the axis would hit the
     * curve in WQDay (if hit).
     * Employ linear interpolation.
     */
    protected static void setHitPoint(final WQDay wqday, final StickyAxisAnnotation annotation) {

        final float q = annotation.getPos();
        final Double day = wqday.interpolateDayByQ(q);

        if (day != null) {
            annotation.setHitPoint(day.floatValue());
        }
        else if (log.isDebugEnabled()) {
            log.debug("StickyAnnotation does not hit wqday curve: " + q);
        }
    }


    /**
     * Returns the data this facet requires.
     *
     * @param artifact the owner artifact.
     * @param context  the CallContext (can be used to find out if in
     *                 navigable fixation-setting, or durationcurve).
     *
     * @return the data.
     */
    @Override
    public Object getData(final Artifact artifact, final CallContext context) {

        log.debug("Get data for flood duration main value Q data");

        final D4EArtifact flys = (D4EArtifact) artifact;

        final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false);

        final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData();

        return data.getMainValueQAnnotation();
    }


    /**
     * Create a deep copy of this Facet.
     * @return a deep copy.
     */
    @Override
    public FloodDurationMainValuesQFacet deepCopy() {
        final FloodDurationMainValuesQFacet copy = new FloodDurationMainValuesQFacet(this.name, this.description);
        copy.set(this);
        return copy;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org