view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java @ 9581:b61e2a9fa5d6

Punkt 4.1. Mittlere Sohlhöhe (lang, statt "Sohl-")
author gernotbelger
date Tue, 08 Jan 2019 17:34:53 +0100
parents c96f6c8a6b03
children 1d4262a68f1f
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.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.sinfo.common.AbstractTkhCalculationResult;
import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
import org.dive4elements.river.artifacts.sinfo.util.WstInfo;

/**
 * Contains the results of a {@link FloodDurationCalculation}.
 *
 * @author Gernot Belger
 */

final class FlowDepthCalculationResult extends AbstractTkhCalculationResult {

    private static final long serialVersionUID = 1L;

    private enum ExportMode { // TODO; nicht ständig kopieren
        pdf, csv
    }

    private static final String JASPER_FILE = "/jasper/templates/sinfo.flowdepth.jrxml"; // TODO use jrxml-path all over the project

    private final BedHeightInfo sounding;

    public FlowDepthCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding, final boolean hasTkh,
            final Collection<ResultRow> rows) {
        super(label, wst, hasTkh, rows);

        this.sounding = sounding;

    }

    public BedHeightInfo getSounding() {
        return this.sounding;
    }

    @Override
    public void writeCSVHeader(final ExportContextCSV exportContext, final RiverInfo river) {
        // getLog().info("FlowDepthExporter.writeCSVHeader");

        final Collection<String> header = new ArrayList<>(15);

        header.add(exportContext.formatCsvHeader(GeneralResultType.station));
        header.add(exportContext.msgUnitCSV(SInfoResultType.flowdepth));

        if (((FlowDepthCalculationResults) exportContext.getResults()).hasTkh()) {
            header.add(exportContext.msgUnitCSV(SInfoResultType.flowdepthtkh));
            header.add(exportContext.msgUnitCSV(SInfoResultType.tkh));
        }

        header.add(exportContext.msgUnitCSV(SInfoResultType.waterlevel, river.getWstUnit()));
        header.add(exportContext.msgUnitCSV(SInfoResultType.discharge));
        header.add(exportContext.formatCsvHeader(GeneralResultType.waterlevelLabel));

        if (((FlowDepthCalculationResults) exportContext.getResults()).isShowRefGauges()) {
            header.add(exportContext.formatCsvHeader(GeneralResultType.gaugeLabel));
        }

        header.add(exportContext.msgUnitCSV(SInfoResultType.meanBedHeight, river.getWstUnit()));
        header.add(exportContext.formatCsvHeader(SInfoResultType.soundingLabel));
        header.add(exportContext.formatCsvHeader(GeneralResultType.location));

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

    }

    @Override
    protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) {

        exportContextCSV.writeCSVSoundingMetadata(this.sounding);

        exportContextCSV.writeBlankLine();// .writeNext(new String[] { "" }); // break line

        exportContextCSV.writeCSVWaterlevelMetadata(super.getWst()); // TODO move to super

        exportContextCSV.writeBlankLine();// .writeNext(new String[] { "" }); // break line

    }

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

    @Override
    protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) {
        return formatRow(ExportMode.csv, exportContextCSV, row);
    }

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

        return formatRow(ExportMode.pdf, exportContextPDF, row);
    }

    @Override
    protected void addJRTableHeader(final ExportContextPDF exportContextPDF, final MetaAndTableJRDataSource source) {

        /* column headings */
        exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station);
        exportContextPDF.addJRMetadata(source, "flowdepth_header", SInfoResultType.flowdepth);
        exportContextPDF.addJRMetadata(source, "flowdepth_tkh_header", SInfoResultType.flowdepthtkh);
        exportContextPDF.addJRMetadata(source, "tkh_header", SInfoResultType.tkh);
        exportContextPDF.addJRMetadata(source, "waterlevel_header", SInfoResultType.waterlevel);
        exportContextPDF.addJRMetadata(source, "discharge_header", SInfoResultType.discharge);
        exportContextPDF.addJRMetadata(source, "waterlevel_name_header", GeneralResultType.waterlevelLabel);
        exportContextPDF.addJRMetadata(source, "gauge_header", GeneralResultType.gaugeLabel);
        exportContextPDF.addJRMetadata(source, "bedheight_header", SInfoResultType.meanBedHeight);
        exportContextPDF.addJRMetadata(source, "sounding_name_header", SInfoResultType.soundingLabel);
        exportContextPDF.addJRMetadata(source, "location_header", GeneralResultType.location);
    }

    private String[] formatRow(final ExportMode mode, final IExportContext exportContext, final ResultRow row) {

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

        lines.add(exportContext.formatRowValue(row, GeneralResultType.station));
        lines.add(exportContext.formatRowValue(row, SInfoResultType.flowdepth));
        final FlowDepthCalculationResults results = exportContext.getResults();

        // REMARK: for csv: only remove tkh columns, if no result has tkh
        // for pdf: adding by default is necessary. If there is no tkh, columns will be removed later in the exporter.
        if (mode == ExportMode.pdf || results.hasTkh()) {
            lines.add(exportContext.formatRowValue(row, SInfoResultType.flowdepthtkh));
            lines.add(exportContext.formatRowValue(row, SInfoResultType.tkh));
        }

        lines.add(exportContext.formatRowValue(row, SInfoResultType.waterlevel));
        lines.add(exportContext.formatRowValue(row, SInfoResultType.discharge));
        lines.add(exportContext.formatRowValue(row, GeneralResultType.waterlevelLabel));

        if (mode == ExportMode.pdf || results.isShowRefGauges()) {
            lines.add(exportContext.formatRowValue(row, GeneralResultType.gaugeLabel));
        }

        lines.add(exportContext.formatRowValue(row, SInfoResultType.meanBedHeight));
        lines.add(exportContext.formatRowValue(row, SInfoResultType.soundingLabel));
        lines.add(exportContext.formatRowValue(row, GeneralResultType.location));

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

}

http://dive4elements.wald.intevation.org