view artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstState.java @ 9444:ecadc9ed0ba0

Added heights and depths of cross section fields in the bundu bzws calculation and longitudinal section charts
author mschaefer
date Tue, 21 Aug 2018 13:41:18 +0200
parents d2f5375ede26
children bb278c927b66
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.List;

import org.apache.log4j.Logger;
import org.dive4elements.artifactdatabase.state.Facet;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.ChartArtifact;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.bundu.BUNDUArtifact;
import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
import org.dive4elements.river.artifacts.model.Calculation;
import org.dive4elements.river.artifacts.model.CalculationResult;
import org.dive4elements.river.artifacts.model.DataFacet;
import org.dive4elements.river.artifacts.model.EmptyFacet;
import org.dive4elements.river.artifacts.model.FacetTypes;
import org.dive4elements.river.artifacts.model.ReportFacet;
import org.dive4elements.river.artifacts.states.DefaultState;
import org.dive4elements.river.model.BedHeightValueType;

/**
 * State to compute the bundu bezugswst results.
 */
public class BezugswstState extends DefaultState implements FacetTypes {

    private static final long serialVersionUID = 1L;

    /** The log used in this class. */
    private static Logger log = Logger.getLogger(BezugswstState.class);

    private static final String I18N_WQ_CURVE = "fix.vollmer.wq.curve";

    /**
     * The default constructor that initializes an empty State object.
     */
    public BezugswstState() {
    }

    @Override
    public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) {

        log.debug("BezugswstState.computeAdvance");

        if (artifact instanceof ChartArtifact) {
            facets.add(new EmptyFacet());
            return null;
        }
        return compute((BUNDUArtifact) artifact, context, hash, facets, old);
    }

    @Override
    public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) {

        if (artifact instanceof ChartArtifact) {
            facets.add(new EmptyFacet());
            return null;
        }
        return compute((BUNDUArtifact) artifact, context, hash, facets, old);
    }

    /**
     * Compute result or returned object from cache, create facets.
     *
     * @param old
     *            Object that was cached.
     */
    private Object compute(final BUNDUArtifact artifact, final CallContext context, final String hash, final List<Facet> facets, final Object old) {

        final CalculationResult res = doCompute(artifact, context, old);

        if (facets == null)
            return res;

        final BezugswstCalculationResults results = (BezugswstCalculationResults) res.getData();

        final List<AbstractCalculationExportableResult> resultList = results.getResults();

        int facetIndex = 0;

        if (!resultList.isEmpty()) {
            final BezugswstMainCalculationResult result = (BezugswstMainCalculationResult) resultList.get(0);
            facets.add(BezugswstHeightProcessor.createChannelminFacet(context, hash, this.id, facetIndex++, 0));
            facets.add(BezugswstHeightProcessor.createBedheightFacet(context, hash, this.id, facetIndex++, 0, result.getBedHeightLabel()));
            final String nameQ = result.getWstLabel();
            final String nameW = "W(" + nameQ + ")";
            facets.add(new BezugswstFixationFacet(0, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, hash, this.id));
            facets.add(new BezugswstFixationFacet(0, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, hash, this.id));
            for (int i = BedHeightValueType.FIELD_FIRST_INDEX; i <= BedHeightValueType.FIELD_LAST_INDEX; i++)
                facets.add(BezugswstHeightProcessor.createFieldBedheightFacet(context, hash, this.id, facetIndex++, 0, i));

            facets.add(BezugswstDepthProcessor.createFlowdepthFilteredFacet(context, hash, this.id, facetIndex++, 0, result.getBedHeightLabel()));
            facets.add(BezugswstDepthProcessor.createChanneldepthFacet(context, hash, this.id, facetIndex++, 0));
            for (int i = BedHeightValueType.FIELD_FIRST_INDEX; i <= BedHeightValueType.FIELD_LAST_INDEX; i++)
                facets.add(BezugswstDepthProcessor.createFieldDepthFacet(context, hash, this.id, facetIndex++, 0, i));

            final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id);
            final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id);

            facets.add(csv);
            facets.add(pdf);
        }

        final Calculation report = res.getReport();

        if (report.hasProblems())
            facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id));

        return res;
    }

    private CalculationResult doCompute(final BUNDUArtifact uinfo, final CallContext context, final Object old) {

        if (old instanceof CalculationResult)
            return (CalculationResult) old;

        return new BezugswstCalculation(context).calculate(uinfo);
    }
}

http://dive4elements.wald.intevation.org