view artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixRealizingCalculationExtended.java @ 9646:0380717105ba

Implemented alternative fitting strategy for Log-Linear function.
author Gernot Belger <g.belger@bjoernsen.de>
date Mon, 02 Dec 2019 17:56:15 +0100
parents 9744ce3c3853
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.model.fixings;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import org.dive4elements.river.artifacts.access.FixRealizingAccess;

/**
 * REMARK: this inheritance is only needed, beause changing the orignal calculation will probably break the
 * serialization of the artifact....
 *
 * @author Gernot Belger
 */
public class FixRealizingCalculationExtended extends FixRealizingCalculation {
    private static final long serialVersionUID = 1L;

    public FixRealizingCalculationExtended(final FixRealizingAccess fixAccess) {
        super(fixAccess);
    }

    public int determineMeanYear() {
        final FixingsOverview overview = FixingsOverviewFactory.getOverview(this.river);
        final ColumnCache cc = new ColumnCache();

        final SortedSet<Integer> years = new TreeSet<>();

        final Calendar cal = Calendar.getInstance();

        final List<FixingColumnWithData> columns = getEventColumns(overview, cc);
        for (final FixingColumnWithData column : columns) {
            final Date date = column.getDate();
            cal.setTime(date);

            final int year = cal.get(Calendar.YEAR);
            years.add(year);
        }

        final Integer first = years.first();
        final Integer last = years.last();
        if (first == null || last == null)
            return -1;

        return (first + last) / 2;
    }
}

http://dive4elements.wald.intevation.org