Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java @ 9265:e5367900dd6d
Small cleanup concerning getPoints
Adding validStations as dataItem to flood duration calculation
Flood duration now km aware
author | gernotbelger |
---|---|
date | Tue, 17 Jul 2018 19:48:28 +0200 |
parents | b515ed950d39 |
children | 9b16f58c62a7 |
comparison
equal
deleted
inserted
replaced
9264:baef46792354 | 9265:e5367900dd6d |
---|---|
13 import java.util.ArrayList; | 13 import java.util.ArrayList; |
14 import java.util.Collection; | 14 import java.util.Collection; |
15 import java.util.Collections; | 15 import java.util.Collections; |
16 import java.util.List; | 16 import java.util.List; |
17 | 17 |
18 import org.apache.commons.collections.Predicate; | |
18 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; | 19 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; |
19 import org.dive4elements.river.artifacts.common.AbstractExportContext; | 20 import org.dive4elements.river.artifacts.common.AbstractExportContext; |
20 import org.dive4elements.river.artifacts.common.ExportContextCSV; | 21 import org.dive4elements.river.artifacts.common.ExportContextCSV; |
21 import org.dive4elements.river.artifacts.common.ExportContextPDF; | 22 import org.dive4elements.river.artifacts.common.ExportContextPDF; |
22 import org.dive4elements.river.artifacts.common.GeneralResultType; | 23 import org.dive4elements.river.artifacts.common.GeneralResultType; |
24 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; | 25 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; |
25 import org.dive4elements.river.artifacts.common.ResultRow; | 26 import org.dive4elements.river.artifacts.common.ResultRow; |
26 import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings; | 27 import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings; |
27 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | 28 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
28 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | 29 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
29 import org.dive4elements.river.exports.DiagramGenerator; | |
30 import org.dive4elements.river.model.Attribute.AttributeKey; | 30 import org.dive4elements.river.model.Attribute.AttributeKey; |
31 | 31 |
32 import gnu.trove.TDoubleArrayList; | 32 import gnu.trove.TDoubleArrayList; |
33 | 33 |
34 /** | 34 /** |
36 * | 36 * |
37 * @author Gernot Belger | 37 * @author Gernot Belger |
38 */ | 38 */ |
39 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { | 39 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { |
40 | 40 |
41 private final static class RiversidePredicate implements Predicate { | |
42 | |
43 private final AttributeKey riverside; | |
44 | |
45 public RiversidePredicate(final AttributeKey riverside) { | |
46 this.riverside = riverside; | |
47 } | |
48 | |
49 @Override | |
50 public boolean evaluate(final Object object) { | |
51 final ResultRow row = (ResultRow) object; | |
52 | |
53 return row.getValue(SInfoResultType.riverside) == this.riverside; | |
54 } | |
55 } | |
56 | |
41 private static final long serialVersionUID = 1L; | 57 private static final long serialVersionUID = 1L; |
42 | 58 |
43 private final String[] mainvalueLabels; | 59 private final String[] mainvalueLabels; |
44 | 60 |
45 // private final WstInfo wstInfo; | 61 // private final WstInfo wstInfo; |
60 } | 76 } |
61 | 77 |
62 /** | 78 /** |
63 * Collection of the result rows containing only the rows describing an infrastructure | 79 * Collection of the result rows containing only the rows describing an infrastructure |
64 */ | 80 */ |
81 // FIXME: bad to override, instead make new method 'getInfrastructureRows' or similar? | |
65 @Override | 82 @Override |
66 public Collection<ResultRow> getRows() { | 83 public Collection<ResultRow> getRows() { |
84 | |
85 final Collection<ResultRow> rows = super.getRows(); | |
86 | |
67 final List<ResultRow> infrasOnlyRows = new ArrayList<>(); | 87 final List<ResultRow> infrasOnlyRows = new ArrayList<>(); |
68 for (final ResultRow row : this.rows) | 88 for (final ResultRow row : rows) { |
69 if (row.getValue(SInfoResultType.infrastructuretype) != null) | 89 if (row.getValue(SInfoResultType.infrastructuretype) != null) |
70 infrasOnlyRows.add(row); | 90 infrasOnlyRows.add(row); |
91 } | |
71 return Collections.unmodifiableCollection(infrasOnlyRows); | 92 return Collections.unmodifiableCollection(infrasOnlyRows); |
72 } | 93 } |
73 | 94 |
74 @Override | 95 @Override |
75 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { | 96 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { |
80 // "# Bezeichnung der Wasserspiegellage: " | 101 // "# Bezeichnung der Wasserspiegellage: " |
81 final String label = this.getMainValueLabel(i - 1); | 102 final String label = this.getMainValueLabel(i - 1); |
82 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, String.format("%d: %s", i, label)); | 103 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, String.format("%d: %s", i, label)); |
83 } | 104 } |
84 // "# Bezugspegel: " | 105 // "# Bezugspegel: " |
85 for (final ResultRow row : this.rows) { | 106 for (final ResultRow row : getRows()) { |
86 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, row.getValue(SInfoResultType.gaugeLabel)); | 107 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, row.getValue(SInfoResultType.gaugeLabel)); |
87 break; | 108 break; |
88 } | 109 } |
89 } | 110 } |
90 exportContextCSV.writeBlankLine(); | 111 exportContextCSV.writeBlankLine(); |
92 | 113 |
93 @Override | 114 @Override |
94 protected String getJasperFile() { | 115 protected String getJasperFile() { |
95 if (this.getWaterlevelCount() <= 1) | 116 if (this.getWaterlevelCount() <= 1) |
96 return "/jasper/templates/sinfo.floodduration.jrxml"; | 117 return "/jasper/templates/sinfo.floodduration.jrxml"; |
97 else | 118 |
98 return "/jasper/templates/sinfo.floodduration2.jrxml"; | 119 return "/jasper/templates/sinfo.floodduration2.jrxml"; |
99 } | 120 } |
100 | 121 |
101 protected String[] formatRow(final AbstractExportContext exportContextCSV, final ResultRow row, final ExportMode mode) { | 122 protected String[] formatRow(final AbstractExportContext exportContextCSV, final ResultRow row, final ExportMode mode) { |
102 | 123 |
103 final Collection<String> lines = new ArrayList<>(10); | 124 final Collection<String> lines = new ArrayList<>(10); |
158 | 179 |
159 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); | 180 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.gaugeLabel)); |
160 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); | 181 header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location)); |
161 | 182 |
162 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); | 183 exportContextCSV.writeCSVLine(header.toArray(new String[header.size()])); |
163 | 184 } |
185 | |
186 public List<Double> getValidDurationChartKilometers() { | |
187 return getValues(GeneralResultType.station); | |
164 } | 188 } |
165 | 189 |
166 @Override | 190 @Override |
167 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) { | 191 protected String[] formatCSVRow(final ExportContextCSV exportContextCSV, final ResultRow row) { |
168 | 192 |
219 | 243 |
220 /** | 244 /** |
221 * Gets the longitudinal section of a result value type for one river side | 245 * Gets the longitudinal section of a result value type for one river side |
222 */ | 246 */ |
223 public final double[][] getInfrastructurePoints(final IResultType type, final AttributeKey riverside) { | 247 public final double[][] getInfrastructurePoints(final IResultType type, final AttributeKey riverside) { |
224 | 248 return getPoints(GeneralResultType.station, type, new RiversidePredicate(riverside)); |
225 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); | |
226 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); | |
227 | |
228 for (final ResultRow row : this.rows) { | |
229 | |
230 final double station = row.getDoubleValue(GeneralResultType.station); | |
231 final double value = row.getDoubleValue(type); | |
232 if (row.getValue(SInfoResultType.riverside) == riverside) { | |
233 xPoints.add(station); | |
234 yPoints.add(value); | |
235 } | |
236 } | |
237 | |
238 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; | |
239 } | 249 } |
240 | 250 |
241 /** | 251 /** |
242 * Gets a longitudinal section of W, Q, or flood duration of one of the waterlevels | 252 * Gets a longitudinal section of W, Q, or flood duration of one of the waterlevels |
243 */ | 253 */ |
244 public final double[][] getMainValueDurationPoints(final DiagramGenerator generator, final ValueGetter valuegetter, final int dataIndex) { | 254 public final double[][] getMainValueDurationPoints(final ValueGetter valuegetter, final int dataIndex) { |
245 | 255 |
246 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); | 256 final Collection<ResultRow> rows = getRows(); |
247 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); | 257 |
248 | 258 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); |
249 for (final ResultRow row : this.rows) { | 259 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); |
260 | |
261 for (final ResultRow row : rows) { | |
250 | 262 |
251 final double station = row.getDoubleValue(GeneralResultType.station); | 263 final double station = row.getDoubleValue(GeneralResultType.station); |
252 | 264 |
253 final List<DurationWaterlevel> waterlevels = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel); | 265 final List<DurationWaterlevel> waterlevels = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel); |
254 final DurationWaterlevel waterlevel = waterlevels.get(dataIndex); | 266 final DurationWaterlevel waterlevel = waterlevels.get(dataIndex); |