view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java @ 9170:9b2e46090099

tkh cast exception fix gigantic refactoring 2
author gernotbelger
date Thu, 21 Jun 2018 14:32:11 +0200
parents 23945061daec
children 1614cb14308f
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.flood_duration;

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

import org.apache.commons.lang.math.DoubleRange;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.common.GeneralResultType;
import org.dive4elements.river.artifacts.common.ResultRow;
import org.dive4elements.river.artifacts.model.Calculation;
import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider;
import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
import org.dive4elements.river.artifacts.sinfo.util.WstInfo;

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

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

    private final RiverInfoProvider riverInfoProvider;

    private final CallContext context;

    public FloodDurationCalculator(final CallContext context, final RiverInfoProvider riverInfoProvider) {
        this.context = context;
        this.riverInfoProvider = riverInfoProvider;
    }

    public FloodDurationCalculationResults execute(final Calculation problems, final String label, final WstInfo wstInfo, final String calcModeLabel,
            final DoubleRange calcRange, final String riverside, final String user) {

        calculateResultRow(8888.888);
        calculateResultRow(99);
        calculateResultRow(77);
        final boolean hasTkh = false; // TODO tkh richtig machen, oder anderen result-Type wählen als super-klasse für FloodDurationCalculationResult

        final FloodDurationCalculationResult result = new FloodDurationCalculationResult(label, wstInfo, this.rows, false, 4);

        final RiverInfo riverInfo = new RiverInfo(this.riverInfoProvider.getRiver());

        final FloodDurationCalculationResults results = new FloodDurationCalculationResults(calcModeLabel, user, riverInfo, calcRange, riverside);
        results.addResult(result, problems);
        return results;
    }

    private void calculateResultRow(final double station) {

        final ResultRow row = ResultRow.create();

        // REMARK: access the location once only during calculation
        final String location = this.riverInfoProvider.getLocation(station);
        row.putValue(GeneralResultType.station, station);
        row.putValue(SInfoResultType.riverside, "todo:getRiverside");
        row.putValue(SInfoResultType.inundationduration, 44);
        row.putValue(SInfoResultType.inundationdurationq, 444);
        row.putValue(SInfoResultType.infrastructureHeight, 55);
        row.putValue(SInfoResultType.infrastructuretype, "todo_get_infrastructureType");

        // custom type; each entry produces 4 Columns
        final List<DurationWaterlevel> rowWsps = new ArrayList<>();

        rowWsps.add(new DurationWaterlevel(222, 30, 666, "1. Test"));
        rowWsps.add(new DurationWaterlevel(111, 40, 555, "2. Test"));
        rowWsps.add(new DurationWaterlevel(123, 333, 33, "3. Test"));
        rowWsps.add(new DurationWaterlevel(444, 452, 55, "4. Test"));
        row.putValue(SInfoResultType.customMultiRowColWaterlevel, rowWsps);

        row.putValue(SInfoResultType.gaugeLabel, "todo:getReferencedGauge");
        row.putValue(SInfoResultType.location, "location");

        this.rows.add(row);
    }
}

http://dive4elements.wald.intevation.org