view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationMainValuesWFacet.java @ 9259:66b003701546

Added infrastructure height and Q annotation to S-Info flood duration curve chart
author mschaefer
date Mon, 16 Jul 2018 08:43:07 +0200
parents ef7b65576d4b
children 465347d12990
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.RiverAnnotation;
import org.dive4elements.river.jfree.StickyAxisAnnotation;

/**
 * Facet to show Main W Values.
 */
public class FloodDurationMainValuesWFacet extends DefaultFacet {

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

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


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

        final float w = annotation.getPos();
        final Double day = wqday.interpolateDayByW(w);
        if (day != null)
            annotation.setHitPoint(day.floatValue());
        else
            log.debug("StickyAnnotation does not hit wqday curve: " + w);
    }


    /**
     * Returns the data this facet provides.
     *
     * @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 W data");

        final D4EArtifact flys = (D4EArtifact) artifact;

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

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

        return new RiverAnnotation(this.description, data.getMainValueWAnnotations());
    }


    /**
     * Create a deep copy of this Facet.
     * @return a deep copy.
     */
    @Override
    public FloodDurationMainValuesWFacet deepCopy() {
        final FloodDurationMainValuesWFacet copy = new FloodDurationMainValuesWFacet(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