view artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstHeightProcessor.java @ 9583:2a67d05a1af0

Punkt 10.4 Sohlhöhe (rechts)/(links)
author gernotbelger
date Wed, 09 Jan 2019 14:48:53 +0100
parents 3fa8551c3d1b
children 5395c6d4ca50
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.bundu.bezugswst;

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.bundu.BunduResultType;
import org.dive4elements.river.artifacts.common.AbstractProcessor;
import org.dive4elements.river.artifacts.common.AbstractResultType;
import org.dive4elements.river.artifacts.resources.Resources;
import org.dive4elements.river.exports.DiagramGenerator;
import org.dive4elements.river.exports.LongitudinalSectionGenerator;
import org.dive4elements.river.model.BedHeightValueType;
import org.dive4elements.river.themes.ThemeDocument;

/**
 * Processor to generate the facets and data series of a bundu bezugswst depth longitudinal section
 *
 * @author Matthias Schäfer
 *
 */
public final class BezugswstHeightProcessor extends AbstractProcessor {

    private static final String FACET_CHANNELMIN = "bundu_facet_channelmin";

    private static final String FACET_CHANNELMIN_DESCRIPTION = "bundu_facet_channelmin.description";

    private static final String FACET_BEDHEIGHT = "bundu_facet_bedheight";

    private static final String FACET_BEDHEIGHT_DESCRIPTION = "bundu_facet_bedheight.description";

    public static final String FACET_FIELD_BEDHEIGHT_PREFIX = "bundu_facet_bedheight_";

    private static final String FACET_FIELD_BEDHEIGHT_FORMAT = FACET_FIELD_BEDHEIGHT_PREFIX + "%02d";

    private static final String FACET_FIELD_BEDHEIGHT_DESCRIPTION = "bundu_facet_field_bedheight.description";

    private static final String AXIS_LABEL = LongitudinalSectionGenerator.I18N_YAXIS_LABEL;

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

    static {
        HANDLED_FACET_TYPES.add(FACET_CHANNELMIN);
        HANDLED_FACET_TYPES.add(FACET_BEDHEIGHT);
        for (int i = BedHeightValueType.FIELD_FIRST_INDEX; i <= BedHeightValueType.FIELD_LAST_INDEX; i++)
            HANDLED_FACET_TYPES.add(String.format(FACET_FIELD_BEDHEIGHT_FORMAT, i));
    }

    public BezugswstHeightProcessor() {
        super(AXIS_LABEL, HANDLED_FACET_TYPES);
    }

    public static Facet createChannelminFacet(final CallContext context, final String hash, final String id, final int facetIndex, final int resultIndex) {

        final String description = Resources.getMsg(context.getMeta(), FACET_CHANNELMIN_DESCRIPTION, FACET_CHANNELMIN_DESCRIPTION);
        return new BezugswstResultFacet(facetIndex, resultIndex, FACET_CHANNELMIN, description, AXIS_LABEL, id, hash);
    }

    public static Facet createBedheightFacet(final CallContext context, final String hash, final String id, final int facetIndex, final int resultIndex,
            final String seriesName) {

        final String description = Resources.getMsg(context.getMeta(), FACET_BEDHEIGHT_DESCRIPTION, FACET_BEDHEIGHT_DESCRIPTION, seriesName);
        return new BezugswstResultFacet(facetIndex, resultIndex, FACET_BEDHEIGHT, description, AXIS_LABEL, id, hash);
    }

    public static Facet createFieldBedheightFacet(final CallContext context, final String hash, final String id, final int facetIndex, final int resultIndex,
            final int fieldIndex) {
        final String leftRightAppendixKey = BedHeightValueType.field(fieldIndex).getLeftRightStringAppendix();
        final String leftRightAppendix = Resources.getMsg(context.getMeta(), leftRightAppendixKey, leftRightAppendixKey);
        final String description = Resources.getMsg(context.getMeta(), FACET_FIELD_BEDHEIGHT_DESCRIPTION, FACET_FIELD_BEDHEIGHT_DESCRIPTION, fieldIndex,
                leftRightAppendix);

        final String facetName = String.format(FACET_FIELD_BEDHEIGHT_FORMAT, fieldIndex);
        return new BezugswstResultFacet(facetIndex, resultIndex, facetName, description, AXIS_LABEL, id, hash);
    }

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

        if (bundle.getFacetName().startsWith(FACET_FIELD_BEDHEIGHT_PREFIX)) {
            final int fieldIndex = Integer.parseInt(bundle.getFacetName().substring(FACET_FIELD_BEDHEIGHT_PREFIX.length()));
            return generateFieldHeightSeries(generator, bundle, theme, visible, fieldIndex);
        }

        return buildSeriesForType(generator, bundle, theme, visible, doGetType(bundle.getFacetName()), null);
    }

    protected AbstractResultType doGetType(final String facetName) {

        if (FACET_CHANNELMIN.contentEquals(facetName))
            return BunduResultType.channelLowerEdge;
        if (FACET_BEDHEIGHT.contentEquals(facetName))
            return BunduResultType.heightMeanBed;

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

    private final String generateFieldHeightSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme,
            final boolean visible, final int fieldIndex) {

        final BezugswstMainCalculationResult data = (BezugswstMainCalculationResult) getResult(generator, bundle);
        final double[][] points = data.getFieldValuePoints(fieldIndex, BunduResultType.bedHeightFields);

        return buildSeriesForPoints(points, generator, bundle, theme, visible, null);
    }
}

http://dive4elements.wald.intevation.org