view artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixRealizingCalculationExtended.java @ 9415:9744ce3c3853

Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets. The facets also put the valid station range into their xml-metadata
author gernotbelger
date Thu, 16 Aug 2018 16:27:53 +0200
parents 7565d7dce850
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