view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodQProcessor.java @ 9632:9c07a33c2d62

pos 20 steps for q (height)
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Tue, 15 Oct 2019 15:14:07 +0200
parents 6ecd1a28017f
children
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * 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 java.util.HashSet;
import java.util.Set;

import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.artifactdatabase.state.Facet;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.common.AbstractCalculationResult;
import org.dive4elements.river.artifacts.common.AbstractProcessor;
import org.dive4elements.river.artifacts.resources.Resources;
import org.dive4elements.river.artifacts.sinfo.flood_duration.FloodDurationCalculationResult.ValueGetter;
import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
import org.dive4elements.river.exports.DiagramGenerator;
import org.dive4elements.river.exports.process.QOutProcessor;
import org.dive4elements.river.themes.ThemeDocument;

/**
 * Processor to generate the facet and data series of mainvalue discharges
 *
 * @author Matthias Schäfer
 *
 */
public final class FloodQProcessor extends AbstractProcessor {

    private static final String FACET_MAIN_VALUE_Q_DESCRIPTION = "mainvalue.q.description";

    public static final String FACET_MAIN_VALUE_Q = "mainvalue.q";

    private static final String I18N_AXIS_LABEL = QOutProcessor.I18N_LONGITUDINAL_LABEL;

    private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();

    static {
        HANDLED_FACET_TYPES.add(FACET_MAIN_VALUE_Q);
    }

    public FloodQProcessor() {
        super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
    }

    public static Facet createMainValueQFacet(final CallContext context, final String hash, final String id, final FloodDurationCalculationResult result,
            final int facetIndex, final int resultIndex, final int dataIndex) {
        final String description = Resources.getMsg(context.getMeta(), FACET_MAIN_VALUE_Q_DESCRIPTION, FACET_MAIN_VALUE_Q_DESCRIPTION,
                result.getWaterlevelLabel(dataIndex));

        return new FloodDurationFacet(facetIndex, resultIndex, dataIndex, FACET_MAIN_VALUE_Q, description, ComputeType.ADVANCE, I18N_AXIS_LABEL, hash, id);
    }

    @Override
    protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {

        final String facetName = bundle.getFacetName();
        if (FACET_MAIN_VALUE_Q.contentEquals(facetName)) {

            final AbstractCalculationResult data = getResult(generator, bundle);

            final FloodDurationFacet facet = (FloodDurationFacet) bundle.getFacet();
            final int index = facet.getWaterlevelIndex();

            if (data instanceof FloodDurationCalculationResult) {
                final FloodDurationCalculationResult.ValueGetter valuegetter = new ValueGetter() {
                    @Override
                    public double getValue(final DurationWaterlevel waterlevel) {
                        return waterlevel.getDischarge();
                    }
                };
                final double[][] points = ((FloodDurationCalculationResult) data).getMainValueDurationPoints(valuegetter, index);

                return buildStepLineSeriesForType(points, generator, bundle, theme, visible);
            }
        }

        final String error = String.format("Unknown facet name: %s", facetName);
        throw new UnsupportedOperationException(error);
    }
}

http://dive4elements.wald.intevation.org