Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java @ 9202:b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
author | mschaefer |
---|---|
date | Mon, 02 Jul 2018 07:33:53 +0200 |
parents | a4121ec450d6 |
children | 3dae6b78e1da |
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.Collections; import java.util.List; 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.IResultType; import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; import org.dive4elements.river.artifacts.common.ResultRow; import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings; import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; import gnu.trove.TDoubleArrayList; /** * Contains the result of a {@link FloodDurationCalculation}. * * @author Gernot Belger */ public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { private static final long serialVersionUID = 1L; private static final String JASPER_FILE = "/jasper/templates/sinfo.floodduration.jrxml"; private final String[] mainvalueLabels; public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows) { super(label, rows); this.mainvalueLabels = mainvalueLabels; } /** * The label of one of the optional main values, or null */ public String getMainValueLabel(final int index) { if (index <= this.mainvalueLabels.length - 1) return this.mainvalueLabels[index]; else return null; } /** * Collection of the result rows containing only the rows describing an infrastructure */ @Override public Collection<ResultRow> getRows() { final List<ResultRow> infrasOnlyRows = new ArrayList<>(); for (final ResultRow row : this.rows) if (row.getValue(SInfoResultType.infrastructuretype) != null) infrasOnlyRows.add(row); return Collections.unmodifiableCollection(infrasOnlyRows); } /** * Fetches the km-longitudinal section of the infrastructures and one of their result fields */ public final double[][] fetchInfrastructurePoints(final IResultType type) { final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); for (final ResultRow row : this.rows) { if (row.getValue(SInfoResultType.infrastructuretype) != null) { xPoints.add(row.getDoubleValue(GeneralResultType.station)); yPoints.add(row.getDoubleValue(type)); } } return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; } /** * Fetches the km-longitudinal section of a main value */ public final double[][] fetchMainValuePoints(final IResultType type) { final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); // final IResultType check = new IResultType[] { SInfoResultType.mainValue1Duration, SInfoResultType.mainValue2Duration, // SInfoResultType.mainValue3Duration }[index]; for (final ResultRow row : this.rows) { // if (!Double.isNaN(row.getDoubleValue(check))) { xPoints.add(row.getDoubleValue(GeneralResultType.station)); yPoints.add(row.getDoubleValue(type)); // } } return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; } @Override protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { if (this.mainvalueLabels.length >= 1) { // "##METADATEN WASSERSPIEGELLAGE" exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL); for (int i = 1; i <= this.mainvalueLabels.length; i++) { // "# Bezeichnung der Wasserspiegellage: " final String label = this.getMainValueLabel(i - 1); exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, String.format("%d: %s", i, label)); } // "# Bezugspegel: " exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, "TODO: gauge"); } } @Override protected String getJasperFile() { // TODO Variante mit Wasserspiegellage(n) return JASPER_FILE; } protected String[] formatRow(final IExportContext exportContextCSV, final ResultRow row) { final Collection<String> lines = new ArrayList<>(10); lines.add(exportContextCSV.formatRowValue(row, GeneralResultType.station)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.riverside)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); if (this.getMainValueLabel(0) != null) { lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel1)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.mainValue1Duration)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge1)); if (this.getMainValueLabel(1) != null) { lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel2)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.mainValue2Duration)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge2)); if (this.getMainValueLabel(2) != null) { lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel3)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.mainValue3Duration)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge3)); } } } lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location)); return lines.toArray(new String[lines.size()]); } @Override public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) { final Collection<String> header = new ArrayList<>(20); header.add(exportContextCSV.formatCsvHeader(GeneralResultType.station)); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.riverside)); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.floodDuration)); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit())); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, SInfoResultType.infrastructureHeight.getUnit())); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); if (this.getMainValueLabel(0) != null) { header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel1, SInfoResultType.waterlevel.getUnit())); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.mainValue1Duration)); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge1, SInfoResultType.discharge.getUnit())); if (this.getMainValueLabel(1) != null) { header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel2, SInfoResultType.waterlevel2.getUnit())); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.mainValue2Duration)); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge2, SInfoResultType.discharge2.getUnit())); if (this.getMainValueLabel(2) != null) { header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel3, SInfoResultType.waterlevel3.getUnit())); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.mainValue3Duration)); header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge3, SInfoResultType.discharge3.getUnit())); } } } header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.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, "riverside_header", SInfoResultType.riverside); exportContextPDF.addJRMetadata(source, "inundationduration_header", SInfoResultType.floodDuration); exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge); exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeight); exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); // TODO Feldnamen ergaenzen und aktivieren wenn Report fertig // if (this.getMainValueLabel(0) != null) { // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.waterlevel); // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.mainValue1Duration); // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.discharge); // if (this.getMainValueLabel(1) != null) { // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.waterlevel2); // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.mainValue2Duration); // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.discharge2); // if (this.getMainValueLabel(2) != null) { // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.waterlevel3); // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.mainValue3Duration); // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.discharge3); // } // } // } exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel); exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location); } }