comparison 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
comparison
equal deleted inserted replaced
9201:491e1a434457 9202:b4402594213b
9 */ 9 */
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; 10 package org.dive4elements.river.artifacts.sinfo.flood_duration;
11 11
12 import java.util.ArrayList; 12 import java.util.ArrayList;
13 import java.util.Collection; 13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.List;
14 16
15 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; 17 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
16 import org.dive4elements.river.artifacts.common.ExportContextCSV; 18 import org.dive4elements.river.artifacts.common.ExportContextCSV;
17 import org.dive4elements.river.artifacts.common.ExportContextPDF; 19 import org.dive4elements.river.artifacts.common.ExportContextPDF;
18 import org.dive4elements.river.artifacts.common.GeneralResultType; 20 import org.dive4elements.river.artifacts.common.GeneralResultType;
19 import org.dive4elements.river.artifacts.common.IExportContext; 21 import org.dive4elements.river.artifacts.common.IExportContext;
22 import org.dive4elements.river.artifacts.common.IResultType;
20 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; 23 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
21 import org.dive4elements.river.artifacts.common.ResultRow; 24 import org.dive4elements.river.artifacts.common.ResultRow;
25 import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings;
22 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; 26 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
23 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; 27 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
28
29 import gnu.trove.TDoubleArrayList;
24 30
25 /** 31 /**
26 * Contains the result of a {@link FloodDurationCalculation}. 32 * Contains the result of a {@link FloodDurationCalculation}.
27 * 33 *
28 * @author Gernot Belger 34 * @author Gernot Belger
29 */ 35 */
30 final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { 36 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult {
31 37
32 private static final long serialVersionUID = 1L; 38 private static final long serialVersionUID = 1L;
33 39
34 private static final String JASPER_FILE = "/jasper/templates/sinfo.floodduration.jrxml"; 40 private static final String JASPER_FILE = "/jasper/templates/sinfo.floodduration.jrxml";
35 41
36 public FloodDurationCalculationResult(final String label, final Collection<ResultRow> rows) { 42 private final String[] mainvalueLabels;
43
44 public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows) {
37 super(label, rows); 45 super(label, rows);
46 this.mainvalueLabels = mainvalueLabels;
47 }
48
49 /**
50 * The label of one of the optional main values, or null
51 */
52 public String getMainValueLabel(final int index) {
53 if (index <= this.mainvalueLabels.length - 1)
54 return this.mainvalueLabels[index];
55 else
56 return null;
57 }
58
59 /**
60 * Collection of the result rows containing only the rows describing an infrastructure
61 */
62 @Override
63 public Collection<ResultRow> getRows() {
64 final List<ResultRow> infrasOnlyRows = new ArrayList<>();
65 for (final ResultRow row : this.rows)
66 if (row.getValue(SInfoResultType.infrastructuretype) != null)
67 infrasOnlyRows.add(row);
68 return Collections.unmodifiableCollection(infrasOnlyRows);
69 }
70
71 /**
72 * Fetches the km-longitudinal section of the infrastructures and one of their result fields
73 */
74 public final double[][] fetchInfrastructurePoints(final IResultType type) {
75 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
76 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
77 for (final ResultRow row : this.rows) {
78 if (row.getValue(SInfoResultType.infrastructuretype) != null) {
79 xPoints.add(row.getDoubleValue(GeneralResultType.station));
80 yPoints.add(row.getDoubleValue(type));
81 }
82 }
83 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
84 }
85
86 /**
87 * Fetches the km-longitudinal section of a main value
88 */
89 public final double[][] fetchMainValuePoints(final IResultType type) {
90 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
91 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
92 // final IResultType check = new IResultType[] { SInfoResultType.mainValue1Duration, SInfoResultType.mainValue2Duration,
93 // SInfoResultType.mainValue3Duration }[index];
94 for (final ResultRow row : this.rows) {
95 // if (!Double.isNaN(row.getDoubleValue(check))) {
96 xPoints.add(row.getDoubleValue(GeneralResultType.station));
97 yPoints.add(row.getDoubleValue(type));
98 // }
99 }
100 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
38 } 101 }
39 102
40 @Override 103 @Override
41 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { 104 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) {
42 // TODO Metadaten der Wasserspiegellage(n) falls gewählt 105 if (this.mainvalueLabels.length >= 1) {
43 // exportContextCSV.writeCSVWaterlevelMetadata(this.wstInfo); 106 // "##METADATEN WASSERSPIEGELLAGE"
44 // exportContextCSV.writeBlankLine(); 107 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL);
45 // writer.writeNext(new String[] { "" }); // break line 108 for (int i = 1; i <= this.mainvalueLabels.length; i++) {
109 // "# Bezeichnung der Wasserspiegellage: "
110 final String label = this.getMainValueLabel(i - 1);
111 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, String.format("%d: %s", i, label));
112 }
113 // "# Bezugspegel: "
114 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, "TODO: gauge");
115 }
46 } 116 }
47 117
48 @Override 118 @Override
49 protected String getJasperFile() { 119 protected String getJasperFile() {
50 // TODO Variante mit Wasserspiegellage(n) 120 // TODO Variante mit Wasserspiegellage(n)
60 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration)); 130 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDuration));
61 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge)); 131 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.floodDischarge));
62 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight)); 132 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructureHeight));
63 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype)); 133 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.infrastructuretype));
64 134
65 // TODO Wasserspiegellage(n) und Dauerzahlen falls gewählt 135 if (this.getMainValueLabel(0) != null) {
136 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel1));
137 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.mainValue1Duration));
138 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge1));
139 if (this.getMainValueLabel(1) != null) {
140 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel2));
141 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.mainValue2Duration));
142 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge2));
143 if (this.getMainValueLabel(2) != null) {
144 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.waterlevel3));
145 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.mainValue3Duration));
146 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.discharge3));
147 }
148 }
149 }
66 150
67 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel)); 151 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.gaugeLabel));
68 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location)); 152 lines.add(exportContextCSV.formatRowValue(row, SInfoResultType.location));
69 153
70 return lines.toArray(new String[lines.size()]); 154 return lines.toArray(new String[lines.size()]);
80 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.floodDuration)); 164 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.floodDuration));
81 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit())); 165 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.floodDischarge, SInfoResultType.floodDischarge.getUnit()));
82 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, SInfoResultType.infrastructureHeight.getUnit())); 166 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.infrastructureHeight, SInfoResultType.infrastructureHeight.getUnit()));
83 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype)); 167 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.infrastructuretype));
84 168
85 // TODO Je vier Spalten der bis zu drei Wasserspiegellagen 169 if (this.getMainValueLabel(0) != null) {
170 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel1, SInfoResultType.waterlevel.getUnit()));
171 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.mainValue1Duration));
172 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge1, SInfoResultType.discharge.getUnit()));
173 if (this.getMainValueLabel(1) != null) {
174 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel2, SInfoResultType.waterlevel2.getUnit()));
175 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.mainValue2Duration));
176 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge2, SInfoResultType.discharge2.getUnit()));
177 if (this.getMainValueLabel(2) != null) {
178 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.waterlevel3, SInfoResultType.waterlevel3.getUnit()));
179 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.mainValue3Duration));
180 header.add(exportContextCSV.msgUnitCSV(SInfoResultType.discharge3, SInfoResultType.discharge3.getUnit()));
181 }
182 }
183 }
86 184
87 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); 185 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel));
88 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); 186 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location));
89 187
90 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); 188 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
109 /* column headings */ 207 /* column headings */
110 exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station); 208 exportContextPDF.addJRMetadata(source, "station_header", GeneralResultType.station);
111 exportContextPDF.addJRMetadata(source, "riverside_header", SInfoResultType.riverside); 209 exportContextPDF.addJRMetadata(source, "riverside_header", SInfoResultType.riverside);
112 exportContextPDF.addJRMetadata(source, "inundationduration_header", SInfoResultType.floodDuration); 210 exportContextPDF.addJRMetadata(source, "inundationduration_header", SInfoResultType.floodDuration);
113 exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge); 211 exportContextPDF.addJRMetadata(source, "inundationduration_q_header", SInfoResultType.floodDischarge);
114 exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeightFloodDur); 212 exportContextPDF.addJRMetadata(source, "infrastructure_height_header", SInfoResultType.infrastructureHeight);
115 exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype); 213 exportContextPDF.addJRMetadata(source, "infrastructure_type_header", SInfoResultType.infrastructuretype);
116 214
117 // TODO Je vier Spalten der bis zu drei Wasserspiegellagen 215 // TODO Feldnamen ergaenzen und aktivieren wenn Report fertig
216 // if (this.getMainValueLabel(0) != null) {
217 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.waterlevel);
218 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.mainValue1Duration);
219 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.discharge);
220 // if (this.getMainValueLabel(1) != null) {
221 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.waterlevel2);
222 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.mainValue2Duration);
223 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.discharge2);
224 // if (this.getMainValueLabel(2) != null) {
225 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.waterlevel3);
226 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.mainValue3Duration);
227 // exportContextPDF.addJRMetadata(source, "?", SInfoResultType.discharge3);
228 // }
229 // }
230 // }
118 231
119 exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel); 232 exportContextPDF.addJRMetadata(source, "gauge_header", SInfoResultType.gaugeLabel);
120 exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location); 233 exportContextPDF.addJRMetadata(source, "location_header", SInfoResultType.location);
121 } 234 }
122 } 235 }

http://dive4elements.wald.intevation.org