view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/FlowDepthProcessor.java @ 8980:b194fa64506a

SINFO - show results themes according to spec, either raw data or floating mean values. Some improvements to error handling and handling of empty results.
author gernotbelger
date Thu, 05 Apr 2018 18:30:34 +0200
parents ee5ce13016ed
children 23945061daec
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.common;

import java.util.HashSet;
import java.util.Set;

import org.dive4elements.artifactdatabase.state.Facet;
import org.dive4elements.artifacts.CallContext;

public final class FlowDepthProcessor extends AbstractSInfoLineProcessor<AbstractSInfoCalculationResult> {

    private static final String AXIS_LABEL = "sinfo.chart.flow_depth.section.yaxis.label";

    private static final String SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL = "sinfo.chart.flow_depth.yaxis.label";

    /* Theme name, usually defined in 'FacetTypes', but that is soooo bad dependencies... */
    // REMARK: these mustend with 'filtered' so extra handling happens in chart: point are always recalculated, because data
    // changes depending on zoom state

    /* flow depth */
    public static final String FACET_FLOW_DEPTH_FILTERED = "sinfo_facet_flow_depth.filtered";

    private static final String FACET_FLOW_DEPTH_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth.filtered.description";

    public static final String FACET_FLOW_DEPTH_RAW = "sinfo_facet_flow_depth";

    private static final String FACET_FLOW_DEPTH_RAW_DESCRIPTION = "sinfo.facet.flow_depth.raw.description";

    /* flow depth with tkh */
    private static final String FACET_FLOW_DEPTH_TKH_FILTERED = "sinfo_facet_flow_depth_with_tkh.filtered";

    private static final String FACET_FLOW_DEPTH_TKH_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth_with_tkh.filtered.description";

    public static final String FACET_FLOW_DEPTH_TKH_RAW = "sinfo_facet_flow_depth_with_tkh";

    private static final String FACET_FLOW_DEPTH_TKH_RAW_DESCRIPTION = "sinfo.facet.flow_depth_with_tkh.raw.description";

    /* minimal flow depth */
    public static final String FACET_FLOW_DEPTH_MIN_FILTERED = "sinfo_facet_flow_depth_min.filtered";

    private static final String FACET_FLOW_DEPTH_MIN_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth_min.filtered.description";

    public static final String FACET_FLOW_DEPTH_MIN_RAW = "sinfo_facet_flow_depth_min";

    private static final String FACET_FLOW_DEPTH_MIN_RAW_DESCRIPTION = "sinfo.facet.flow_depth_min.raw.description";

    /* maximal flow depth */
    public static final String FACET_FLOW_DEPTH_MAX_FILTERED = "sinfo_facet_flow_depth_max.filtered";

    private static final String FACET_FLOW_DEPTH_MAX_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth_max.filtered.description";

    public static final String FACET_FLOW_DEPTH_MAX_RAW = "sinfo_facet_flow_depth_max";

    private static final String FACET_FLOW_DEPTH_MAX_RAW_DESCRIPTION = "sinfo.facet.flow_depth_max.raw.description";

    /* current flow depth */
    public static final String FACET_FLOW_DEPTH_CURRENT_FILTERED = "sinfo_facet_flow_depth_current.filtered";

    private static final String FACET_FLOW_DEPTH_CURRENT_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth_current.filtered.description";

    public static final String FACET_FLOW_DEPTH_CURRENT_RAW = "sinfo_facet_flow_depth_current";

    private static final String FACET_FLOW_DEPTH_CURRENT_RAW_DESCRIPTION = "sinfo.facet.flow_depth_current.raw.description";

    /* historical flow depth */
    public static final String FACET_FLOW_DEPTH_HISTORICAL_FILTERED = "sinfo_facet_flow_depth_historical.filtered";

    private static final String FACET_FLOW_DEPTH_HISTORICAL_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth_historical.filtered.description";

    public static final String FACET_FLOW_DEPTH_HISTORICAL_RAW = "sinfo_facet_flow_depth_historical";

    private static final String FACET_FLOW_DEPTH_HISTORICAL_RAW_DESCRIPTION = "sinfo.facet.flow_depth_historical.raw.description";

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

    static {
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_FILTERED);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_RAW);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_TKH_FILTERED);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_TKH_RAW);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_MIN_FILTERED);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_MIN_RAW);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_MAX_FILTERED);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_MAX_RAW);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_CURRENT_FILTERED);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_CURRENT_RAW);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_HISTORICAL_FILTERED);
        HANDLED_FACET_TYPES.add(FACET_FLOW_DEPTH_HISTORICAL_RAW);
    }

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

    @Override
    protected double[][] doGetPoints(final AbstractSInfoCalculationResult data, final String facetName) {

        if (FACET_FLOW_DEPTH_FILTERED.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepth);
        if (FACET_FLOW_DEPTH_RAW.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepth);

        if (FACET_FLOW_DEPTH_TKH_FILTERED.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthtkh);
        if (FACET_FLOW_DEPTH_TKH_RAW.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthtkh);

        if (FACET_FLOW_DEPTH_MIN_FILTERED.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthmin);
        if (FACET_FLOW_DEPTH_MIN_RAW.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthmin);

        if (FACET_FLOW_DEPTH_MAX_FILTERED.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthmax);
        if (FACET_FLOW_DEPTH_MAX_RAW.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthmax);

        if (FACET_FLOW_DEPTH_CURRENT_FILTERED.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthCurrent);
        if (FACET_FLOW_DEPTH_CURRENT_RAW.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthCurrent);

        if (FACET_FLOW_DEPTH_HISTORICAL_FILTERED.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthHistorical);
        if (FACET_FLOW_DEPTH_HISTORICAL_RAW.contentEquals(facetName))
            return data.getStationPoints(SInfoResultType.flowdepthHistorical);

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

    public static Facet createFlowDepthFilteredFacet(final CallContext context, final String hash, final String id, final AbstractSInfoCalculationResult result,
            final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_FILTERED,
                FACET_FLOW_DEPTH_FILTERED_DESCRIPTION);
    }

    public static Facet createFlowDepthRawFacet(final CallContext context, final String hash, final String id, final AbstractSInfoCalculationResult result,
            final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_RAW,
                FACET_FLOW_DEPTH_RAW_DESCRIPTION);
    }

    public static Facet createFlowDepthTkhFilteredFacet(final CallContext context, final String hash, final String id,
            final AbstractSInfoCalculationResult result, final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_TKH_FILTERED,
                FACET_FLOW_DEPTH_TKH_FILTERED_DESCRIPTION);
    }

    public static Facet createFlowDepthTkhRawFacet(final CallContext context, final String hash, final String id, final AbstractSInfoCalculationResult result,
            final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_TKH_RAW,
                FACET_FLOW_DEPTH_TKH_RAW_DESCRIPTION);
    }

    public static Facet createFlowDepthMinFilteredFacet(final CallContext context, final String hash, final String id,
            final AbstractSInfoCalculationResult result, final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_MIN_FILTERED,
                FACET_FLOW_DEPTH_MIN_FILTERED_DESCRIPTION);
    }

    public static Facet createFlowDepthMinRawFacet(final CallContext context, final String hash, final String id, final AbstractSInfoCalculationResult result,
            final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_MIN_RAW,
                FACET_FLOW_DEPTH_MIN_RAW_DESCRIPTION);
    }

    public static Facet createFlowDepthMaxFilteredFacet(final CallContext context, final String hash, final String id,
            final AbstractSInfoCalculationResult result, final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_MAX_FILTERED,
                FACET_FLOW_DEPTH_MAX_FILTERED_DESCRIPTION);
    }

    public static Facet createFlowDepthMaxRawFacet(final CallContext context, final String hash, final String id, final AbstractSInfoCalculationResult result,
            final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_MAX_RAW,
                FACET_FLOW_DEPTH_MAX_RAW_DESCRIPTION);
    }

    public static Facet createFlowDepthCurrentFilteredFacet(final CallContext context, final String hash, final String id,
            final AbstractSInfoCalculationResult result, final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_CURRENT_FILTERED,
                FACET_FLOW_DEPTH_CURRENT_FILTERED_DESCRIPTION);
    }

    public static Facet createFlowDepthCurrentRawFacet(final CallContext context, final String hash, final String id,
            final AbstractSInfoCalculationResult result, final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_CURRENT_RAW,
                FACET_FLOW_DEPTH_CURRENT_RAW_DESCRIPTION);
    }

    public static Facet createFlowDepthHistoricalFilteredFacet(final CallContext context, final String hash, final String id,
            final AbstractSInfoCalculationResult result, final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL,
                FACET_FLOW_DEPTH_HISTORICAL_FILTERED, FACET_FLOW_DEPTH_HISTORICAL_FILTERED_DESCRIPTION);
    }

    public static Facet createFlowDepthHistoricalRawFacet(final CallContext context, final String hash, final String id,
            final AbstractSInfoCalculationResult result, final int index) {
        return AbstractSInfoLineProcessor.createFacet(context, hash, id, result, index, SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, FACET_FLOW_DEPTH_HISTORICAL_RAW,
                FACET_FLOW_DEPTH_HISTORICAL_RAW_DESCRIPTION);
    }
}

http://dive4elements.wald.intevation.org