view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculator.java @ 8946:5d5d482da3e9

Implementing SINFO - FlowDepthMinMax calculation
author gernotbelger
date Tue, 13 Mar 2018 18:49:33 +0100
parents 82998242ba84
children a4f1ac81f26d
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.sinfo.common.RiverInfoProvider;
import org.dive4elements.river.artifacts.sinfo.tkhcalculation.Tkh;
import org.dive4elements.river.artifacts.sinfo.tkhcalculation.TkhCalculator;
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<FlowDepthRow> rows = new ArrayList<>();

    private final BedHeightsFinder bedHeight;

    private final TkhCalculator tkhCalculator;

    private final RiverInfoProvider riverInfoProvider;

    private final String bedHeightLabel;

    private final String wstLabel;

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

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

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

        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 Tkh tkh = this.tkhCalculator.getTkh(station);

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

        // REMARK: access the gauge once only during calculation
        final String gaugeLabel = this.riverInfoProvider.findGauge(station);

        this.rows.add(new FlowDepthRow(tkh, this.wstLabel, gaugeLabel, this.bedHeightLabel, location));
    }
}

http://dive4elements.wald.intevation.org