view artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstMainCalculationResult.java @ 9708:93389a05119e

zu Nachtrag - BezugsWST in intell. Datenkorb
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Fri, 22 Jan 2021 18:45:39 +0100
parents 7228bd10a8cc
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.bundu.bezugswst;

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

import org.dive4elements.river.artifacts.bundu.BunduResultType;
import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
import org.dive4elements.river.artifacts.common.ExportContextCSV;
import org.dive4elements.river.artifacts.common.ExportContextPDF;
import org.dive4elements.river.artifacts.common.GeneralResultType;
import org.dive4elements.river.artifacts.common.IExportContext;
import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
import org.dive4elements.river.artifacts.common.ResultRow;
import org.dive4elements.river.artifacts.model.WQKms;
import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
import org.dive4elements.river.artifacts.sinfo.util.WstInfo;

import gnu.trove.TDoubleArrayList;

/**
 * Contains the results of a //TODO LINK{@link BezugswstCalculation}.
 *
 * @author Gernot Belger
 */
public final class BezugswstMainCalculationResult extends AbstractCalculationExportableResult {

    private static final long serialVersionUID = 1L;

    private static final String JASPER_FILE = "/jasper/templates/bundu.bezugswst.jrxml";

    private final WstInfo wst;
    private final BedHeightInfo sounding;
    private final String function;
    private final boolean preprocessing;
    private final int startYear;
    private final int endYear;
    private final Double missingVolumeFrom;
    private final Double missingVolumeTo;
    private final Integer ud;
    private final String qOfGauges;

    private final WQKms wqkms;

    public BezugswstMainCalculationResult(final String label, final Collection<ResultRow> rows, final BedHeightInfo sounding, final WstInfo wst,
            final String function, final boolean preprocessing, final int startYear, final int endYear, final Integer ud, final String qOfGauges,
            final WQKms wqkms, final Double missingVolumeFrom, final Double missingVolumeTo) {
        super(label, rows);
        this.wst = wst;
        this.sounding = sounding;
        this.function = function;
        this.preprocessing = preprocessing;
        this.startYear = startYear;
        this.endYear = endYear;
        this.missingVolumeTo = missingVolumeTo;
        this.missingVolumeFrom = missingVolumeFrom;
        this.ud = ud;
        this.qOfGauges = qOfGauges;
        this.wqkms = wqkms;
    }

    public WQKms getWQKms() {
        return this.wqkms;
    }

    public String getWstLabel() {
        if (this.ud != null)
            return Integer.toString(this.getEndYear()) + "; UD=" + Integer.toString(this.ud); // FIXME per WaterlevelDescriptionBuilder o.ä. zentralisieren
        return Integer.toString(this.getEndYear()) + "; " + this.wst.getLabel();
    }

    public String getBedHeightLabel() {
        if (this.sounding != null)
            return this.sounding.getDescription();
        return "";
    }

    public boolean getIsMissingVolume() {
        return !Double.isNaN(this.missingVolumeFrom);
    }

    @Override
    protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) {

        exportContextCSV.writeCSVWaterlevelMetadata(this.wst);
        exportContextCSV.writeBlankLine();
        if (this.sounding != null)
            exportContextCSV.writeCSVSoundingMetadata(this.sounding, "common.export.csv.meta.header.sounding");

        // Reihenfolge in der LV anders; ich finde sie aber so sinnvoller
        exportContextCSV.writeCSVMetaEntry("bundu.export.bezugswst.csv.meta.function", this.function);
        exportContextCSV.writeCSVMetaEntry("bundu.export.bezugswst.csv.meta.preprocessing", exportContextCSV.msg(String.valueOf(this.preprocessing)));
        exportContextCSV.writeCSVMetaEntry("bundu.export.bezugswst.csv.meta.q_period", String.valueOf(this.startYear), String.valueOf(this.getEndYear()));
        if (this.ud != null)
            exportContextCSV.writeCSVMetaEntry("bundu.export.bezugswst.csv.meta.ud", this.ud);
        else if (this.qOfGauges != null)
            exportContextCSV.writeCSVMetaEntry("common.export.waterlevel.csv.meta.q", this.qOfGauges);

        if (this.missingVolumeFrom != null && this.missingVolumeTo != null)
            exportContextCSV.writeCSVMetaEntry("bundu.export.bezugswst.csv.meta.missing_volume_range", this.missingVolumeFrom, this.missingVolumeTo);

        exportContextCSV.writeBlankLine();
    }

    @Override
    protected String getJasperFile() {
        return JASPER_FILE;
    }

    protected String[] formatRow(final IExportContext exportContext, final ResultRow row) {

        final Collection<String> lines = new ArrayList<>(10);

        lines.add(exportContext.formatRowValue(row, GeneralResultType.station));
        lines.add(exportContext.formatRowValue(row, BunduResultType.bezugswst));
        lines.add(exportContext.formatRowValue(row, GeneralResultType.dischargeQwithUnit));

        lines.add(exportContext.formatRowValue(row, GeneralResultType.waterlevelLabel));
        lines.add(exportContext.formatRowValue(row, GeneralResultType.gaugeLabel));
        lines.add(exportContext.formatRowValue(row, GeneralResultType.location));

        return lines.toArray(new String[lines.size()]);
    }

    @Override
    public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) {
        final int colSize = 6;
        exportContextCSV.writeTitleForTabs("bundu.export.csv.title.bezugswst.overview", colSize); // Voraussetzung für Tabs ist, dass der Titel vor den Headern
        final Collection<String> header = new ArrayList<>(colSize);

        header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station));
        header.add(exportContextCSV.formatCsvHeader(BunduResultType.bezugswst) + " [" + river.getWstUnit() + "]");
        header.add(exportContextCSV.formatCsvHeader(GeneralResultType.dischargeQwithUnit));
        header.add(exportContextCSV.formatCsvHeader(GeneralResultType.waterlevelLabel));
        header.add(exportContextCSV.formatCsvHeader(GeneralResultType.gaugeLabel));
        header.add(exportContextCSV.formatCsvHeader(GeneralResultType.location));

        exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));

    }

    @Override
    protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) {

        return this.formatRow(exportContextCSV, row);
    }

    @Override
    protected String[] formatPDFRow(final ExportContextPDF exportContextPDF, final ResultRow row) {

        return this.formatRow(exportContextPDF, row);
    }

    @Override
    protected void addJRTableHeader(final ExportContextPDF exportContextPDF, final MetaAndTableJRDataSource source) {
        /* column headings */
        exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station);
        exportContextPDF.addJRMetadata(source, "bezugswst_header", BunduResultType.bezugswst);
        // exportContextPDF.addJRMetadata(source, " [" + river.getWstUnit() + "]");
        exportContextPDF.addJRMetadata(source, "discharge_header", GeneralResultType.dischargeQwithUnit);
        exportContextPDF.addJRMetadata(source, "waterlevel_name_header", GeneralResultType.waterlevelLabel);
        exportContextPDF.addJRMetadata(source, "gauge_header", GeneralResultType.gaugeLabel);
        exportContextPDF.addJRMetadata(source, "location_header", GeneralResultType.location);

    }

    /**
     * Gets a longitudinal section of a result type value of a cross section field
     *
     * @param fieldIndex
     *            1-based field index
     * @param type
     *            result type like bedHeightField
     */
    public final double[][] getFieldValuePoints(final int fieldIndex, final BunduResultType type) {

        final TDoubleArrayList x = new TDoubleArrayList(this.getRows().size());
        final TDoubleArrayList y = new TDoubleArrayList(this.getRows().size());

        for (final ResultRow row : this.getRows()) {
            x.add(row.getDoubleValue(GeneralResultType.station));
            @SuppressWarnings("unchecked")
            final List<Double> fieldHeights = (List<Double>) row.getValue(type);
            y.add(fieldHeights.get(fieldIndex - 1));
        }

        return new double[][] { x.toNativeArray(), y.toNativeArray() };
    }

	public int getEndYear() {
		return endYear;
	}
}

http://dive4elements.wald.intevation.org