Mercurial > dive4elements > river
diff 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 diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java Sun Jul 01 15:29:40 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java Mon Jul 02 07:33:53 2018 +0200 @@ -11,38 +11,108 @@ 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 */ -final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { +public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { private static final long serialVersionUID = 1L; private static final String JASPER_FILE = "/jasper/templates/sinfo.floodduration.jrxml"; - public FloodDurationCalculationResult(final String label, final Collection<ResultRow> rows) { + 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) { - // TODO Metadaten der Wasserspiegellage(n) falls gewählt - // exportContextCSV.writeCSVWaterlevelMetadata(this.wstInfo); - // exportContextCSV.writeBlankLine(); - // writer.writeNext(new String[] { "" }); // break line + 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 @@ -62,7 +132,21 @@ lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); - // TODO Wasserspiegellage(n) und Dauerzahlen falls gewählt + 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)); @@ -82,7 +166,21 @@ header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, SInfoResultType.infrastructureHeight.getUnit())); header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); - // TODO Je vier Spalten der bis zu drei Wasserspiegellagen + 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)); @@ -111,10 +209,25 @@ 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.infrastructureHeightFloodDur); + exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeight); exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); - // TODO Je vier Spalten der bis zu drei Wasserspiegellagen + // 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);