view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculator.java @ 9499:853f2dafc16e

VegetationZones in CrossSectionsDiagram
author gernotbelger
date Thu, 27 Sep 2018 18:06:26 +0200
parents ba1e2e8f05d1
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.flowdepth;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.lang.math.DoubleRange;
import org.dive4elements.river.artifacts.common.GeneralResultType;
import org.dive4elements.river.artifacts.common.ResultRow;
import org.dive4elements.river.artifacts.model.river.RiverInfoProvider;
import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
import org.dive4elements.river.artifacts.sinfo.tkhcalculation.TkhCalculator;
import org.dive4elements.river.artifacts.sinfo.tkhcalculation.TkhCalculator.TkhCalculateState;
import org.dive4elements.river.artifacts.sinfo.tkhstate.BedHeightsFinder;
import org.dive4elements.river.artifacts.sinfo.util.WstInfo;

/**
 * @author Gernot Belger
 */
final class FlowDepthCalculator {

    private final Collection<ResultRow> rows = new ArrayList<>();

    private final BedHeightsFinder bedHeight;

    private final TkhCalculator tkhCalculator;

    private final RiverInfoProvider riverInfoProvider;

    private final String bedHeightLabel;

    private final String wstLabel;

    private final boolean showRefGauges;

    public FlowDepthCalculator(final RiverInfoProvider riverInfoProvider, final String wstLabel, final BedHeightsFinder bedHeight,
            final TkhCalculator tkhCalculator, final boolean showRefGauges) {

        this.riverInfoProvider = riverInfoProvider;
        this.wstLabel = wstLabel;

        this.bedHeight = bedHeight;
        this.tkhCalculator = tkhCalculator;
        this.showRefGauges = showRefGauges;

        this.bedHeightLabel = bedHeight.getInfo().getDescription();
    }

    public FlowDepthCalculationResult execute(final String label, final WstInfo wstInfo, final DoubleRange calcRange) {

        final Collection<Double> stations = this.bedHeight.getStations();
        for (final Double station : stations) {
            if (calcRange.containsDouble(station))
                calculateResultRow(station);
        }

        final boolean hasTkh = this.tkhCalculator.hasTkh();

        return new FlowDepthCalculationResult(label, wstInfo, this.bedHeight.getInfo(), hasTkh, this.rows);
    }

    private void calculateResultRow(final double station) {

        final ResultRow row = ResultRow.create();

        row.putValue(GeneralResultType.waterlevelLabel, this.wstLabel);
        row.putValue(SInfoResultType.soundingLabel, this.bedHeightLabel);

        // REMARK: access the gauge once only during calculation
        if (this.showRefGauges) {
            final String gaugeLabel = this.riverInfoProvider.findGauge(station);
            row.putValue(GeneralResultType.gaugeLabel, gaugeLabel);
        }

        // REMARK: access the location once only during calculation
        final String location = this.riverInfoProvider.getLocation(station);
        row.putValue(GeneralResultType.location, location);

        final TkhCalculateState calcState = this.tkhCalculator.calculateTkh(station, row);
        if ((calcState == TkhCalculateState.SUCCESS) || ((calcState != TkhCalculateState.NO_W) && (calcState != TkhCalculateState.NO_BED_HEIGHT)))
            this.rows.add(row);
        // REMARK: Siehe Softwaretest Zwischenrelease 1 2.2.3, Bedingung nach Ruecksprache ggf. auf SUCCESS reduzieren
    }
}

http://dive4elements.wald.intevation.org